Add adds an item to the list and returns false if an item for the hash existed. searchStart = nil will start to search at the head item.
(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value)
| 30 | // Add adds an item to the list and returns false if an item for the hash existed. |
| 31 | // searchStart = nil will start to search at the head item. |
| 32 | func (l *List[Key, Value]) Add(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (element *ListElement[Key, Value], existed bool, inserted bool) { |
| 33 | left, found, right := l.search(searchStart, hash, key) |
| 34 | if found != nil { // existing item found |
| 35 | return found, true, false |
| 36 | } |
| 37 | |
| 38 | element = &ListElement[Key, Value]{ |
| 39 | key: key, |
| 40 | keyHash: hash, |
| 41 | } |
| 42 | element.value.Store(&value) |
| 43 | return element, false, l.insertAt(element, left, right) |
| 44 | } |
| 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) { |