MCPcopy
hub / github.com/trekhleb/javascript-algorithms / set

Method set

src/data-structures/lru-cache/LRUCache.js:63–72  ·  view source on GitHub ↗

* Sets the value to cache by its key. * Time complexity: O(1) in average. * @param {string} key * @param {any} val

(key, val)

Source from the content-addressed store, hash-verified

61 * @param {any} val
62 */
63 set(key, val) {
64 if (this.nodesMap[key]) {
65 const node = this.nodesMap[key];
66 node.val = val;
67 this.promote(node);
68 } else {
69 const node = new LinkedListNode(key, val);
70 this.append(node);
71 }
72 }
73
74 /**
75 * Promotes the node to the end of the linked list.

Callers 11

LRUCache.test.jsFile · 0.45
addMethod · 0.45
addChildMethod · 0.45
makeNodeRedMethod · 0.45
makeNodeBlackMethod · 0.45
swapNodeColorsMethod · 0.45
setPixelFunction · 0.45

Calls 2

promoteMethod · 0.95
appendMethod · 0.95

Tested by

no test coverage detected