C # how does a hashtable shrink when items are removed from a hash table?

I'm looking to find out the logic, if any, that compresses a hash table in C # when elements are removed from it.

Harish relationship

+1


source to share


3 answers


C # hashtables don't shrink; they only grow. The logic is important because the paraphrasing algorithm is VERY expensive to run; for most situations, the space saved by renaming to a smaller hash table will be completely covered by the cost of rephrasing. In particular, in automatic mode, when any deletions from the hash table may not be the last delete (it is impossible to determine from the hash table on an algorithmic basis), the potential value is simply not worth it.



If your hash table is shrinking significantly and you really want to reclaim space, I recommend just creating a new one (with the size you want) and copying the items to it.

+4


source


As an aside, since you are using .net2.0 or newer, you should probably use Dictionary<K,V>

HashTable, not.



+1


source


The only indication of size changes for the hash table in the documentation is when the load factor is exceeded and the size of the hash table increases. There is no mention of a quick cut.

See below for details on MSDN load factor .

0


source







All Articles