mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
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:
parent
819f38f792
commit
5df28bd5b5
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user