Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all Hash-based datastructures in java use the 'bucket' concept?

The hash structures I am aware of - HashTable, HashSet & HashMap.

Do they all use the bucket structure - ie when two hashcodes are similar exactly the same one element does not overwrite the other, instead they are placed in the same bucket associated with that hashcode?

like image 399
ST. Avatar asked Dec 30 '25 07:12

ST.


1 Answers

In Sun's current implementation of the Java library, IdentityHashMap and the internal implementation in ThreadLocal use probing structures.

The general problem with probing hash tables in Java is that hashCode and equals may be relatively expensive. Therefore you want to cache the hash value. You can't have an array that mixes references and primitives, so you'd need to do something relatively complicated. On the other hand, if you are using == to check matches, then you can check many references without a performance problem.

IIRC, Azul had a fast concurrent quadratic probing hash map.

like image 102
Tom Hawtin - tackline Avatar answered Jan 01 '26 20:01

Tom Hawtin - tackline