Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default HashMap probing in Java

What does Java use as a default probing method for HashMap? Is it Linear? Chaining or something else?

like image 306
ashokgelal Avatar asked Nov 06 '08 01:11

ashokgelal


1 Answers

Looks like chaining to me. Code: (link)

...
724         /**
725          * Create new entry.
726          */
727         Entry(int h, K k, V v, Entry n) {
728             value = v;
729             next = n;
730             key = k;
731             hash = h;
732         }
...

...
795     void addEntry(int hash, K key, V value, int bucketIndex) {
796     Entry e = table[bucketIndex];
797         table[bucketIndex] = new Entry(hash, key, value, e);
...

That is, grab the entry at bucketIndex, then replace it with a new entry that has as its "next" field the entry that was already there (i.e. chain it).

like image 168
2 revs Avatar answered Oct 20 '22 00:10

2 revs