| 30 | } |
| 31 | |
| 32 | func (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 | |
| 54 | func (this *FixedMap[KeyT, ValueT]) Get(key KeyT) (value ValueT, ok bool) { |
| 55 | this.locker.RLock() |