This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashing  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please anybody help me regarding the Hashing process , what is the concept behind the hashmap,hashtable and hashset can anybody help in neat explained manner.Point is how hashmap,hashtable and hashset rely on hashing
 
Sheriff
Posts: 21327
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For fast lookups, objects are stored in so-called buckets. Each bucket contains objects with the exact same hash code.

If the value for a key is looked up, its hash code is calculated first. Then the bucket for that hash code is retrieved. This will decrease the number of objects to search through - instead of checking every single object in the map / set, only the objects in the one bucket will be checked. The better your hash code, the better objects are distributed among buckets, and the faster your map / set becomes.

That also shows the reason why the hash code for equal objects should be the same as well - otherwise, the object will not be found. It also shows another issue: you cannot modify objects stored in the map / set (keys for maps only) in such a way that the hash code will change, or it will never be found again.
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!