No description, website, or topics provided.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.npmignore
.travis.yml
Makefile
README.md
index.js
package.json

README.md

Build Status Coverage Status Dependency Status

Introduction

This lib provides a set that uses a binary tree as data structure. If you are able to hash all or object use a hash set instead, it is faster! If not and you can provide a complete lesser and equality function for your objects you can use this set.

Speed Comparison for insert, find, remove; HashSet is O(1) BinaryTree is O(log(n)) Array is O(n)

Installation

$ npm install specialized-set

Usage

var equalityFunction = function(a,b){return a == b};
var lesserFunction = function(a,b){return a < b};
var SpecializedSet = require('../')(equalityFunction, lesserFunction);

var set1 = new SpecializedSet(['a', 'd','c','c']);
var set2 = new SpecializedSet(['b','d','e']);

set1.add('x');
set1.values(); // ['a','c','d','x'];

set1.minus(new SpecializedSet(['x']))
set1.values(); // ['a','c','d'];
// or
SpecializedSet.minus(set1, new SpecializedSet(['x']))
set1.values(); // ['a','c','d'];

set1.union(set2).values(); // ['a','b','c','d','e'] 
// or
SpecializedSet.union(set1, set2).values(); // ['a','b','c','d','e'] 

set1.intersect(set2).values(); // ['d'] 
// or
SpecializedSet.intersect(set1, set2).values(); // ['d'] 

set1.equals(set2); // false
// or
SpecializedSet.equals(set1, set2)// false

set1.equals(new SpecializedSet(['a', 'd','c'])); // true

License

LGPLv3