From 88af35a90daca27d612a785d8263f749d3219882 Mon Sep 17 00:00:00 2001 From: qiubowen <3561288101@qq.com> Date: Tue, 15 Oct 2024 21:21:02 +0800 Subject: [PATCH] fix(algorithm): fix bug of lrucache in issue #251 --- algorithm/lrucache.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/algorithm/lrucache.go b/algorithm/lrucache.go index c1c737d1..db320532 100644 --- a/algorithm/lrucache.go +++ b/algorithm/lrucache.go @@ -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 } @@ -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) } @@ -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 } @@ -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 }