MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / PutCompact

Method PutCompact

internal/utils/sync/map_int.go:51–62  ·  view source on GitHub ↗
(k K, v V, compactFunc func(oldV V, newV V) V)

Source from the content-addressed store, hash-verified

49}
50
51func (this *IntMap[K, V]) PutCompact(k K, v V, compactFunc func(oldV V, newV V) V) {
52 var index = this.index(k)
53 this.lockers[index].Lock()
54 // 再次检查是否已经存在,如果已经存在则合并
55 oldV, ok := this.m[index][k]
56 if ok {
57 this.m[index][k] = compactFunc(oldV, v)
58 } else {
59 this.m[index][k] = v
60 }
61 this.lockers[index].Unlock()
62}
63
64func (this *IntMap[K, V]) Has(k K) bool {
65 var index = this.index(k)

Callers 1

TestIntMap_PutCompactFunction · 0.80

Calls 3

indexMethod · 0.95
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestIntMap_PutCompactFunction · 0.64