From 69c3a16f75175fa6f49cd936e0049fdc6ede1da4 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Tue, 24 Jan 2023 09:04:02 +0100 Subject: [PATCH] Refactor LRU Cache. --- src/data-structures/lru-cache/LRUCache.js | 23 +++++++++++++++++-- .../lru-cache/LinkedListNode.js | 17 -------------- 2 files changed, 21 insertions(+), 19 deletions(-) delete mode 100644 src/data-structures/lru-cache/LinkedListNode.js diff --git a/src/data-structures/lru-cache/LRUCache.js b/src/data-structures/lru-cache/LRUCache.js index dc27d1b4..09bf58e4 100644 --- a/src/data-structures/lru-cache/LRUCache.js +++ b/src/data-structures/lru-cache/LRUCache.js @@ -1,5 +1,24 @@ -/* eslint-disable no-param-reassign */ -import LinkedListNode from './LinkedListNode'; +/* eslint-disable no-param-reassign, max-classes-per-file */ + +/** + * 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 diff --git a/src/data-structures/lru-cache/LinkedListNode.js b/src/data-structures/lru-cache/LinkedListNode.js deleted file mode 100644 index 6c2b3cd6..00000000 --- a/src/data-structures/lru-cache/LinkedListNode.js +++ /dev/null @@ -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;