| 223 | } |
| 224 | |
| 225 | private removeItem(item: Item<K, V>): void { |
| 226 | if (item === this._head && item === this._tail) { |
| 227 | this._head = undefined; |
| 228 | this._tail = undefined; |
| 229 | } |
| 230 | else if (item === this._head) { |
| 231 | this._head = item.next; |
| 232 | } |
| 233 | else if (item === this._tail) { |
| 234 | this._tail = item.previous; |
| 235 | } |
| 236 | else { |
| 237 | const next = item.next; |
| 238 | const previous = item.previous; |
| 239 | if (!next || !previous) { |
| 240 | throw new Error('Invalid list'); |
| 241 | } |
| 242 | next.previous = previous; |
| 243 | previous.next = next; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | private touch(item: Item<K, V>, touch: Touch): void { |
| 248 | if (!this._head || !this._tail) { |