resize doubles the capacity of the hashmap and rehashes all existing entries
()
| 91 | |
| 92 | // resize doubles the capacity of the hashmap and rehashes all existing entries |
| 93 | func (hm *HashMap) resize() { |
| 94 | oldTable := hm.table |
| 95 | hm.capacity <<= 1 |
| 96 | hm.table = make([]*node, hm.capacity) |
| 97 | hm.size = 0 |
| 98 | |
| 99 | for _, head := range oldTable { |
| 100 | for current := head; current != nil; current = current.next { |
| 101 | hm.Put(current.key, current.value) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // hash generates a hash value for the given key |
| 107 | func (hm *HashMap) hash(key any) uint64 { |