simple-hashset

Simple hashsets for node

simple-hashset

Simple hashsets for node

npm install simple-hashset
var Set = require('simple-hashset');
 
var s = new Set('a', 'b', 'c');
 
console.log(s.contains('b'));
console.log(s.contains('d'));

This package simply uses objects as associative arrays. Therefore, using sets with objects or functions is not recommended.

var a = new Set();        // Creates an empty set 
var b = new Set(1, 2, 4); // Creates a set that contains 1, 2 and 3 
var c = new Set(b);       // Creates a copy of set b 

Returns true iff the set is empty.

Returns the cardinality of the set.

Returns true iff elem is an element of the set.

Adds elements to the set.

var s = new Set(1); // s = { 1 } 
 
s.add(2, 5, 7);     // s = { 1, 2, 5, 7 } 

Removes elements to the set.

var s = new Set(1, 2, 3, 4); // s = { 1, 2, 3, 4 } 
 
s.remove(2, 7);              // s = { 1, 3, 4 } 

Returns an array containing the elements of the set. The order of elements is unspecified.

Returns a new set containing the elements from this and the elements from that.

Returns a new set containing the elements from this which are not in that.

Returns a new set containing the elements from this which are also in that.

Returns a new set containing the elements that are in either this or that but not in both. This is the symmetric difference of sets.

Returns a new set containing elements mapped by f.

var a = new Set(2, 5);                     // a = { 2, 5 } 
var b = a.map(function(x) { return x+1 }); // b = { 3, 6 } 

Like map but f returns sets.

var a = new Set(2, 5);    // a = { 2, 5 } 
var f = function(x) {
  return new Set(x, x+3);
};
var b = a.flatMap(f);     // b = { 2, 5, 8 } 

Copyright (c) 2013 Johann-Michael Thiebaut <johann.thiebaut@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.