File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed
src/data-structures/hash-maps Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,8 @@ function HashJavaMultiplication(key) {
309309}
310310
311311/**
312+ * http://isthe.com/chongo/tech/comp/fnv/
313+ * https://github.com/schwarzkopfb/fnv1a/blob/master/index.js
312314 * https://github.com/sindresorhus/fnv1a/blob/master/index.js
313315 * @param {* } key
314316 */
Original file line number Diff line number Diff line change @@ -137,19 +137,19 @@ function useBenchmark() {
137137 66.808 ops/s with HashMap4
138138 */
139139
140- suite . add ( 'Map (built-in)' , function ( ) {
141- const map = new Map ( ) ;
142- testMapOperations ( map ) ;
143- } )
140+ // .add('Map (built-in)', function() {
141+ // const map = new Map();
142+ // testMapOperations(map);
143+ // })
144144
145145 // HashMap3 x 543 ops/sec ±1.53% (84 runs sampled)
146- suite . add ( 'HashMap3' , function ( ) {
146+ . add ( 'HashMap3' , function ( ) {
147147 map = new HashMap3 ( ) ;
148148 testMapOperations ( map ) ;
149149 } )
150150
151151 // HashMap4 x 302 ops/sec ±2.09% (75 runs sampled)
152- suite . add ( 'HashMap4' , function ( ) {
152+ . add ( 'HashMap4' , function ( ) {
153153 map = new HashMap4 ( ) ;
154154 testMapOperations ( map ) ;
155155 } )
Original file line number Diff line number Diff line change @@ -41,7 +41,6 @@ class HashMap {
4141
4242 /**
4343 * Polynomial hash codes are used to hash String typed keys.
44- *
4544 * It uses FVN-1a hashing algorithm for 32 bits
4645 * @see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
4746 * @param {any } key
@@ -51,7 +50,7 @@ class HashMap {
5150 const str = String ( key ) ;
5251 let hash = 2166136261 ; // FNV_offset_basis (32 bit)
5352 for ( let i = 0 ; i < str . length ; i += 1 ) {
54- hash ^= str . codePointAt ( i ) ;
53+ hash ^= str . codePointAt ( i ) ; // XOR
5554 hash *= 16777619 ; // 32 bit FNV_prime
5655 }
5756 return ( hash >>> 0 ) % this . buckets . length ;
@@ -247,4 +246,7 @@ class HashMap {
247246 }
248247}
249248
249+ // Aliases
250+ HashMap . prototype . containsKey = HashMap . prototype . has ;
251+
250252module . exports = HashMap ;
You can’t perform that action at this time.
0 commit comments