redblack.js is a red-black tree implementation for Node.js and the browser.
var tree = redblack.tree();
tree.insert('foo', 'bar');
tree.get('foo'); // -> 'bar'
tree.delete('foo');
tree.get('foo'); // -> null
tree.forEach(function(value, key) {
console.log(key + '=' + value);
});
Releases are available on GitHub or via NPM.
npm install redblack
Development: redblack.js
Production: redblack.min.js
Insert the given key/value pair into the tree.
Arguments:
- key
- value
Get the value mapped to the given key or null
if no such value exists.
Arguments:
- key
Remove the given key from the tree
Arguments:
- key
Returns a Cursor (see below) for traversing the tree in the given range (inclusive).
Arguments:
- start - the lower bound of the range, if
undefined
then assumed to be the minimum value in the tree - end - the upper bound of the range, if
undefined
the assumed to be the maximum value in the tree
Cursor shortcut for iterating over the entire tree (see forEach below).
Cursor shortcut for mapping over the entire tree (see map below).
Cursor API ---------- ### forEach(iterator)Iterate over a set of nodes in order.
Arguments:
- iterator(value, key, tree)
Map over a set of nodes in order.
Arguments:
- iterator(value, key, tree) - should return a result