Skip to content

Commit

Permalink
fix(hashmap): fix TextEncoder reference
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed May 20, 2020
1 parent 6974354 commit e13ff88
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/data-structures/maps/hash-maps/hash-map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-bitwise, no-iterator, no-restricted-syntax */
const { TextEncoder } = require('util');
const LinkedList = require('../../linked-lists/linked-list');
const { nextPrime } = require('./primes');

Expand Down Expand Up @@ -55,14 +56,14 @@ class HashMap {
hashFunction(key) {
const bytes = encoding.encode(key);
const { length } = bytes;

let hash = 2166136261; // FNV_offset_basis (32 bit)
for (let i = 0; i < length; ) {
hash ^= bytes[i++]; // XOR

for (let i = 0; i < length; i++) {
hash ^= bytes[i]; // XOR
hash *= 16777619; // 32 bit FNV_prime
}

return (hash >>> 0) % this.buckets.length;
}
// end::hashFunction[]
Expand Down

0 comments on commit e13ff88

Please sign in to comment.