@Test public void lruCache() { final int capacity = 8; final Map<Integer, Integer> map = new HashMap<>(); final List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); final LRUCache cache = new LRUCache(capacity); list.forEach(i -> { cache.insert(i, i); }); assertNull(cache.lookup(1)); assertNull(cache.lookup(2)); assertEquals(list.get(2), cache.lookup(3)); cache.insert(1, 1); assertNull(cache.lookup(4)); cache.remove(1); assertNull(cache.lookup(1)); }
public LRUCache(int capacity) { this.capacity = capacity; map = new HashMap<>(); head = new Node(-1, -1); tail = new Node(-1, -1); head.next = tail; tail.prev = head; }
LRUCache { public LRUCache(int capacity) { this.capacity = capacity; map = new HashMap<>(); head = new Node(-1, -1); tail = new Node(-1, -1); head.next = tail; tail.prev = head; } }
LRUCache { public LRUCache(int capacity) { this.capacity = capacity; map = new HashMap<>(); head = new Node(-1, -1); tail = new Node(-1, -1); head.next = tail; tail.prev = head; } LRUCache(int capacity); }
LRUCache { public LRUCache(int capacity) { this.capacity = capacity; map = new HashMap<>(); head = new Node(-1, -1); tail = new Node(-1, -1); head.next = tail; tail.prev = head; } LRUCache(int capacity); Integer lookup(Integer key); Integer insert(Integer key, Integer value); Integer remove(Integer key); }
LRUCache { public LRUCache(int capacity) { this.capacity = capacity; map = new HashMap<>(); head = new Node(-1, -1); tail = new Node(-1, -1); head.next = tail; tail.prev = head; } LRUCache(int capacity); Integer lookup(Integer key); Integer insert(Integer key, Integer value); Integer remove(Integer key);  }