mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01:18 +08:00
Refactor LRU Cache.
This commit is contained in:
parent
fbd77551b3
commit
69c3a16f75
@ -1,5 +1,24 @@
|
|||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign, max-classes-per-file */
|
||||||
import LinkedListNode from './LinkedListNode';
|
|
||||||
|
/**
|
||||||
|
* Simple implementation of the Doubly-Linked List Node
|
||||||
|
* that is used in LRUCache class below.
|
||||||
|
*/
|
||||||
|
class LinkedListNode {
|
||||||
|
/**
|
||||||
|
* Creates a doubly-linked list node.
|
||||||
|
* @param {string} key
|
||||||
|
* @param {any} val
|
||||||
|
* @param {LinkedListNode} prev
|
||||||
|
* @param {LinkedListNode} next
|
||||||
|
*/
|
||||||
|
constructor(key, val, prev = null, next = null) {
|
||||||
|
this.key = key;
|
||||||
|
this.val = val;
|
||||||
|
this.prev = prev;
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the LRU (Least Recently Used) Cache
|
* Implementation of the LRU (Least Recently Used) Cache
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
class LinkedListNode {
|
|
||||||
/**
|
|
||||||
* Creates a doubly-linked list node.
|
|
||||||
* @param {string} key
|
|
||||||
* @param {any} val
|
|
||||||
* @param {LinkedListNode} prev
|
|
||||||
* @param {LinkedListNode} next
|
|
||||||
*/
|
|
||||||
constructor(key, val, prev = null, next = null) {
|
|
||||||
this.key = key;
|
|
||||||
this.val = val;
|
|
||||||
this.prev = prev;
|
|
||||||
this.next = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default LinkedListNode;
|
|
Loading…
Reference in New Issue
Block a user