Skip to content

Commit

Permalink
more links
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Sep 24, 2018
1 parent a21270f commit 62b5ce8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions benchmarks/hashing-functions.perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ function HashJavaMultiplication(key) {
}

/**
* http://isthe.com/chongo/tech/comp/fnv/
* https://github.com/schwarzkopfb/fnv1a/blob/master/index.js
* https://github.com/sindresorhus/fnv1a/blob/master/index.js
* @param {*} key
*/
Expand Down
12 changes: 6 additions & 6 deletions benchmarks/hashmap.perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ function useBenchmark() {
66.808 ops/s with HashMap4
*/

suite.add('Map (built-in)', function() {
const map = new Map();
testMapOperations(map);
})
// .add('Map (built-in)', function() {
// const map = new Map();
// testMapOperations(map);
// })

// HashMap3 x 543 ops/sec ±1.53% (84 runs sampled)
suite.add('HashMap3', function() {
.add('HashMap3', function() {
map = new HashMap3();
testMapOperations(map);
})

// HashMap4 x 302 ops/sec ±2.09% (75 runs sampled)
suite.add('HashMap4', function() {
.add('HashMap4', function() {
map = new HashMap4();
testMapOperations(map);
})
Expand Down
6 changes: 4 additions & 2 deletions src/data-structures/hash-maps/hashmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class HashMap {

/**
* Polynomial hash codes are used to hash String typed keys.
*
* It uses FVN-1a hashing algorithm for 32 bits
* @see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
* @param {any} key
Expand All @@ -51,7 +50,7 @@ class HashMap {
const str = String(key);
let hash = 2166136261; // FNV_offset_basis (32 bit)
for (let i = 0; i < str.length; i += 1) {
hash ^= str.codePointAt(i);
hash ^= str.codePointAt(i); // XOR
hash *= 16777619; // 32 bit FNV_prime
}
return (hash >>> 0) % this.buckets.length;
Expand Down Expand Up @@ -247,4 +246,7 @@ class HashMap {
}
}

// Aliases
HashMap.prototype.containsKey = HashMap.prototype.has;

module.exports = HashMap;

0 comments on commit 62b5ce8

Please sign in to comment.