Skip to content

Commit

Permalink
fix(algorithm): fix bug of lrucache in issue #251 (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
aki-colt authored Oct 16, 2024
1 parent 0bc1100 commit a254ebd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions algorithm/lrucache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (l *LRUCache[K, V]) Get(key K) (V, bool) {

node, ok := l.cache[key]
if ok {
l.moveToHead(node)
l.moveToTail(node)
return node.value, true
}

Expand All @@ -66,7 +66,7 @@ func (l *LRUCache[K, V]) Put(key K, value V) {
}
} else {
node.value = value
l.moveToHead(node)
l.moveToTail(node)
}
l.length = len(l.cache)
}
Expand All @@ -79,7 +79,7 @@ func (l *LRUCache[K, V]) Delete(key K) bool {
delete(l.cache, key)
return true
}

l.length = len(l.cache)
return false
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (l *LRUCache[K, V]) deleteNode(node *lruNode[K, V]) K {
return node.key
}

func (l *LRUCache[K, V]) moveToHead(node *lruNode[K, V]) {
func (l *LRUCache[K, V]) moveToTail(node *lruNode[K, V]) {
if l.tail == node {
return
}
Expand Down

0 comments on commit a254ebd

Please sign in to comment.