MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / LRUCache

Method LRUCache

java/Linked Lists/LRUCache.java:20–30  ·  view source on GitHub ↗
(int capacity)

Source from the content-addressed store, hash-verified

18 public DoublyLinkedListNode head;
19 public DoublyLinkedListNode tail;
20 public LRUCache(int capacity) {
21 this.capacity = capacity;
22 // A hash map that maps keys to nodes.
23 cache = new HashMap<>();
24 // Initialize the head and tail dummy nodes and connect them to
25 // each other to establish a basic two-node doubly linked list.
26 head = new DoublyLinkedListNode(-1, -1);
27 tail = new DoublyLinkedListNode(-1, -1);
28 head.next = tail;
29 tail.prev = head;
30 }
31
32 public int get(int key) {
33 if (!cache.containsKey(key)) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected