sset

Sorted Set in javascript for node that uses binary search for maintaining sort order

npm install sset
10 downloads in the last week
20 downloads in the last month

sset - Sorted Set for javascript

Yet another sorted set, but with the following feature set:

  • Uses binary-sort to insert and search and insert in set, so it is incredibly fast.
  • Can contain any kind of object
  • You can specify a custom comparator, if you have objects, strings etc (default uses number values)

Benchmark against array (though an array is not a set) benchmark

Usage:

var SortedSet = require('SortedSet');

var set = SortedSet([5,4,2,1]);

set.add(3);

// set will now contain 1, 2, 3, 4, 5

Custom comparator

var set = SortedSet(function(a, b) {
    return a.val - b.val;
});

set.add({val: 5}, {val: 3});

// set now contains [{val: 3}, {val: 5}];

Installation

npm install sset

Todo

Obvious big things missing, namely:

  • things handling other sets:
    • union
    • intersection
  • tests for all functionlity

License

MIT

npm loves you