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

@mpaauw/data-structures-typescript

v0.1.3

Published

A collection of commonly used data structures written in TypeScript.

Downloads

4

Readme

Build npm version License: MIT

data-structures-typescript

A collection of commonly used data structures written in TypeScript.

Installation

To install, simply add as an npm dependency:

npm install @mpaauw/data-structures-typescript

Usage

This library offers a variety of data structures out-of-the-box. Currently supported structures include: Hash Table, Singly-Linked List, Queue, Stack, and Binary Search Tree. See the sections below for usage instructions.

HashTable

import { HashTable } from '@mpaauw/data-structures-typescript';

// instantiate a new Hash Table, choosing a default of 100 buckets
const hashTable = new HashTable<string, object>(100); 

// insert a new key-value pair into the Hash Table:
hashTable.put('cat', {
    name: 'Ms. Kitty',
    type: Animal.Cat,
    weightInLbs: 4.20
}); 

// retrieve an entry from the Hash Table, given a key:
const cat = hashTable.get('cat');

// determine whether or not the Hash Table is empty:
const isEmpty = hashTable.isEmpty();

// determine whether or not the Hash Table contains a given key:
const containsCat = hashTable.contains('cat');

// remove an entry from the Hash Table, given a key:
hashTable.remove('cat');

singly-Linked List

import { SinglyLinkedList } from '@mpaauw/data-structures-typescript';

// instantiate a new Singly-Linked List:
const singlyLinkedList = new SinglyLinkedList<string>();

// insert a value into the head of the list:
singlyLinkedList.insertAtHead('red');

// insert a value into the tail of the list:
singlyLinkedList.insertAtTail('blue');

// insert a value into a specific index of the list:
singlyLinkedList.insertAt(1, 'yellow');

// attempt to find a value within the linked list:
const valueFound = singlyLinkedList.find('green');

// attempt to find the value at a specific index within the list:
const valueFoundAt = singlyLinkedList.findAt(2);

// retrieve the head of the list:
const head = singlyLinkedList.getHead();

// retrieve the tail of the list:
const tail = singlyLinkedList.getTail();

// determines if the list is empty or not:
const isEmpty = singlyLinkedList.isEmpty();

// removes value from the head of the list:
singlyLinkedList.removeAtHead();

// removes value from the tail of the list:
singlyLinkedList.removeAtTail();

// removes value from a specified index within the list:
singlyLinkedList.removeAt(2);

Queue

import { Queue } from '@mpaauw/data-structures-typescript';

// instantiate a new Queue:
const queue = new Queue<string>();

// insert a value into the tail of the Queue:
queue.enqueue('dog');

// return the value from the head of the Queue:
const peekedValue = queue.peek();

// remove and return the value from the head of the Queue:
const dequeuedValue = queue.dequeue();

// determine if the Queue is empty or not:
const isEmpty = queue.isEmpty();

Stack

import { Stack } from '@mpaauw/data-structures-typescript';

// instantiate a new Stack:
const stack = new Stack<string>();

// insert a value onto the top of the Stack:
stack.push('fish');

// return the value from the top of the Stack:
const peekedValue = stack.peek();

// remove and return the value from the top of the Stack:
const poppedValue = stack.pop();

// determine if the Stack is empty or not:
const isEmpty = stack.isEmpty();

Binary Search Tree

import { BinarySearchTree } from '@mpaauw/data-structures-typescript';

// instantiate a new Binary Search Tree:
const binarySearchTree = new BinarySearchTree<number>();

// insert a value into the Tree, either iteratively or recursively:
binarySearchTree.insertIteratively(5);
binarySearchTree.insertRecursively(10);

// determine whether or not a value exists within the Tree:
const foundNode = binarySearchTree.find(9001);

// find the minimum value in the Tree, passing an optional node to be used as the subtree within the search:
const minNode = binarySearchTree.findMinimumNode(foundNode);

// find the maximum value within the Tree, passing an optional node to be used as the subtree within the search:
const maxNode = binarySearchTree.findMaximumNode(minNode);

// remove a value from the Tree, either iteratively or recursively:
binarySearchTree.removeIteratively(1337);
binarySearchTree.removeRecursively(420);

// determine whether or not the Tree is empty:
const isEmpty = binarySearchTree.isEmpty();

// validate whether or not the Tree maintains BST rules:
const isBST = binarySearchTree.validateRecursively();