MCPcopy Index your code
hub / github.com/trekhleb/javascript-algorithms / set

Method set

src/data-structures/hash-table/HashTable.js:51–64  ·  view source on GitHub ↗

* @param {string} key * @param {*} value

(key, value)

Source from the content-addressed store, hash-verified

49 * @param {*} value
50 */
51 set(key, value) {
52 const keyHash = this.hash(key);
53 this.keys[key] = keyHash;
54 const bucketLinkedList = this.buckets[keyHash];
55 const node = bucketLinkedList.find({ callback: (nodeValue) => nodeValue.key === key });
56
57 if (!node) {
58 // Insert new node.
59 bucketLinkedList.append({ key, value });
60 } else {
61 // Update value of existing node.
62 node.value.value = value;
63 }
64 }
65
66 /**
67 * @param {string} key

Callers 1

HashTable.test.jsFile · 0.45

Calls 3

hashMethod · 0.95
findMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected