Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    redblackpublic

    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

    Keywords

    none

    install

    npm i redblack

    Downloadslast 7 days

    0

    version

    0.1.2

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar