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
This commit is contained in:
Sambath Kumar Logakrishnan 2022-02-01 23:26:56 +01:00 committed by GitHub
parent 819f38f792
commit 5df28bd5b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;