MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / put

Method put

javascript/0146-lru-cache.js:33–43  ·  view source on GitHub ↗
(key, value)

Source from the content-addressed store, hash-verified

31 }
32
33 put(key, value) {
34 const hasKey = this.get(key) !== -1;
35 const isAtCapacity = this.map.size === this.capacity;
36
37 if (hasKey) return (this.tail.prev.value = value);
38 if (isAtCapacity) this.removeLastUsed();
39
40 const node = { key, value };
41 this.map.set(key, node);
42 this.moveToFront(node);
43 }
44
45 moveToFront(node) {
46 const [prev, next] = [this.tail.prev, this.tail];

Callers

nothing calls this directly

Calls 4

getMethod · 0.95
removeLastUsedMethod · 0.95
moveToFrontMethod · 0.95
setMethod · 0.45

Tested by

no test coverage detected