Skip to content

maxtaco/redblack.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redblack.js

redblack.js is a red-black tree implementation for Node.js and the browser.

Usage

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);
});

Download

Releases are available on GitHub or via NPM.

npm install redblack

Development: redblack.js

Production: redblack.min.js

Tree API

insert(key, value)

Insert the given key/value pair into the tree.

Arguments:

  • key
  • value

get(key)

Get the value mapped to the given key or null if no such value exists.

Arguments:

  • key

delete(key)

Remove the given key from the tree

Arguments:

  • key

range(start, end)

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

forEach(iterator)

Cursor shortcut for iterating over the entire tree (see forEach below).

map(iterator)

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(iterator)

Map over a set of nodes in order.

Arguments:

  • iterator(value, key, tree) - should return a result

About

Red-black tree for Node.js and the browser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%