* Appends a new node to the end of the cache linked list. * @param {LinkedListNode} node
(node)
| 87 | * @param {LinkedListNode} node |
| 88 | */ |
| 89 | append(node) { |
| 90 | this.nodesMap[node.key] = node; |
| 91 | |
| 92 | if (!this.head.next) { |
| 93 | // First node to append. |
| 94 | this.head.next = node; |
| 95 | this.tail.prev = node; |
| 96 | node.prev = this.head; |
| 97 | node.next = this.tail; |
| 98 | } else { |
| 99 | // Append to an existing tail. |
| 100 | const oldTail = this.tail.prev; |
| 101 | oldTail.next = node; |
| 102 | node.prev = oldTail; |
| 103 | node.next = this.tail; |
| 104 | this.tail.prev = node; |
| 105 | } |
| 106 | |
| 107 | this.size += 1; |
| 108 | |
| 109 | if (this.size > this.capacity) { |
| 110 | this.evict(this.head.next); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Evicts (removes) the node from cache linked list. |
no test coverage detected