evicting-cache 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/evicting-cache.js.map +1 -1
- package/package.json +14 -15
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../node_modules/.pnpm/@d1g1tal+collections@2.0.
|
|
3
|
+
"sources": ["../node_modules/.pnpm/@d1g1tal+collections@2.0.3_typescript@5.8.3/node_modules/@d1g1tal/collections/src/node.ts", "../node_modules/.pnpm/@d1g1tal+collections@2.0.3_typescript@5.8.3/node_modules/@d1g1tal/collections/src/keyed-node.ts", "../node_modules/.pnpm/@d1g1tal+collections@2.0.3_typescript@5.8.3/node_modules/@d1g1tal/collections/src/linked-map.ts", "../src/evicting-cache.ts"],
|
|
4
4
|
"sourcesContent": ["type NodeOptions<E> = Partial<Omit<Node<E>, 'value'>> & { value: E };\n\n/**\n * JavaScript implementation of a Node that can be used in a linked list.\n */\nexport class Node<E> {\n\tprotected $previous: Node<E> | null;\n\tprotected $next: Node<E> | null;\n\tprotected $value: E;\n\n\t/**\n\t * Creates a new node with the given value.\n\t *\n\t * @param {Node<E>} options The options for the node, or the node to copy.\n\t * @param {Node<E>} [options.previous] The previous node.\n\t * @param {Node<E>} [options.next] The next node.\n\t * @param {E} options.value The value to be assigned to the node.\n\t */\n\tconstructor({ previous = null, next = null, value }: NodeOptions<E>) {\n\t\tthis.$previous = previous;\n\t\tthis.$next = next;\n\t\tthis.$value = value;\n\t}\n\n\t/**\n\t * Gets the previous node.\n\t *\n\t * @returns {Node<E> | null} The previous node.\n\t */\n\tget previous(): Node<E> | null {\n\t\treturn this.$previous;\n\t}\n\n\t/**\n\t * Sets the previous node.\n\t *\n\t * @param {Node<E> | null} previous The previous node.\n\t */\n\tset previous(previous: Node<E> | null) {\n\t\tthis.$previous = previous;\n\t}\n\n\t/**\n\t * Gets the next node.\n\t *\n\t * @returns {Node<E> | null} The next node.\n\t */\n\tget next(): Node<E> | null {\n\t\treturn this.$next;\n\t}\n\n\t/**\n\t * Sets the next node.\n\t *\n\t * @param {Node<E> | null} next The next node.\n\t */\n\tset next(next: Node<E> | null) {\n\t\tthis.$next = next;\n\t}\n\n\t/**\n\t * Gets the value of the node.\n\t *\n\t * @returns {E} The value of the node.\n\t */\n\tget value(): E {\n\t\treturn this.$value;\n\t}\n\n\t/**\n\t * Sets the value of the node.\n\t *\n\t * @param {E} value The value of the node.\n\t */\n\tset value(value: E) {\n\t\tthis.$value = value;\n\t}\n\n\t/**\n\t * Unlinks this node from the list.\n\t *\n\t * @returns {void}\n\t */\n\tunlink(): void {\n\t\tif (this.$previous !== null) { this.$previous.next = this.$next }\n\n\t\tif (this.$next !== null) { this.$next.previous = this.$previous }\n\n\t\tthis.$previous = this.$next = null;\n\t}\n\n\t/**\n\t * Returns a string description of the class.\n\t *\n\t * @override\n\t * @returns {string} A string description of the class.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'Node';\n\t}\n}", "import { Node } from './node';\n\ntype KeyedNodeOptions<K, E> = Partial<Omit<KeyedNode<K, E>, 'value' | 'key'>> & { key: K, value: E };\n\n/** JavaScript implementation of a Node that can be used in a linked list. */\nexport class KeyedNode<K, E> extends Node<E> {\n\tprivate $key: K | null;\n\n\t/**\n\t * Creates a new node with the given value.\n\t *\n\t * @param {Object} options The options for the node, or the node to copy.\n\t * @param {KeyedNode<K, E>} [options.previous] The previous node.\n\t * @param {KeyedNode<K, E>} [options.next] The next node.\n\t * @param {K} options.key The key to be assigned to the node.\n\t * @param {E} options.value The value to be assigned to the node.\n\t */\n\tconstructor({ previous = null, next = null, key, value }: KeyedNodeOptions<K, E>) {\n\t\tsuper({ previous, next, value });\n\t\tthis.$key = key;\n\t}\n\n\t/**\n\t * Gets the key.\n\t *\n\t * @returns {K | null} The key.\n\t */\n\tget key(): K | null {\n\t\treturn this.$key;\n\t}\n\n\t/**\n\t * Sets the key.\n\t *\n\t * @param {K} key The key.\n\t */\n\tset key(key: K) {\n\t\tthis.$key = key;\n\t}\n\n\t/**\n\t * Gets the previous node.\n\t *\n\t * @returns {KeyedNode<K, E> | null} The previous node.\n\t */\n\toverride get previous(): KeyedNode<K, E> | null {\n\t\treturn this.$previous as KeyedNode<K, E>;\n\t}\n\n\t/**\n\t * Sets the previous node.\n\t *\n\t * @param {Node<E> | null} previous The previous node.\n\t */\n\toverride set previous(previous: KeyedNode<K, E> | null) {\n\t\tthis.$previous = previous;\n\t}\n\n\t/**\n\t * Gets the next node.\n\t *\n\t * @returns {Node<E> | null} The next node.\n\t */\n\toverride get next(): KeyedNode<K, E> | null {\n\t\treturn this.$next as KeyedNode<K, E>;\n\t}\n\n\t/**\n\t * Sets the next node.\n\t *\n\t * @param {KeyedNode<K, E> | null} next The next node.\n\t */\n\toverride set next(next: KeyedNode<K, E> | null) {\n\t\tthis.$next = next;\n\t}\n\n\t/**\n\t * Gets the value of the node.\n\t *\n\t * @returns {E} The value of the node.\n\t */\n\toverride get value(): E {\n\t\treturn this.$value;\n\t}\n\n\t/**\n\t * Sets the value of the node.\n\t *\n\t * @param {E} value The value of the node.\n\t */\n\toverride set value(value: E) {\n\t\tthis.$value = value;\n\t}\n\n\t/**\n\t * Gets the string description of the class.\n\t *\n\t * @override\n\t * @returns {string} The string description of the class.\n\t */\n\toverride get [Symbol.toStringTag](): string {\n\t\treturn 'KeyedNode';\n\t}\n}", "import { KeyedNode } from './keyed-node';\n\n/** A Map that maintains insertion order. */\nexport class LinkedMap<K, V> {\n\tprivate readonly $map: Map<K, KeyedNode<K, V>>;\n\tprivate $head: KeyedNode<K, V> | null = null;\n\tprivate $tail: KeyedNode<K, V> | null = null;\n\n\t/**\n\t * Initializes an empty LinkedMap.\n\t */\n\tconstructor() {\n\t\tthis.$map = new Map();\n\t}\n\n\t/**\n\t * Retrieves the value associated with a given key.\n\t *\n\t * @param {K} key The key to retrieve.\n\t * @returns {V | undefined} The value associated with the key, or undefined if the key is not in the map.\n\t */\n\tget(key: K): V | undefined {\n\t\treturn this.$map.get(key)?.value;\n\t}\n\n\t/**\n\t * Associates the specified value with the specified key in this map.\n\t *\n\t * @param {K} key The key with which the specified value is to be associated.\n\t * @param {V} value The value to be associated with the specified key.\n\t */\n\tset(key: K, value: V): void {\n\t\tconst node = this.$map.get(key);\n\n\t\tif (node !== undefined) {\n\t\t\tnode.value = value;\n\t\t\tthis.$moveToLast(node);\n\t\t} else {\n\t\t\tthis.appendNewNode(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the mapping for a key from this map if it is present.\n\t *\n\t * @param {K} key The key whose mapping is to be removed from the map.\n\t * @returns {boolean} True if the map contained a mapping for the specified key, false otherwise.\n\t */\n\tremove(key: K | null): boolean {\n\t\tif (key === null) { return false }\n\t\treturn this.unlinkNode(this.$map.get(key)) ? this.$map.delete(key) : false;\n\t}\n\n\t/**\n\t * Adds a new node to the beginning of the list.\n\t * If the key already exists, it will be moved to the beginning of the list.\n\t * If the key does not exist, a new node will be created and added to the beginning of the list.\n\t * If the list is empty, the new node will be both the head and the tail.\n\t * If the list is not empty, the new node will be the head.\n\t * If the key already exists, the value will be updated.\n\t *\n\t * @param {K} key The key of the new node.\n\t * @param {V} value The value of the new node.\n\t * @returns {void}\n\t */\n\taddFirst(key: K, value: V): void {\n\t\tconst node = this.$map.get(key);\n\n\t\tif (node !== undefined) {\n\t\t\tthis.$moveToFirst(node);\n\t\t\tnode.value = value;\n\t\t} else {\n\t\t\tthis.prependNewNode(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new node to the end of the list.\n\t * If the key already exists, it will be moved to the end of the list.\n\t * If the key does not exist, a new node will be created and added to the end of the list.\n\t * If the list is empty, the new node will be both the head and the tail.\n\t * If the list is not empty, the new node will be the tail.\n\t * If the key already exists, the value will be updated.\n\t *\n\t * @param {K} key The key of the new node.\n\t * @param {V} value The value of the new node.\n\t * @returns {void}\n\t */\n\taddLast(key: K, value: V): void {\n\t\tconst node = this.$map.get(key);\n\n\t\tif (node !== undefined) {\n\t\t\tthis.$moveToLast(node);\n\t\t\tnode.value = value;\n\t\t} else {\n\t\t\tthis.appendNewNode(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * Moves the node with the specified key to the beginning of the list.\n\t * If the key does not exist, nothing will happen.\n\t * If the node is already the head, nothing will happen.\n\t * If the node is the tail, the tail will be updated to be the previous node.\n\t * If the node is not the tail, the next node's previous pointer will be updated to point to the previous node.\n\t * The node's previous pointer will be updated to point to null.\n\t * The node's next pointer will be updated to point to the head.\n\t * The head's previous pointer will be updated to point to the node.\n\t * The head will be updated to point to the node.\n\t * If the node is the tail, the tail will be updated to be the previous node.\n\t * If the node is not the tail, the next node's previous pointer will be updated to point to the previous node.\n\t *\n\t * @param {K} key The key of the node to move to the beginning of the list.\n\t * @returns {void}\n\t */\n\tmoveToFirst(key: K): void {\n\t\tthis.$moveToFirst(this.$map.get(key));\n\t}\n\n\t/**\n\t * Moves the node with the specified key to the end of the list.\n\t * If the key does not exist, nothing will happen.\n\t * If the node is already the tail, nothing will happen.\n\t * If the node is the head, the head will be updated to be the next node.\n\t * If the node is neither the head nor the tail, the previous node's next pointer will be updated to point to the next node.\n\t * The node's previous pointer will be updated to point to the old tail.\n\t * The old tail's next pointer will be updated to point to the node.\n\t * The tail will be updated to point to the node.\n\t * The node's next pointer will be updated to point to null.\n\t * If the key already exists, the value will be updated.\n\t *\n\t * @param {K} key The key of the node to move to the end of the list.\n\t * @returns {void}\n\t */\n\tmoveToLast(key: K): void {\n\t\tthis.$moveToLast(this.$map.get(key));\n\t}\n\n\t/**\n\t * Returns the value to which the first key is mapped, or null if this map contains no mappings.\n\t *\n\t * @returns {V|null} The value to which the first key is mapped, or null if this map contains no mappings.\n\t */\n\tgetFirst(): V | null {\n\t\treturn this.$head?.value ?? null;\n\t}\n\n\t/**\n\t * Returns the value to which the last key is mapped, or null if this map contains no mappings.\n\t *\n\t * @returns {V|null} The value to which the last key is mapped, or null if this map contains no mappings.\n\t */\n\tgetLast(): V | null {\n\t\treturn this.$tail?.value ?? null;\n\t}\n\n\t/**\n\t * Removes the first key and its corresponding value from this map.\n\t * If the map is empty, nothing will happen.\n\t * If the map is not empty, the head will be updated to be the next node.\n\t * If the map is not empty and the head is not null, the head's previous pointer will be updated to point to null.\n\t * The node will be removed from the map.\n\t * The node's previous and next pointers will be updated to point to null.\n\t *\n\t * @returns {boolean} True if the first key and its corresponding value were removed, false otherwise.\n\t */\n\tremoveFirst(): boolean {\n\t\treturn this.$head === null ? false : this.remove(this.$head.key);\n\t}\n\n\t/**\n\t * Removes the last key and its corresponding value from this map.\n\t * If the map is empty, nothing will happen.\n\t * If the map is not empty, the tail will be updated to be the previous node.\n\t * If the map is not empty and the tail is not null, the tail's next pointer will be updated to point to null.\n\t * The node will be removed from the map.\n\t * The node's previous and next pointers will be updated to point to null.\n\t * If the key does not exist, nothing will happen.\n\t * If the node is already the tail, nothing will happen.\n\t *\n\t * @returns {boolean} True if the last key and its corresponding value were removed, false otherwise.\n\t */\n\tremoveLast(): boolean {\n\t\treturn this.$tail === null ? false : this.remove(this.$tail.key);\n\t}\n\n\t/**\n\t * Returns a boolean indicating whether the map contains a specific key.\n\t *\n\t * @param {K} key The key to check.\n\t * @returns {boolean} True if the map contains the key, false otherwise.\n\t */\n\thas(key: K): boolean {\n\t\treturn this.$map.has(key);\n\t}\n\n\t/**\n\t * Executes a provided function once for each key-value pair in the map.\n\t *\n\t * @param {function(V, K, LinkedMap<K, V>): void} callback - Function to execute for each key-value pair.\n\t * @param {any} [thisArg=this] - Value to use as `this` when executing the callback.\n\t * @returns {void}\n\t */\n\tforEach(callback: (value: V, key: K, thisArg: LinkedMap<K, V>) => void, thisArg: unknown = this): void {\n\t\tfor (const [ key, value ] of this) { callback.call(thisArg, value as V, key as K, this) }\n\t}\n\n\t/**\n\t * Removes all of the mappings from this map. The map will be empty after this call returns.\n\t */\n\tclear(): void {\n\t\tthis.$map.clear();\n\t\tthis.$head = this.$tail = null;\n\t}\n\n\tget size(): number {\n\t\treturn this.$map.size;\n\t}\n\n\t/**\n\t * Returns an iterator that yields all keys in the map in their insertion order.\n\t *\n\t * @yields {K} An iterator for the keys in the map.\n\t */\n\t*keys(): Generator<K | null, void, unknown> {\n\t\tfor (const [ key ] of this) { yield key }\n\t}\n\n\t/**\n\t * Returns an iterator that yields all values in the map in their insertion order.\n\t *\n\t * @yields {V} An iterator for the values in the map.\n\t */\n\t*values(): Generator<V | null, void, unknown> {\n\t\tfor (const [ _key , value ] of this) { yield value }\n\t}\n\n\t/**\n\t * Returns an iterator that yields all key-value pairs in the map as arrays in their insertion order.\n\t *\n\t * @yields {[K, V]} An iterator for the key-value pairs in the map.\n\t */\n\t*entries(): Generator<[K | null, V | null], void, unknown> {\n\t\tyield* this;\n\t}\n\n\t/**\n\t * Returns an iterator that yields all key-value pairs in the map as arrays in their insertion order.\n\t *\n\t * @yields {[K, V]} An iterator for the key-value pairs in the map.\n\t */\n\t*[Symbol.iterator](): Generator<[K | null, V | null], void, unknown> {\n\t\tfor (let node = this.$head; node !== null; node = node.next) { yield [ node.key, node.value ] }\n\t}\n\n\t/**\n\t * Returns a string description of the class.\n\t *\n\t * @returns {string} A string description of the class.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'LinkedMap';\n\t}\n\n\t/**\n\t * Moves the node to the end of the list.\n\t * If the node is already the tail, nothing will happen.\n\t * If the node is not in the map, nothing will happen.\n\t * If the node is the head, the head will be updated to be the next node.\n\t * If the node is not the head, the node's previous pointer will be updated to point to the node's next node.\n\t * If the node is not the tail, the node's next pointer will be updated to point to null.\n\t * The node will be added to the end of the list.\n\t * The node's previous pointer will be updated to point to the current tail.\n\t * The current tail's next pointer will be updated to point to the node.\n\t *\n\t * @private\n\t * @param {KeyedNode<K, V>} node The node to move to the end of the list.\n\t * @returns {boolean} True if the node was moved to the end of the list, false otherwise.\n\t */\n\tprivate unlinkNode(node?: KeyedNode<K, V>): boolean {\n\t\tif (node === undefined) { return false }\n\n\t\t// Handle previous node\n\t\tif (node.previous !== null) {\n\t\t\tnode.previous.next = node.next;\n\t\t} else {\n\t\t\tthis.$head = node.next;\n\t\t}\n\n\t\t// Handle next node\n\t\tif (node.next !== null) {\n\t\t\tnode.next.previous = node.previous;\n\t\t} else {\n\t\t\tthis.$tail = node.previous;\n\t\t}\n\n\t\t// Clean up the removed node's pointers\n\t\tnode.previous = null;\n\t\tnode.next = null;\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Adds a new node to the beginning of the list.\n\t * If the key already exists, the node will be moved to the beginning of the list.\n\t * If the key does not exist, a new node will be created and added to the beginning of the list.\n\t * If the key already exists, the node's value will be updated to the new value.\n\t * If the key does not exist, the node's value will be set to the new value.\n\t * If the key already exists, the node will be moved to the beginning of the list.\n\t * If the key does not exist, the node will be added to the beginning of the list.\n\t *\n\t * @private\n\t * @param {K} key The key of the node to add.\n\t * @param {V} value The value of the node to add.\n\t * @returns {void}\n\t */\n\tprivate prependNewNode(key: K, value: V): void {\n\t\tconst newNode = new KeyedNode({ key, value });\n\n\t\tthis.$map.set(key, newNode);\n\n\t\tif (this.$head === null) {\n\t\t\tthis.$head = this.$tail = newNode;\n\t\t} else {\n\t\t\tnewNode.next = this.$head;\n\t\t\tthis.$head.previous = newNode;\n\t\t\tthis.$head = newNode;\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new node to the end of the list.\n\t * If the key already exists, the node will be moved to the end of the list.\n\t * If the key does not exist, a new node will be created and added to the end of the list.\n\t * If the key already exists, the node's value will be updated to the new value.\n\t * If the key does not exist, the node's value will be set to the new value.\n\t * If the key already exists, the node will be moved to the end of the list.\n\t * If the key does not exist, the node will be added to the end of the list.\n\t *\n\t * @private\n\t * @param {K} key The key of the node to add.\n\t * @param {V} value The value of the node to add.\n\t * @returns {void}\n\t */\n\tprivate appendNewNode(key: K, value: V): void {\n\t\tconst newNode = new KeyedNode({ key, value });\n\n\t\tthis.$map.set(key, newNode);\n\n\t\tif (this.$head === null) {\n\t\t\tthis.$head = this.$tail = newNode;\n\t\t} else {\n\t\t\tnewNode.previous = this.$tail;\n\t\t\tthis.$tail!.next = newNode;\n\t\t\tthis.$tail = newNode;\n\t\t}\n\t}\n\n\t/**\n\t * Moves the node to the beginning of the list.\n\t * If the node is already the head, nothing will happen.\n\t * If the node is not in the map, nothing will happen.\n\t * If the node is the tail, the tail will be updated to be the previous node.\n\t * If the node is not the tail, the node's next pointer will be updated to point to the node's previous node.\n\t * If the node is not the head, the node's previous pointer will be updated to point to null.\n\t * The node will be added to the beginning of the list.\n\t * The node's next pointer will be updated to point to the current head.\n\t * The current head's previous pointer will be updated to point to the node.\n\t *\n\t * @private\n\t * @param {KeyedNode<K, V>} node The node to move to the beginning of the list.\n\t * @returns {void}\n\t */\n\tprivate $moveToFirst(node?: KeyedNode<K, V>): void {\n\t\tif (node === undefined || node === this.$head) { return }\n\n\t\tthis.unlinkNode(node);\n\n\t\t// Add the node at the start\n\t\tnode.next = this.$head;\n\t\tthis.$head!.previous = node;\n\t\tthis.$head = node;\n\t}\n\n\t/**\n\t * Moves the node to the end of the list.\n\t * If the node is already the tail, nothing will happen.\n\t * If the node is not in the map, nothing will happen.\n\t * If the node is the head, the head will be updated to be the next node.\n\t * If the node is not the head, the node's previous pointer will be updated to point to the node's next node.\n\t * If the node is not the tail, the node's next pointer will be updated to point to null.\n\t * The node will be added to the end of the list.\n\t * The node's previous pointer will be updated to point to the current tail.\n\t *\n\t * @private\n\t * @param {KeyedNode<K, V>} node The node to move to the end of the list.\n\t * @returns {void}\n\t */\n\tprivate $moveToLast(node?: KeyedNode<K, V>): void {\n\t\tif (node === undefined || node === this.$tail) { return }\n\n\t\tthis.unlinkNode(node);\n\n\t\t// Add the node at the end\n\t\tnode.previous = this.$tail;\n\t\tthis.$tail!.next = node;\n\t\tthis.$tail = node;\n\t}\n}", "import { LinkedMap } from '@d1g1tal/collections/src';\n\n/** JavaScript implementation of a Least Recently Used(LRU) Cache using a doubly linked list. */\nexport class EvictingCache<K, V> {\n\tprivate readonly $capacity: number;\n\tprivate readonly cache: LinkedMap<K, V>;\n\n\t/**\n\t * Creates a new Evicting Cache with the given capacity.\n\t *\n\t * @param {number} [capacity=100] The maximum number of key-value pairs the cache can hold.\n\t */\n\tconstructor(capacity: number = 100) {\n\t\tif (capacity < 1) { throw new RangeError('capacity must be greater than 0') }\n\t\tif (!Number.isInteger(capacity)) { throw new RangeError('capacity must be an integer') }\n\n\t\tthis.$capacity = capacity;\n\t\tthis.cache = new LinkedMap();\n\t}\n\n\t/**\n\t * Returns the value associated with the given key from the cache and updates the LRU order.\n\t *\n\t * @param {K} key The key to get the value for.\n\t * @returns {V | null} The associated value if the key is in the cache, or null otherwise.\n\t */\n\tget(key: K): V | null {\n\t\tconst value = this.cache.get(key);\n\t\tif (!value) { return null }\n\n\t\tthis.cache.moveToFirst(key);\n\n\t\treturn value;\n\t}\n\n\t/**\n\t * Returns true if the given key is in the cache, false otherwise.\n\t *\n\t * @param {K} key The key to check.\n\t * @returns {boolean} True if the key is in the cache, false otherwise.\n\t */\n\thas(key: K): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Adds a new key-value pair to the cache and updates the LRU order.\n\t * If adding the new pair will exceed the capacity, removes the least recently used pair from the cache.\n\t *\n\t * @param {K} key The key to add.\n\t * @param {V} value The value to add.\n\t * @returns {void}\n\t */\n\tput(key: K, value: V): void {\n\t\tthis.putAndEvict(key, value);\n\t}\n\n\t/**\n\t * Returns the value for the key if it exists in the cache. If not, put the key-value pair into the cache and return the value.\n\t * @param {K} key The key.\n\t * @param {function(): V} producer The value to put if the key does not exist in the cache.\n\t * @returns {V} The value corresponding to the key.\n\t */\n\tgetOrPut(key: K, producer: () => V): V {\n\t\treturn this.get(key) ?? this.putAndEvict(key, producer());\n\t}\n\n\t/**\n\t * Removes the least recently used key-value pair from the cache.\n\t *\n\t * @returns {boolean} True if an item was removed, false otherwise.\n\t */\n\tevict(): boolean {\n\t\treturn this.cache.size ? this.cache.removeLast() : false;\n\t}\n\n\t/**\n\t * Clears the cache and the LRU list.\n\t *\n\t * @returns {void}\n\t */\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n\n\t/**\n\t * Gets the capacity of the cache.\n\t * This is the maximum number of key-value pairs the cache can hold.\n\t * This is not the number of key-value pairs in the cache.\n\t *\n\t * @readonly\n\t * @returns {number} The capacity of the cache.\n\t */\n\tget capacity(): number {\n\t\treturn this.$capacity;\n\t}\n\n\t/**\n\t * Gets the size of the cache.\n\t * This is the number of key-value pairs in the cache.\n\t * This is not the capacity of the cache.\n\t * The capacity is the maximum number of key-value pairs the cache can hold.\n\t * The size is the number of key-value pairs currently in the cache.\n\t * The size will be less than or equal to the capacity.\n\t *\n\t * @returns {number} The size of the cache.\n\t */\n\tget size(): number {\n\t\treturn this.cache.size;\n\t}\n\n\t/**\n\t * Gets the description of the object.\n\t *\n\t * @override\n\t * @returns {string} The description of the object.\n\t */\n\tget [Symbol.toStringTag](): string {\n\t\treturn 'EvictingCache';\n\t}\n\n\tprivate putAndEvict(key: K, value: V): V {\n\t\tthis.cache.addFirst(key, value);\n\t\tif (this.cache.size > this.$capacity) { this.evict() }\n\n\t\treturn value;\n\t}\n}"],
|
|
5
5
|
"mappings": "AAKO,IAAMA,EAAN,KAAc,CACV,UACA,MACA,OAUV,YAAY,CAAE,SAAAC,EAAW,KAAM,KAAAC,EAAO,KAAM,MAAAC,CAAM,EAAmB,CACpE,KAAK,UAAYF,EACjB,KAAK,MAAQC,EACb,KAAK,OAASC,CACf,CAOA,IAAI,UAA2B,CAC9B,OAAO,KAAK,SACb,CAOA,IAAI,SAASF,EAA0B,CACtC,KAAK,UAAYA,CAClB,CAOA,IAAI,MAAuB,CAC1B,OAAO,KAAK,KACb,CAOA,IAAI,KAAKC,EAAsB,CAC9B,KAAK,MAAQA,CACd,CAOA,IAAI,OAAW,CACd,OAAO,KAAK,MACb,CAOA,IAAI,MAAMC,EAAU,CACnB,KAAK,OAASA,CACf,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", "next", "value", "KeyedNode", "Node", "previous", "next", "key", "value", "LinkedMap", "key", "value", "node", "callback", "thisArg", "_key", "newNode", "KeyedNode", "EvictingCache", "capacity", "LinkedMap", "key", "value", "producer"]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evicting-cache",
|
|
3
3
|
"author": "D1g1talEntr0py",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "Cache implementation with an LRU evicting policy",
|
|
7
7
|
"type": "module",
|
|
@@ -23,23 +23,22 @@
|
|
|
23
23
|
"evicting-lru-cache"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@d1g1tal/collections": "^2.0.
|
|
26
|
+
"@d1g1tal/collections": "^2.0.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@eslint/compat": "^1.
|
|
29
|
+
"@eslint/compat": "^1.3.1",
|
|
30
30
|
"@types/eslint": "^9.6.1",
|
|
31
|
-
"@types/
|
|
32
|
-
"@
|
|
33
|
-
"@typescript-eslint/
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"eslint-plugin-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"typescript": "^
|
|
41
|
-
"
|
|
42
|
-
"vitest": "^2.1.1"
|
|
31
|
+
"@types/node": "^24.0.15",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
33
|
+
"@typescript-eslint/parser": "^8.37.0",
|
|
34
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
35
|
+
"eslint": "^9.31.0",
|
|
36
|
+
"eslint-plugin-compat": "^6.0.2",
|
|
37
|
+
"eslint-plugin-jsdoc": "^51.4.1",
|
|
38
|
+
"globals": "^16.3.0",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"typescript-eslint": "^8.37.0",
|
|
41
|
+
"vitest": "^3.2.4"
|
|
43
42
|
},
|
|
44
43
|
"browserslist": [
|
|
45
44
|
"defaults",
|