fix(package): [algorithm] keep LRU endpoint links consistent (#406)

This commit is contained in:
Rupayon Haldar authored and GitHub committed 2026-10-31 09:56:48 +08:00
1 parent 9f7d939e5a
commit 7e02d7e4e6
2 files changed
+82 -4

No files matched your search

+6 -4
View File
@@ -102,12 +102,14 @@ func (l *LRUCache[K, V]) addNode(node *lruNode[K, V]) {
}
func (l *LRUCache[K, V]) deleteNode(node *lruNode[K, V]) K {
if node == l.tail {
l.tail = l.tail.pre
} else if node == l.head {
l.head = l.head.next
if node.pre == nil {
l.head = node.next
} else {
node.pre.next = node.next
}
if node.next == nil {
l.tail = node.pre
} else {
node.next.pre = node.pre
}
return node.key