You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the HashTable implementation currently there is no collision resolution mechanism. The following insertion method updates the existing node. There can be chaining or open addressing methods implemented.
insert(key, value) {
const bucketLinkedList = this.buckets[this.hash(key)];
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
if (!node) {
// Insert new node.
bucketLinkedList.append({ key, value });
} else {
// Update value of existing node.
node.value.value = value;
}
}
The text was updated successfully, but these errors were encountered:
@abrarShariar
Actually collisions are being handled by the set method of HashTable class. The code of set method looks exactly the same as you've provided:
set(key,value){constkeyHash=this.hash(key);this.keys[key]=keyHash;constbucketLinkedList=this.buckets[keyHash];constnode=bucketLinkedList.find({callback: nodeValue=>nodeValue.key===key});if(!node){// Insert new node.bucketLinkedList.append({ key, value });}else{// Update value of existing node.node.value.value=value;}}
In the HashTable implementation currently there is no collision resolution mechanism. The following insertion method updates the existing node. There can be chaining or open addressing methods implemented.
The text was updated successfully, but these errors were encountered: