MCPcopy
hub / github.com/TheAlgorithms/Go / increaseFreq

Method increaseFreq

cache/lfu.go:92–104  ·  view source on GitHub ↗

increaseFreq increase the frequency if element

(e *list.Element)

Source from the content-addressed store, hash-verified

90
91// increaseFreq increase the frequency if element
92func (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
107func (c *LFU) insertMap(obj item) {

Callers 2

GetMethod · 0.95
PutMethod · 0.95

Calls 3

insertMapMethod · 0.95
LenMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected