Fast Map built for keys that are always fixed size uniformly distributed buffers.
npm install turbo-hash-map
Uses a prefix trie to map hashes to values in an effectice manner.
const HashMap = require('turbo-hash-map')
const map = new HashMap()
map.set(hash('hello world'), 'a value')
function hash (val) { // any hash algo without practical collisions will work
return crypto.createHash('sha256').update(val).digest()
}
Create a new HashMap. The HashMap follows the api of a JS map, except keys are buffers containing hashes.
Insert a value with a hash as the key. Hash should be a fixed size buffer.
Get the value out. Returns undefined
if the value cannot be found.
Does the map have it?
Delete an entry.
How many entries?
Delete all entries.
Iterate the map. Yields arrays of [hash, value]
.
Key (hash) iterator.
Value iterator.
There is a bench included. On my macbook this yields
turbo-hash-map-set: 2.068s
turbo-hash-map-get: 1.931s
js-map-set: 16.078s
js-map-get: 6.626s
MIT