Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
/ node-native-set Public archive

A native implementation of ES6 sets using C++11 unordered_set

License

Notifications You must be signed in to change notification settings

chad3814/node-native-set

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

es6-native-set

Set collection as specified in ECMAScript6

Uses native C++ unordered_set container, so the memory is stored outside of node and it is a lot faster than native JS implementations.

As of 2.0.0, requires node.js 0.12 or later. If you are running node.js 0.10, stick with the 1.x.x.

As of 3.6.0, es6-native-set implements @@iterator, so you can use all the iterable functions and operators.

Usage

var Set = require('es6-native-set');

Installation

$ npm install es6-native-set

API

Best is to refer to specification. Still if you want quick look, follow examples:

var Set = require('es6-native-set');

var set = new Set();

set.add('raz').add('dwa').add({});
set.size;                 // 3
set.has('raz');           // true
set.has('foo');           // false
set.add('foo');           // set
set.size                  // 4
set.has('foo');           // true
set.has('dwa');           // true
set.delete('dwa');        // true
set.size;                 // 3

set.forEach(function (value) {
  // 'raz', {}, 'foo' iterated
});

var iterator = set.values();

iterator.next(); // { done: false, value: 'raz' }
iterator.next(); // { done: false, value: {} }
iterator.next(); // { done: false, value: 'foo' }
iterator.next(); // { done: true, value: undefined }

set.clear(); // undefined
set.size; // 0

var setFromArray = new Set([1,2,3]);
setFromArray.has(1); // true
Array.from(setFromArray); // [1,2,3] (order may differ)
[...setFromArray]; // [1,2,3] (order may differ)

This package is made possible because of Grokker, one of the best places to work. If you are a JS developer looking for a new gig, send me an email at ['chad', String.fromCharCode(64), 'grokker', String.fromCharCode(0x2e), 'com'].join('').

About

A native implementation of ES6 sets using C++11 unordered_set

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •