I found this in the standard as the post-condition for the rehash
function in unordered associative containers :
Post: a.bucket_count() > a.size() / a.max_load_factor() and a.bucket_count() >= n. (n being the number of buckets in the container)
Can I take the above to mean that an automatic rehashing is triggered when either of the above conditions is met for all implementations? Or, are implementations free to decide when to rehash and the above only pertains to the rehash
function?
The implementation shall keep the load_factor() <= max_load_factor()
and load_factor() == size() / bucket_count()
. So automatic rehashing can occur during an insert
to keep the load factor invariant.
Although the load_factor()
can not exceed max_load_factor()
, I don't think there is a guarantee that no rehashing will be done during an insert even if you can prove that this invariant will not be violated.
Definition for max_load_factor
is:
Returns a positive number that the container attempts to keep the load factor less than or equal to. The container automatically increases the number of buckets as necessary to keep the load factor below this number.
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