File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/data-structures/maps/hash-maps Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable no-bitwise, no-iterator, no-restricted-syntax */
2
+ const { TextEncoder } = require ( 'util' ) ;
2
3
const LinkedList = require ( '../../linked-lists/linked-list' ) ;
3
4
const { nextPrime } = require ( './primes' ) ;
4
5
@@ -55,14 +56,14 @@ class HashMap {
55
56
hashFunction ( key ) {
56
57
const bytes = encoding . encode ( key ) ;
57
58
const { length } = bytes ;
58
-
59
+
59
60
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
63
64
hash *= 16777619 ; // 32 bit FNV_prime
64
65
}
65
-
66
+
66
67
return ( hash >>> 0 ) % this . buckets . length ;
67
68
}
68
69
// end::hashFunction[]
You can’t perform that action at this time.
0 commit comments