Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e13ff88

Browse files
fix(hashmap): fix TextEncoder reference
1 parent 6974354 commit e13ff88

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

Lines changed: 6 additions & 5 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /