Why is there no Dictionary.TrimExcess()?

后端 未结 5 1539
醉梦人生
醉梦人生 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:15

    Actually I was the one that asked Microsoft to implement TrimExcess. I already presented more than one article that deals with dictionaries and in all cases I implemented TrimExcess. In fact, the Resize used when the buckets are too small can be invoked when increasing or decreasing the size of the buckets.

    Today I just published another article, it is a C++ implementation of a dictionary, which supports TrimExcess: http://www.codeproject.com/Articles/761040/A-NET-like-Dictionary-in-Cplusplus

    Another implementation (.NET) can be found in this article: http://www.codeproject.com/Articles/548406/Dictionary-plus-Locking-versus-ConcurrentDictionar

提交回复
热议问题