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

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)

var SortedSet = require('SortedSet');
var set = SortedSet([5,4,2,1]);
// set will now contain 1, 2, 3, 4, 5 
var set = SortedSet(function(ab) {
    return a.val - b.val;
set.add({val: 5}, {val: 3});
// set now contains [{val: 3}, {val: 5}]; 
npm install sset

Obvious big things missing, namely:

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