Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Virtual gardener
staff: administrator
Original Poster
#1 Old 3rd Feb 2021 at 2:56 PM
Default Difference between a PairedListDictionary and a regular Dictionary
Heya!

It's actually quite an easy question; what exactly is the difference between C#'s dictionary and EA's PairedListDictionary? 

All I can get out of it is that the keyvaluepair is easier to access? But even that's just a theory. So was just wondering if anyone else knows!
Advertisement
Space Pony
#2 Old 3rd Feb 2021 at 4:06 PM
Quote: Originally posted by Lyralei
Heya!

It's actually quite an easy question; what exactly is the difference between C#'s dictionary and EA's PairedListDictionary? 

All I can get out of it is that the keyvaluepair is easier to access? But even that's just a theory. So was just wondering if anyone else knows!


C#'s generic dictionaries are implemented using hash tables, whereas the PairedListDictionary appears to just be an association list. In practice, the two would be functionally equivalent for most cases, but if you're doing a lot of searching or deleting, C# dictionaries will be faster on average. Plus, it uses generics, so you don't have the hassle of boxing to/unboxing from object like you would with a PairedListDictionary.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Virtual gardener
staff: administrator
Original Poster
#3 Old 4th Feb 2021 at 10:33 AM
Quote: Originally posted by gamefreak130
C#'s generic dictionaries are implemented using hash tables, whereas the PairedListDictionary appears to just be an association list. In practice, the two would be functionally equivalent for most cases, but if you're doing a lot of searching or deleting, C# dictionaries will be faster on average. Plus, it uses generics, so you don't have the hassle of boxing to/unboxing from object like you would with a PairedListDictionary.
Ah right! I thought indeed PairedListDictionaries also used Hash tables but indeed, it doesn't (looking at the source code of it)  Also explains why only 3 functions in the entirety of the game uses this type of Dictionary. Still think they probably should just converted those other PairedListDictionaries to proper Dictionaries as 99% of the time EA's code seems to just use Dictionaries. Oh well! 

Anyways! Thanks for the explanation! It does really help!  Difference I noticed as well is that PairedListDictionary has the concept of ContainKey() but when it comes to the value, it's trying to get the value, rather than being able to see if it 'contains' the value. Which is an interesting design choice IMO.
Forum Resident
#4 Old 5th Feb 2021 at 11:26 PM
From what I can see the PairedListDictionary is sprinkled all over the source code.

The only reason I can see to use it is that the EA implementation keeps it's internal order of elements while the normal Dictionary doesn't guarantee for it but often "happens" to be in the order you expect.

Or perhaps Mono's inplementation was flawed at the time they started development? In the older code you often see them using arrays and hashtables instead of lists and dictionaries.

Find my Mods: Here at MTS, over at Simlogical
Back to top