Why is there no Dictionary.TrimExcess()?

后端 未结 5 1519
醉梦人生
醉梦人生 2021-02-14 08:03

In .NET, there is a constructor for Dictionary that takes one parameter, int capacity. This is the same as with many other collecti

5条回答
  •  名媛妹妹
    2021-02-14 08:13

    Per MSDN Dictionary is implemented as a hash table. If you trimmed excess you would have to come up with an algorithm that still provided close to O(1) lookup times in what would effectively be a randomly sorted list.

提交回复
热议问题