We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 6974354 + e13ff88 commit a24c0d7Copy full SHA for a24c0d7
src/data-structures/maps/hash-maps/hash-map.js
@@ -1,4 +1,5 @@
1
/* eslint-disable no-bitwise, no-iterator, no-restricted-syntax */
2
+const { TextEncoder } = require('util');
3
const LinkedList = require('../../linked-lists/linked-list');
4
const { nextPrime } = require('./primes');
5
@@ -55,14 +56,14 @@ class HashMap {
55
56
hashFunction(key) {
57
const bytes = encoding.encode(key);
58
const { length } = bytes;
-
59
+
60
let hash = 2166136261; // FNV_offset_basis (32 bit)
61
- for (let i = 0; i < length; ) {
62
- hash ^= bytes[i++]; // XOR
+ for (let i = 0; i < length; i++) {
63
+ hash ^= bytes[i]; // XOR
64
hash *= 16777619; // 32 bit FNV_prime
65
}
66
67
return (hash >>> 0) % this.buckets.length;
68
69
// end::hashFunction[]
0 commit comments