Skip to content
Branch: master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

fastmap

Version Badge Build Status License

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.

Install

Download the development or minified version, or install via NPM:

npm install @ryanmorr/fastmap

Usage

Use just like an object literal:

const map = fastmap();

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

{}.toString.call(map); //=> "[object Object]"
JSON.stringify(map); //=> "{\"foo\":1,\"bar\":2}"

Unlike object literals, the object is empty:

'toString' in {}; //=> true
'toString' in hashmap(); //=> 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});

map.foo; //=> 10
map.bar; //=> 2
map.baz; //=> 3

License

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

You can’t perform that action at this time.