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

@idcom4/ts-bst

v1.0.0

Published

a package that provides an implementation of Binary Search Tree as well as Chained List

Downloads

4

Readme

Binary Search Tree

This implementation of a binary search tree is meant to be versatile, and easy to use.

Setup

To use this class, all you have to do is create a new instance of it and passing it the array of data you want to process:

import { BinarySearchTree } from '@idcom4/ts-bst'

const someArrayOfData: number[] = [ 18, 935, -47, 0, -1785, 5624, 3, 42, -415, 327, 98, 7 ]

const bst = new BinarySearchTree<number>(someArrayOfData)

And that's it, the tree is created and you have access to all its methods.

💡 Note:
The constructor also accepts some optional parameters:
A boolean that controls weither the provided array of data is to be used as is (and altered) or preserved,
which less optimized but also less intrusive. (default: false -> not preserved)
⚠️if original datas are preserved, it means they are deep copied and as such becomes POJOs And 2 functions, one to compare 2 datas, and one to stringify data nicely for logging purposes.
It is advised to provide them as well to get the best result out of the tree, tho it can operate without in simple cases.

import { BinarySearchTree } from '@idcom4/ts-bst'

interface IUser {
  name: string
  lastName: string,
  age: number
}

const someArrayOfData: IUser[] = [
  { name: 'John', lastName: 'Doe', age: 18 },
  { name: 'Bloody', lastName: 'Mary', age: 208 },
  { name: 'Jeanne', lastName: 'Calment', age: 123 },
  { name: 'Mickey', lastName: 'Mouse', age: 84 },
]

const compareData = (user1: IUser, user2: IUser): number => user1.age - user2.age
const dataToString = (user: IUser): string => `${user.name} ${user.lastName}`

const bst = new BinarySearchTree<IUser>(someArrayOfData, false, compareData, dataToString)

Usage

All of the tree methods are fairly straight-forward.

Tho a thing to know is the difference between the two print methods:

  • print()

    Logs the tree in a readable format, but it can quickly take a lot of screen space:

    print method output

  • printConcise()

    Logs the tree in a more barbaric way, but more concise as the name implies:

    printConcise method output