From e13ff88d7f8f9b7f38844befedc001bc1a4b243f Mon Sep 17 00:00:00 2001 From: Adrian Mejia Date: Wed, 20 May 2020 11:22:12 -0400 Subject: [PATCH] fix(hashmap): fix TextEncoder reference --- src/data-structures/maps/hash-maps/hash-map.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/data-structures/maps/hash-maps/hash-map.js b/src/data-structures/maps/hash-maps/hash-map.js index 25889587..d5ea7382 100644 --- a/src/data-structures/maps/hash-maps/hash-map.js +++ b/src/data-structures/maps/hash-maps/hash-map.js @@ -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'); @@ -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[]