mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [algorithm] keep LRU endpoint links consistent (#406)
This commit is contained in:
1 parent
9f7d939e5a
commit
7e02d7e4e6
2 files changed
+82
-4
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user