MCPcopy
hub / github.com/cornelk/hashmap / AddOrUpdate

Method AddOrUpdate

list.go:47–60  ·  view source on GitHub ↗

AddOrUpdate adds or updates an item to the list.

(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value)

Source from the content-addressed store, hash-verified

45
46// AddOrUpdate adds or updates an item to the list.
47func (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.
63func (l *List[Key, Value]) Delete(element *ListElement[Key, Value]) {

Callers 1

SetMethod · 0.80

Calls 2

searchMethod · 0.95
insertAtMethod · 0.95

Tested by

no test coverage detected