The Java Hashtable has a constructor where you can specify a loadFactor. However, if the initialCapacity (n) is known, what's the point of specifying the loadFactor?
Assuming that the size of its array of buckets (s) is constant, does the constructor Hashtable(int initialCapacity, float loadFactor)
just create a Hash Table that has more capacity than initialCapacity to ensure the correct loadFactor?
Assuming that the size of its array of buckets (s) is constant, […]
This assumption is not correct. The array of buckets is resized when necessary to ensure that the proportion of non-empty buckets is at most loadFactor
.
(Note: the Javadoc states that "The initial capacity and load factor parameters are merely hints to the implementation. The exact details as to when and whether the rehash method is invoked are implementation-dependent", so the above shouldn't be taken as a strict guarantee. But it's the general behavior.)
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