We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 89ff7a1 + 5e150b8 commit 29c318bCopy full SHA for 29c318b
notes/缓存.md
@@ -88,12 +88,14 @@ public class LRU<K, V> implements Iterable<K> {
88
89
public void put(K key, V value) {
90
91
+ Node node;
92
if (map.containsKey(key)) {
- Node node = map.get(key);
93
+ node = map.get(key);
94
unlink(node);
95
}
-
96
- Node node = new Node(key, value);
+ if (node == null) {
97
+ node = new Node(key, value);
98
+ }
99
map.put(key, node);
100
appendHead(node);
101
@@ -109,6 +111,9 @@ public class LRU<K, V> implements Iterable<K> {
109
111
Node next = node.next;
110
112
pre.next = next;
113
next.pre = pre;
114
+
115
+ node.pre = null;
116
+ node.next = null;
117
118
119
0 commit comments