MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / resize

Method resize

structure/hashmap/hashmap.go:93–104  ·  view source on GitHub ↗

resize doubles the capacity of the hashmap and rehashes all existing entries

()

Source from the content-addressed store, hash-verified

91
92// resize doubles the capacity of the hashmap and rehashes all existing entries
93func (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
107func (hm *HashMap) hash(key any) uint64 {

Callers 1

PutMethod · 0.95

Calls 1

PutMethod · 0.95

Tested by

no test coverage detected