What is the need of three different dictionaries- OrderedDictionary,ListDictionary and HybridDictionary when all of them perform similar functions?
None of them is sorted, and elements of the collection can be retrieved by key in all of them. So, what is the purpose of three different classes?
In a nutshell:
Dictionary
- Well, a dictionary.
ListDictionary
- Used for small collections, typically less than 10 items
HybridDictionary
- Used when the collection size is unknown (switches implementations depending on the size of the collection)
OrderedDictionary
- The elements of an OrderedDictionary are not sorted by the key, unlike the elements of a SortedDictionary<TKey, TValue>
class. You can access elements either by the key or by the index.
To complement Kyle's answer:
OrderedDictionary allows retrieval by key and index (it uses a hashtable and and array internally) but has a bigger overhead per item
ListDictionary has a linked list as its internal structure, it does not perform well for insertion and retrieval by key but preserves the original insert order
HybridDictionary is a ListDictionary if the dictionary does not contain many items and converts to a Hashtable if the number of items reaches a speficic limit (I personally think you should use Dictionary<,> instead of it since C#2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With