Get the key in cache by LFU
(key string)
| 51 | |
| 52 | // Get the key in cache by LFU |
| 53 | func (c *LFU) Get(key string) any { |
| 54 | // if existed, will return value |
| 55 | if e, ok := c.itemMap[key]; ok { |
| 56 | // the frequency of e +1 and change freqMap |
| 57 | c.increaseFreq(e) |
| 58 | obj := e.Value.(item) |
| 59 | return obj.value |
| 60 | } |
| 61 | |
| 62 | // if not existed, return nil |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | // Put the key in LFU cache |
| 67 | func (c *LFU) Put(key string, value any) { |