Giter Club home page Giter Club logo

turbo-hash-map's Introduction

turbo-hash-map

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.

Usage

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()
}

API

const m = new HashMap()

Create a new HashMap. The HashMap follows the api of a JS map, except keys are buffers containing hashes.

m.set(hash, value)

Insert a value with a hash as the key. Hash should be a fixed size buffer.

const value = m.get(hash)

Get the value out. Returns undefined if the value cannot be found.

const bool = m.has(hash)

Does the map have it?

const deleted = m.delete(hash)

Delete an entry.

m.size

How many entries?

m.clear()

Delete all entries.

...m

Iterate the map. Yields arrays of [hash, value].

...m.keys()

Key (hash) iterator.

...m.values()

Value iterator.

Performance

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

License

MIT

turbo-hash-map's People

Contributors

mafintosh avatar kasperisager avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.