File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hash function in HashMap method" Watch "Hash function in HashMap method" New topic

Hash function in HashMap method

Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

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?

Salil Verma

Salil Verma
I agree. Here's the link:
subject: Hash function in HashMap method
It's not a secret anymore!