commit
29c318b846
11
notes/缓存.md
11
notes/缓存.md
@ -88,12 +88,14 @@ public class LRU<K, V> implements Iterable<K> {
|
||||
|
||||
public void put(K key, V value) {
|
||||
|
||||
Node node;
|
||||
if (map.containsKey(key)) {
|
||||
Node node = map.get(key);
|
||||
node = map.get(key);
|
||||
unlink(node);
|
||||
}
|
||||
|
||||
Node node = new Node(key, value);
|
||||
if (node == null) {
|
||||
node = new Node(key, value);
|
||||
}
|
||||
map.put(key, node);
|
||||
appendHead(node);
|
||||
|
||||
@ -109,6 +111,9 @@ public class LRU<K, V> implements Iterable<K> {
|
||||
Node next = node.next;
|
||||
pre.next = next;
|
||||
next.pre = pre;
|
||||
|
||||
node.pre = null;
|
||||
node.next = null;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user