npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rb-binary-search-tree

v1.0.3

Published

Implementation of Red/Black Binary Search Tree

Downloads

8

Readme

Overview

An implementation of a Red/Black Binary Search Tree.

Originally created in 2014, this library has been thouroughly tested and battle hardened.

Binary search trees exhibit the following characteristics: Insertion: O(log n) Removal: O(log n) Search: O(log n)

Thanks go to those responsible for this lecture which was supremely helpful: https://youtu.be/hm2GHwyKF1o?si=-WemyU80lZiaae_4

Example Usage:

const BinarySearchTree = require("rb-binary-search-tree");

const bst = new BinarySearchTree();

bst.insert(1, "Apple");
bst.insert(2, "Pear");
bst.insert(3, "Orange");

console.log(bst.find(1));   //Apple
console.log(bst.find(2));   //Pear
console.log(bst.find(3));   //Orange

console.log(bst.length());  //3
console.log(bst.min());     //1
console.log(bst.max());     //3

bst.remove(2);
console.log(bst.find(2)); //null


//To iterate over all entries use either inOrderTraverse() or reverseOrderTraverse()
//To iterate over a subset, use rangeTraverse()
bst.inOrderTraverse(console.log);   //Output:
                                    //1   Apple
                                    //3   Orange

bst.empty();


Methods

This library contains a class with the following methods:

instance.insert(key, data)

Adds an entry to the BST.

instance.remove(key)

Removes an entry from the BST.

instance.find(key)

Returns an entry from the BST.

instance.length()

Returns the number of entries in the BST.

instance.min()

Returns the lowest key value.

instance.max()

Returns the highest key value.

instance.inOrderTraverse(callBack)

Calls callback for every entry in the BST starting from the lowest key value up to the highest.

The arguments key and data shall be passed to the call back function.

instance.reverseOrderTraverse(callBack)

Calls callback for every entry in the BST starting from the highest key value down to the lowest.

The arguments key and data shall be passed to the call back function.

instance.rangeTraverse(from, to, callBack)

Calls callback for every entry in the BST starting from the highest key value down to the lowest.

The arguments key and data shall be passed to the call back function.

empty()

Removes all entries from the BST.