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

Method Get

cache/lfu.go:53–64  ·  view source on GitHub ↗

Get the key in cache by LFU

(key string)

Source from the content-addressed store, hash-verified

51
52// Get the key in cache by LFU
53func (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
67func (c *LFU) Put(key string, value any) {

Callers 1

TestLFUFunction · 0.95

Calls 1

increaseFreqMethod · 0.95

Tested by 1

TestLFUFunction · 0.76