I was trying to understand why hash table (unordered containers such as unordered_map or unordered_set) don't provide an interface for querying or setting minimum load factor.
Say c is a unordered_set, I can use
c.max_load_factor()
for querying
and
c.max_load_factor(val)
for setting.
Why doesn't C++11 provide an interface for querying min_load_factor? Are there implementation details, which would explain?
Also, C++ STL by Josuttis, mentions that:
The minimum load factor, which is used to force rehashing when the number of elements in the container shrinks cannot be influenced.
The load factor on an unordered_map
affects the probability of collision in the hash table. For example,the probability of two elements being located in the same bucket. The container uses the value of max_load_factor
as the threshold that forces an increase in the number of buckets and thus causing a rehash.
There is no such thing as a user-controllable minimum load factor since it should respect the number of elements already in the container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With