Compare commits

...

2 Commits

Author SHA1 Message Date
Sambath Kumar Logakrishnan
7a1b0020e0
Merge 5df28bd5b5 into 2c67b48c21 2024-04-25 08:31:17 +08:00
Sambath Kumar Logakrishnan
5df28bd5b5
Tweaked get function of HashTable
In case of key on present in table, now don't need to be compute hash for that key, then check corresponding list from bucket for that hash that key is present instead now agent will return expected undefined once there is no hash value present at fast lookup keys object
2022-02-01 23:26:56 +01:00

View File

@ -85,7 +85,11 @@ export default class HashTable {
* @return {*}
*/
get(key) {
const bucketLinkedList = this.buckets[this.hash(key)];
const computedHash = this.keys[key]?? null;
if(computedHash === null){
return undefined;
}
const bucketLinkedList = this.buckets[computedHash];
const node = bucketLinkedList.find({ callback: (nodeValue) => nodeValue.key === key });
return node ? node.value.value : undefined;