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

Method Put

internal/utils/maps/map_fixed.go:32–52  ·  view source on GitHub ↗
(key KeyT, value ValueT)

Source from the content-addressed store, hash-verified

30}
31
32func (this *FixedMap[KeyT, ValueT]) Put(key KeyT, value ValueT) {
33 this.locker.Lock()
34 defer this.locker.Unlock()
35
36 if this.maxSize <= 0 {
37 return
38 }
39
40 _, exists := this.m[key]
41 this.m[key] = value
42
43 if !exists {
44 this.keys = append(this.keys, key)
45
46 if len(this.keys) > this.maxSize {
47 var firstKey = this.keys[0]
48 this.keys = this.keys[1:]
49 delete(this.m, firstKey)
50 }
51 }
52}
53
54func (this *FixedMap[KeyT, ValueT]) Get(key KeyT) (value ValueT, ok bool) {
55 this.locker.RLock()

Callers 1

TestNewFixedMapFunction · 0.45

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestNewFixedMapFunction · 0.36