Code a hashmap which you would be happy to place into a production environment.
We already write 2 post before:
[Question] Implement a HashMap
[CC150v5] 8.10 Implement a Hashmap
But still, this is not an easy question when asked at an interview. It won’t harm to do a little recap:
- The basic structure is an array. It can be:
- An array of linked nodes (with a next pointer).
- An array of linked list.
- There should be a hash function.
- There should be a function to convert the hash value to corresponding array index.
- Remember there’s a concept of Load factor. It means to what percentage the hashmap is filled.
- h & (length – 1) means h % length, which maps a hashcode to an array index.