Skip to content

Commit b097303

Browse files
committed
refactor: improvemnts in _hash()
1 parent 8e33980 commit b097303

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/_DataStructures_/HashTable/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class HashTable {
3636
for (let i = 0; i < loopTill; i += 1) {
3737
const char = stringKey[i];
3838
const value = char.charCodeAt(0) - 96;
39-
index = (index * PRIME_MULTIPLIER + value) % this.bucket.length;
39+
// eslint-disable-next-line no-bitwise
40+
index &= index;
41+
index = index * PRIME_MULTIPLIER + value;
4042
if (this.strongHash) {
41-
index = (index + PRIME_ADDER) % this.bucket.length;
43+
index += PRIME_ADDER;
4244
}
4345
}
44-
return index;
46+
return Math.abs(index % this.bucket.length);
4547
}
4648

4749
_resize() {

0 commit comments

Comments
 (0)