As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.--
If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur
Varuna Seneviratna
but there will be more chance of two pairs with the same hashCode % 16, so they will land in the same "bucket" and look-up will be slower
Please explain what you think that statement means. It looks correct to me, but I think I can only explain more if I know what you understand by it.Varuna Seneviratna wrote:"a rehash will not ever occur" . . .
If you set your load factor at 1.0f you won't get rehashing until 16, but there will be more chance of two pairs with the same hashCode % 16, so they will land in the same "bucket" and look-up will be slower.
Creativity is nothing but Breaking Rules
Varuna Seneviratna wrote:So what I gather is "a rehash will not ever occur" is not correct is it?What ever the initial capacity is when ever the load factor is reached it will rehash.I am saying this with the assumption that if the number of entries that will have to be made can not be predetermined
but there will be more chance of two pairs with the same hashCode % 16, so they will land in the same "bucket" and look-up will be slower
I am not able to understand this.What is HashCode?Is it the Key?When entries are made up to 16(16th one also added) with the load factor 1.0f.Another 16 of empty elements will be added and the total number of elements will be 32, is it?
In the HashMap method list I couldn't find a method to get the number of total number entries possible. The size() returns only the number of entries already made.Is there a way to get the total number of possible entries?
By saying that if empty space increases lookup time will be slower, does this mean that when an search has to be carried out using a given Key all the elements even the empty ones will be looked up?
Regards Varuna
That guarantees not less than 8 pairs will have to share buckets. When you increase it to 32 buckets, it will have to accommodate up to 48 objects.
Creativity is nothing but Breaking Rules
santhosh.R gowda wrote:
That guarantees not less than 8 pairs will have to share buckets. When you increase it to 32 buckets, it will have to accommodate up to 48 objects.
please tell me this statement some more clearly with example
24 entries.santhosh.R gowda wrote:please tell me this statement some more clearly with example
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |