How is the c#/.net 3.5 dictionary implemented?

后端 未结 5 1280
無奈伤痛
無奈伤痛 2020-12-01 00:22

I\'m using an application which uses a number of large dictionaries ( up to 10^6 elements), the size of which is unknown in advance, (though I can guess in some cases). I\'m

5条回答
  •  执念已碎
    2020-12-01 00:52

    MSDN says: "Retrieving a value by using its key is very fast, close to O(1), because the Dictionary class is implemented as a hash table." and further on "the capacity is automatically increased as required by reallocating the internal array."

    But you get less reallocations if you give an initial estimate. If you have all items from the beginning the LINQ method ToDictionary might be handy.

提交回复
热议问题