hashset-native

0.0.2 • Public • Published

node-hashset

Provides a native hashset implementation for node.

Often, when you need to use a set in JavaScript, you may instead use a JavaScript object like so:

var cache = {};
 
cache['foobar'] = true;
 
if (!cache['foobar']) {
  ...
}

This works well for up to a few million items, but after that it starts to grind v8 down to a halt.

node-hashset implements a stricly typed hashset with std::unsorted_set to enable working with extremely large sets.

Installation

$ npm install hashset-native

Quick start

var HashSet = require('hashset-native');
var set = new HashSet.string();
set.add('foobar');

Checkout the tests for more examples.

HashSet

There are currently two HashSet constructors, HashSet.int32 and HashSet.string.

add(value)

Adds value to the set.

contains(value)

Returns a boolean value indicating if the set contains value.

iterator()

Returns an iterator to iterate over the values in the set.

var it = set.iterator();
 
while (it.hasNext()) {
  console.log(it.next());
}

remove(value)

Removes value from the set.

clear()

Removes all values from the set.

size()

Returns the numbers of values in the set.

Readme

Keywords

none

Package Sidebar

Install

npm i hashset-native

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • inolen