Skip to content

Commit

Permalink
Fix removal with copy-on-write
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Apr 19, 2022
1 parent 2d74338 commit f091512
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hashmap/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func (m *Map[K, V]) Remove(key K) {
return
}

if m.readonly {
entries := make([]entry[K, V], len(m.entries), cap(m.entries))
copy(entries, m.entries)
m.entries = entries
m.readonly = false
}

m.remove(idx)

idx = (idx + 1) & (m.capacity - 1)
Expand Down

0 comments on commit f091512

Please sign in to comment.