Skip to content

Commit a24c0d7

Browse files
Merge pull request #57 from amejiarosario/hotfix/hashmap
fix(hashmap): fix TextEncoder reference
2 parents 6974354 + e13ff88 commit a24c0d7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/data-structures/maps/hash-maps/hash-map.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-bitwise, no-iterator, no-restricted-syntax */
2+
const { TextEncoder } = require('util');
23
const LinkedList = require('../../linked-lists/linked-list');
34
const { nextPrime } = require('./primes');
45

@@ -55,14 +56,14 @@ class HashMap {
5556
hashFunction(key) {
5657
const bytes = encoding.encode(key);
5758
const { length } = bytes;
58-
59+
5960
let hash = 2166136261; // FNV_offset_basis (32 bit)
60-
61-
for (let i = 0; i < length; ) {
62-
hash ^= bytes[i++]; // XOR
61+
62+
for (let i = 0; i < length; i++) {
63+
hash ^= bytes[i]; // XOR
6364
hash *= 16777619; // 32 bit FNV_prime
6465
}
65-
66+
6667
return (hash >>> 0) % this.buckets.length;
6768
}
6869
// end::hashFunction[]

0 commit comments

Comments
 (0)