From 5e150b8614f6d66368cf75e2eace4dae2a4079fb Mon Sep 17 00:00:00 2001 From: KayKong Date: Tue, 16 Oct 2018 21:18:56 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E7=BC=93=E5=AD=98.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- notes/缓存.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/notes/缓存.md b/notes/缓存.md index 07a9e866..3a3e8140 100644 --- a/notes/缓存.md +++ b/notes/缓存.md @@ -88,12 +88,14 @@ public class LRU implements Iterable { 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 implements Iterable { Node next = node.next; pre.next = next; next.pre = pre; + + node.pre = null; + node.next = null; }