Jump to content
  • Advertisement
Sign in to follow this  
mike74

dynamic hashtables

This topic is 4878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For my own enlightenment, I have been pondering the internal workings of Java hashtables. In particular, I can't figure out how they can seamlessly adjust the size of the hashtables. Back when I was learning hashtables, we basically chose a size from the start, and all of the hash values were intimately tied to that size. For instance, if we were doing strings and had a hash table size of ten, we might add up the ascii values in the string and mod them by ten. Does anyone know how Java adjusts the size of hashtables? I assume it does so while still maintaining roughly constant insertion time, which is where the mystery lies. Any thoughts would be appreciated. Mike C. http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
Advertisement
This is perhaps not the best way, but you can easily create a new hash table with the new size/modulo, and simply remove each node from the first, and add it [re-hash] it to the second. Then delete the first.

Share this post


Link to post
Share on other sites
Someone will probably explain this a bit better, but I'll give it a shot..

Hashtable has a value that indicates how full it is. If this value increases over some threshold like 75% the size of hashtable is increased by some factor like 2 and hashing function is changed. All items in table are remapped to new locations. Since this on average happens only once in n operations you still have O(1) average insert complexity.

Share this post


Link to post
Share on other sites
You know you can get the source code to all of javas built in classes?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!