Default HashMap Sensing in Java

What uses Java as the default definition method for HashMap? Linear? A chain or something else?

+6
java hashmap data-structures
source share
1 answer

Looks like a whole chain. 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, take an entry in bucketIndex, and then replace it with a new entry that has as its β€œnext” field an entry that was already there (ie, a chain).

+8
source share

All Articles