There are several topics on this in stackoverflow as well as in web, I could not understand them clearly. I found this answer in stackoverflow by Nicklas and his representation which gave me some meaningful insight over the topic.
Some ASCII art
key.hashCode()
|
| 32-bit value
| hash table
V +------------+ +----------------------+
HashMap.hash() ----+ | reference | -> | key1 | value1 | null |
| |------------| +----------------------+
| | null |
| offset |------------| +---------------------+
+--------> | reference | -> | key1 | value1 | ref |
|------------| +---------------------+
| .... | |
+----------------+
V
+----------------------+
| key2 | value2 | null |
+----------------------+
What hashing function does Java use to implement Hashtable class?
Map aMap = new HashMap();
aMap.put(key,value);
- Can anyone explain me `what is an offset and its value?. Where is the offset value getting mapped?.
- what's that hash-table?. Is it an Array of Objects?, If so does each object have an key, value1 and a reference propery?.
Can anyone re-explain the above diagram step-by-step. I am not able to understand the Hashing mechanism behind HashMap.