MCPcopy Index your code
hub / github.com/Azure/peerd / Set

Method Set

pkg/cache/syncmap.go:32–54  ·  view source on GitHub ↗

Set sets a new entry or updates an existing one. Set adds or updates an entry in the SyncMap with the specified key. If the key already exists in the map, the entry will be updated. If the key does not exist and the map is at capacity, some entries will be evicted first.

(key string, entry interface{})

Source from the content-addressed store, hash-verified

30// If the key already exists in the map, the entry will be updated.
31// If the key does not exist and the map is at capacity, some entries will be evicted first.
32func (sm *SyncMap) Set(key string, entry interface{}) {
33 sm.lock.Lock()
34 defer sm.lock.Unlock()
35
36 if _, ok := (*sm.mapObj)[key]; !ok {
37 if numEntries := len(*sm.mapObj); numEntries >= sm.capacity {
38 numToEvict := numEntries * sm.evictionPercentage / 100
39 if numToEvict <= 1 {
40 numToEvict = 1
41 }
42 numEvicted := 0
43 for k := range *sm.mapObj {
44 delete(*sm.mapObj, k)
45 numEvicted++
46 if numEvicted >= numToEvict {
47 break
48 }
49 }
50 }
51 }
52
53 (*sm.mapObj)[key] = entry
54}
55
56// Delete removes the entry with the specified key from the SyncMap.
57// If the key does not exist, this method does nothing.

Callers 15

TestSyncMapAddEvictFunction · 0.95
TestSyncMapAddDeleteFunction · 0.95
TestSyncMapUpdateFunction · 0.95
BenchmarkSyncMapFunction · 0.95
TestExistsFunction · 0.80
GetOrCreateMethod · 0.80
PutSizeMethod · 0.80
TestOpenP2pFunction · 0.80
TestOpenNonP2pFunction · 0.80
TestKeyFunction · 0.80
TestLoggerFunction · 0.80
TestFillCorrelationIdFunction · 0.80

Calls

no outgoing calls

Tested by 15

TestSyncMapAddEvictFunction · 0.76
TestSyncMapAddDeleteFunction · 0.76
TestSyncMapUpdateFunction · 0.76
BenchmarkSyncMapFunction · 0.76
TestExistsFunction · 0.64
TestOpenP2pFunction · 0.64
TestOpenNonP2pFunction · 0.64
TestKeyFunction · 0.64
TestLoggerFunction · 0.64
TestFillCorrelationIdFunction · 0.64
TestIsRequestFromPeerFunction · 0.64