From a254ebdc8e462bdf969caf49000df0e7182c81a9 Mon Sep 17 00:00:00 2001 From: BoWen Qiu <45390913+aki-colt@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:55:38 +0800 Subject: [PATCH] fix(algorithm): fix bug of lrucache in issue #251 (#254) --- algorithm/lrucache.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/algorithm/lrucache.go b/algorithm/lrucache.go index c1c737d..db32053 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 }