AddOrUpdate adds or updates an item to the list.
(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value)
| 45 | |
| 46 | // AddOrUpdate adds or updates an item to the list. |
| 47 | func (l *List[Key, Value]) AddOrUpdate(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (*ListElement[Key, Value], bool) { |
| 48 | left, found, right := l.search(searchStart, hash, key) |
| 49 | if found != nil { // existing item found |
| 50 | found.value.Store(&value) // update the value |
| 51 | return found, true |
| 52 | } |
| 53 | |
| 54 | element := &ListElement[Key, Value]{ |
| 55 | key: key, |
| 56 | keyHash: hash, |
| 57 | } |
| 58 | element.value.Store(&value) |
| 59 | return element, l.insertAt(element, left, right) |
| 60 | } |
| 61 | |
| 62 | // Delete deletes an element from the list. |
| 63 | func (l *List[Key, Value]) Delete(element *ListElement[Key, Value]) { |