Accelerated hash maps
JavaScript
Latest commit bedd31d Sep 8, 2016 @ryanmorr Add badges
Permalink
Failed to load latest commit information.
dist
src
test
.babelrc
.editorconfig
.eslintrc
.gitattributes
.gitignore
.travis.yml
README.md
UNLICENSE
gulpfile.babel.js
package.json

README.md

fastmap

GitHub version Build Status Size

Accelerated hash maps

Creates an efficient key/value store by instantiating a constructor function with an empty prototype. This is much faster than using either an object literal ({}) or a "bare" empty object (Object.create(null)), making it the superior alternative for hash maps in memory intensive tasks. Full credit to Node.js for the technique.

Usage

Use just like an object literal:

const map = fastmap();

map.foo = 1;
map.bar = 2;

console.log({}.toString.call(map)); // [object Object]

console.log(JSON.stringify(map)); // {"foo":1,"bar":2}

Unlike object literals, the object is empty:

console.log('toString' in {}); // true
console.log('toString' in fastmap()); // false

for (const key in map) {
    // `hasOwnProperty` check is unnecessary
}

Provide objects as arguments to pre-populate the map:

const map = fastmap({foo: 1}, {bar: 2}, {foo: 10, baz: 3});

console.log(map.foo) // 10
console.log(map.bar) // 2
console.log(map.baz) // 3

Installation

Fastmap is CommonJS and AMD compatible with no dependencies. You can download the development or minified version, or install it in one of the following ways:

npm install ryanmorr/fastmap

bower install ryanmorr/fastmap

Tests

Run unit tests in the command line by issuing the following commands:

npm install
npm install -g gulp
gulp test

License

This project is dedicated to the public domain as described by the Unlicense.