项目作者: ryanmorr

项目描述 :
Accelerated hash maps
高级语言: JavaScript
项目地址: git://github.com/ryanmorr/fastmap.git
创建时间: 2016-09-08T19:46:51Z
项目社区:https://github.com/ryanmorr/fastmap

开源协议:The Unlicense

下载


fastmap

Version Badge
License
Build Status

Accelerated hash maps

Description

Creates an efficient key/value store by instantiating a constructor function with an empty prototype. This is faster than using Object.create(null) to create “bare” objects, @tverwaes/setting-up-prototypes-in-v8-ec9c9491dfe2#5f62">particularly in V8, making it the superior alternative for hash maps in memory intensive tasks. Full credit to Node.js for the technique.

Install

Download the CJS, ESM, UMD versions or install via NPM:

  1. npm install @ryanmorr/fastmap

Usage

Use just like an object literal:

  1. import fastmap from '@ryanmorr/fastmap';
  2. const map = fastmap();
  3. map.foo = 1;
  4. map.bar = 2;
  5. {}.toString.call(map); //=> "[object Object]"
  6. JSON.stringify(map); //=> "{\"foo\":1,\"bar\":2}"

Unlike object literals, the object is empty:

  1. 'toString' in {}; //=> true
  2. 'toString' in fastmap(); //=> false
  3. for (const key in map) {
  4. // `hasOwnProperty` check is unnecessary
  5. }

Provide an object to pre-populate the map:

  1. const map = fastmap(foo: 1, bar: 2, baz: 3});
  2. map.foo; //=> 1
  3. map.bar; //=> 2
  4. map.baz; //=> 3

License

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