Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Hash function in HashMap method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hash function in HashMap method" Watch "Hash function in HashMap method" New topic
Author

Hash function in HashMap method

Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

As per my understanding HashMap applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions.
While looking in the HashMap code, I figured out that below method is being used for this purpose, Can any one help me in understanding below queries ? -

1-How does this function insure that a less number of buckets would be created than the range of integer?
2- How many maximum buckets would be made while using this hash function?
3- Why the programmer has used specific numbers ie 20, 12,7, 4 to be used in shift operation?
4- why the programmer has used right shift and XOR operator?



Regards
Salil Verma


Regards
Salil Verma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hash function in HashMap method
 
Similar Threads
Hash method in HashMap
Why does Java’s hashCode() in String use 31 as a multiplier?
hash() function in HashMap implementation.
tricky question about HashMap + equals