I want to cache 10.000+ key/value pairs (both strings) and started thinking which .NET (2.0, bound to MS Studio 2005 🙁 ) structure would be best. All items will be added in one shot, then there will be a few 100s of queries for particular keys.
I’ve read MSDN descriptions referenced in the other question but I stil miss some details about implementation / complexity of operation on various collections.
E.g. in the above mentioned question, there is quote from MSDN saying that SortedList is based on a tree and SortedDictionary “has similar object model” but different complexity.
The other question: are HashTable and Dictionary implemented in the same way?
For HashTable, they write:
If Count is less than the capacity of the Hashtable, this method is an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.
But when the capacity is increased? With every “Add”? Then it would be quadratic complexity of adding a series of key/value pairs. The same as with SortedList.
Not mentioning OrderedDictionary, where nothing is mentioned about implementation / complexity.
Maybe someone knows some good article about implementation of .NET collections?
If you are adding that many pairs, you can/should use this Dictionary constructor to specify the capacity in advance. Then every add and lookup will be O(1).
If you really want to see how these classes are implemented, you can look at the Rotor source or use .NET Reflector to look at System.Collections (not sure of the legality of the latter).