(element *ListElement[Key, Value], hash uintptr, key Key, value Value)
| 243 | } |
| 244 | |
| 245 | func (m *Map[Key, Value]) insertElement(element *ListElement[Key, Value], hash uintptr, key Key, value Value) bool { |
| 246 | var existed, inserted bool |
| 247 | |
| 248 | for { |
| 249 | store := m.store.Load() |
| 250 | searchStart := store.item(element.keyHash) |
| 251 | |
| 252 | if !inserted { // if retrying after insert during grow, do not add to list again |
| 253 | _, existed, inserted = m.linkedList.Add(searchStart, hash, key, value) |
| 254 | if existed { |
| 255 | return false |
| 256 | } |
| 257 | |
| 258 | if !inserted { |
| 259 | continue // a concurrent add did interfere, try again |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | count := store.addItem(element) |
| 264 | currentStore := m.store.Load() |
| 265 | if store != currentStore { // retry insert in case of insert during grow |
| 266 | continue |
| 267 | } |
| 268 | |
| 269 | if m.isResizeNeeded(store, count) && m.resizing.CompareAndSwap(0, 1) { |
| 270 | go m.grow(0, true) |
| 271 | } |
| 272 | return true |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // deleteElement deletes an element from index. |
| 277 | func (m *Map[Key, Value]) deleteElement(element *ListElement[Key, Value]) { |
no test coverage detected