MCPcopy
hub / github.com/austingebauer/go-leetcode / Get

Method Get

lru_cache_146/solution.go:71–84  ·  view source on GitHub ↗
(key int)

Source from the content-addressed store, hash-verified

69}
70
71func (cache *LRUCache) Get(key int) int {
72 node, ok := cache.keyMap[key]
73 if !ok {
74 return -1
75 }
76
77 // if node is at the front of the list or is the only node in the list
78 if cache.front == node || (node.prev == nil && node.next == nil) {
79 return node.value
80 }
81
82 cache.bringNodeToFront(node)
83 return node.value
84}
85
86func (cache *LRUCache) insertInFront(node *LRUNode) {
87 cache.front.prev = node

Callers 8

TestLRUCache_1Function · 0.45
TestLRUCache_2Function · 0.45
TestLRUCache_3Function · 0.45
TestLRUCache_4Function · 0.45
TestLRUCache_5Function · 0.45
TestLRUCache_6Function · 0.45
TestLRUCache_7Function · 0.45
TestLRUCache_8Function · 0.45

Calls 1

bringNodeToFrontMethod · 0.95

Tested by 8

TestLRUCache_1Function · 0.36
TestLRUCache_2Function · 0.36
TestLRUCache_3Function · 0.36
TestLRUCache_4Function · 0.36
TestLRUCache_5Function · 0.36
TestLRUCache_6Function · 0.36
TestLRUCache_7Function · 0.36
TestLRUCache_8Function · 0.36