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

Method Add

list.go:32–44  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
32func (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.
47func (l *List[Key, Value]) AddOrUpdate(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (*ListElement[Key, Value], bool) {

Callers 7

addItemMethod · 0.80
InsertMethod · 0.80
insertElementMethod · 0.80
DeleteMethod · 0.80
insertAtMethod · 0.80

Calls 2

searchMethod · 0.95
insertAtMethod · 0.95

Tested by 2