This commit is contained in:
Sambath Kumar Logakrishnan 2024-07-17 10:41:37 +09:00 committed by GitHub
commit a6d951c874
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -85,7 +85,11 @@ export default class HashTable {
* @return {*} * @return {*}
*/ */
get(key) { 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 }); const node = bucketLinkedList.find({ callback: (nodeValue) => nodeValue.key === key });
return node ? node.value.value : undefined; return node ? node.value.value : undefined;