increaseFreq increase the frequency if element
(e *list.Element)
| 90 | |
| 91 | // increaseFreq increase the frequency if element |
| 92 | func (c *LFU) increaseFreq(e *list.Element) { |
| 93 | obj := e.Value.(item) |
| 94 | // remove from low frequency first |
| 95 | oldLost := c.freqMap[obj.freq] |
| 96 | oldLost.Remove(e) |
| 97 | // change the value of minFreq |
| 98 | if c.minFreq == obj.freq && oldLost.Len() == 0 { |
| 99 | // if it is the last node of the minimum frequency that is removed |
| 100 | c.minFreq++ |
| 101 | } |
| 102 | // add to high frequency list |
| 103 | c.insertMap(obj) |
| 104 | } |
| 105 | |
| 106 | // insertMap insert item in map |
| 107 | func (c *LFU) insertMap(obj item) { |