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

bst-lib

v1.0.1

Published

> In computer science, binary search trees (BST), sometimes called ordered or sorted binary trees, are a particular type of container: data structures that store "items" (such as numbers, names etc.) in memory. By https://en.wikipedia.org/wiki/Binary_sea

Downloads

11

Readme

Binary search tree

In computer science, binary search trees (BST), sometimes called ordered or sorted binary trees, are a particular type of container: data structures that store "items" (such as numbers, names etc.) in memory. By https://en.wikipedia.org/wiki/Binary_search_tree

The library was written in Typescript provides a binary tree data structure for storing or searching data.

NPM: https://www.npmjs.com/package/bst-lib GIT: https://github.com/edwardconnect/binary-search-tree

Install

npm i bst-lib

Example

Define and instantiate some mock objects.

class Mock {
    constructor(
    	public id: number,
    	public value: string
    ) { }
}
	
var mockA = new Mock(1, 'MockA');
var mockB = new Mock(2, 'MockB');
var mockC = new Mock(3, 'MockC');
var mockD = new Mock(4, 'MockD');
var mockE = new Mock(5, 'MockE');
    

Instantiate a Bst with type 'Mock'

	var bst = new Bst<Mock>()
	

Insert mock object into bst

bst.insert(mockA.id, mockA);
bst.insert(mockC.id, mockC);
bst.insert(mockB.id, mockB);
bst.insert(mockE.id, mockE);
bst.insert(mockD.id, mockD);

Print the bst

bst.print();
/* Print result
                5
                        4
        3
                2
1
*/

Properties

BstNode

| Name | Description | | ------------ | ------------ | | id: string | number | The id of bst node. The searching relies on comparing the value of id | | data: T | Store the data with generic type | | left: Bst<T>() | The left child node of this node | | right: Bst<T>() | The right child node of this node |

Bst

| Name | Description | | ------------ | ------------ | | private root: BstNode<T> = null | Point to a BstNode if not null |

Methods

| Name | Description | | ------------ | ------------ | | isEmpty(): boolean | Whether the node is Bst point to null | | isContains(id: string | number): boolean | Whether the bst contain data with target id | | getMaxId(): number | string | null | Find the largest id | | getMinId(): number | string | null | Find the smallest id | | getMaxData() :T | Find the data with largest id | | getMinData() :T | Find the data with smallest id | | searchDataById(id: number | string): T | null | Find the data by target id. Return null if not found | | print(depth: number = 0) | Print the tree in horizontally. (root on left and leafs on right) | | insert(id: string | number, data: T) | Insert data into bst by inputting id of the data and data itself | | remove(id: string | number) | Remove the data by id |