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 πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

dst-typescript-collection

v1.2.1

Published

πŸš€ Complete TypeScript Data Structures Library: Linked List, Hash Map, Concurrent HashMap, Stack, Queue, Set, Tree, BST, AVL Tree, Red-Black Tree, Graph, Heap, Trie with 100% test coverage, async-safe operations, and comprehensive algorithms. Perfect for

Readme

Data Structures in TypeScript

A comprehensive collection of data structures implemented in TypeScript with full test coverage.

πŸ“š Data Structures Implemented

1. Linked List (MyLinkedList)

  • Singly linked list with generic type support
  • Operations: append, prepend, remove, search, contains
  • Methods: getSize(), isEmpty(), toArray(), print(), clear()

2. Hash Map (MyHashMap)

  • Generic key-value storage with collision handling
  • Dynamic resizing and load factor management
  • Operations: put, get, remove, containsKey, containsValue
  • Methods: keys(), values(), entries(), getCapacity(), getLoadFactor()

3. Concurrent Hash Map (MyConcurrentHashMap)

  • Thread-safe hash map with async-safe operations
  • Built-in mutex for serialized access in concurrent environments
  • All operations are async and return Promises
  • Operations: put, get, remove, containsKey, containsValue (all async)
  • Methods: keys(), values(), entries(), getCapacity(), getLoadFactor() (all async)

4. Stack (MyStack)

  • LIFO (Last In, First Out) data structure
  • Configurable capacity (default: infinite)
  • Operations: push, pop, peek
  • Methods: isEmpty(), isFull(), size(), search(), contains()

5. Queue (MyQueue)

  • FIFO (First In, First Out) data structure
  • Configurable capacity (default: infinite)
  • Operations: enqueue, dequeue, front, back
  • Methods: isEmpty(), isFull(), size(), search(), contains()

6. Set (MySet)

  • Collection of unique elements
  • Set theory operations: union, intersection, difference, symmetric difference
  • Methods: add(), delete(), has(), size(), isEmpty()

7. Tree (MyTree)

  • Multi-child tree with configurable minimum children (default: 2)
  • Traversal: preorder, postorder, level order
  • Methods: addChild(), remove(), getHeight(), getDepth(), isBalanced()

8. Binary Search Tree (MyBST)

  • Binary search tree with efficient search and insertion
  • BST property: left child < parent < right child
  • Traversal: inorder (sorted), preorder, postorder, level order
  • Methods: insert(), search(), remove(), findMin(), findMax()
  • BST-specific: isValidBST(), isBalanced(), getSuccessor(), getPredecessor()
  • Loop detection: hasLoop(), getLoopCount(), getLoopData(), getLoopNodes()

9. AVL Tree (MyAVLTree)

  • Self-balancing binary search tree with height balance
  • AVL property: height difference between left and right subtrees ≀ 1
  • Automatic rebalancing through rotations (left, right, left-right, right-left)
  • Methods: insert(), search(), remove(), findMin(), findMax()
  • AVL-specific: isValidAVL(), isBalanced(), getNodeBalanceFactor(), getNodeHeight()
  • Traversal: inorder (sorted), preorder, postorder, level order

10. Red-Black Tree (MyRedBlackTree)

  • Self-balancing binary search tree with color properties
  • Red-Black properties: root is black, red nodes can't have red children, equal black height
  • Automatic rebalancing through color changes and rotations
  • Methods: insert(), search(), remove(), findMin(), findMax()
  • RB-specific: isValidRedBlack(), getNodeColor(), isRed(), isBlack(), getParent(), getSibling(), getUncle()
  • Traversal: inorder (sorted), preorder, postorder, level order

11. Graph (MyGraph)

  • Directed and undirected graph support
  • Weighted edges with customizable weights
  • Algorithms: DFS, BFS, shortest path, cycle detection, topological sort
  • Methods: addVertex(), addEdge(), hasPath(), getConnectedComponents()

12. Heap (MyHeap)

  • Min/Max heap with priority queue functionality
  • Configurable comparison functions
  • Operations: insert, extract, peek
  • Methods: getMin(), getMax(), getKthElement(), isValid()

13. Trie (MyTrie)

  • Prefix tree for efficient string operations
  • Pattern matching and autocomplete functionality
  • Methods: insert(), search(), startsWith(), getWordsWithPrefix()

πŸš€ Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

From npm (Recommended)

# Install the package
npm install dst-typescript-collection

# Use in your project
import { MyHashMap, MyConcurrentHashMap, MyLinkedList } from 'dst-typescript-collection';

From Source

# Clone the repository
git clone https://github.com/sarcasm1984/DST.git
cd DST

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Build the project
npm run build

πŸ§ͺ Testing

The project includes comprehensive test suites for all data structures:

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage report
npm run test:coverage

Test Coverage

  • 13 Test Suites: All data structures including ConcurrentHashMap
  • 549 Tests: Comprehensive coverage with concurrency scenarios
  • 100% Pass Rate: All tests passing

πŸ“ Project Structure

DST/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ DataStructures/
β”‚   β”‚   β”œβ”€β”€ MyLinkedList.ts
β”‚   β”‚   β”œβ”€β”€ MyHashMap.ts
β”‚   β”‚   β”œβ”€β”€ MyConcurrentHashMap.ts
β”‚   β”‚   β”œβ”€β”€ MyStack.ts
β”‚   β”‚   β”œβ”€β”€ MyQueue.ts
β”‚   β”‚   β”œβ”€β”€ MySet.ts
β”‚   β”‚   β”œβ”€β”€ MyTree.ts
β”‚   β”‚   β”œβ”€β”€ MyBST.ts
β”‚   β”‚   β”œβ”€β”€ MyAVLTree.ts
β”‚   β”‚   β”œβ”€β”€ MyRedBlackTree.ts
β”‚   β”‚   β”œβ”€β”€ MyGraph.ts
β”‚   β”‚   β”œβ”€β”€ MyHeap.ts
β”‚   β”‚   └── MyTrie.ts
β”‚   β”œβ”€β”€ Test/
β”‚   β”‚   β”œβ”€β”€ MyLinkedList.test.ts
β”‚   β”‚   β”œβ”€β”€ MyHashMap.test.ts
β”‚   β”‚   β”œβ”€β”€ MyConcurrentHashMap.test.ts
β”‚   β”‚   β”œβ”€β”€ MyStack.test.ts
β”‚   β”‚   β”œβ”€β”€ MyQueue.test.ts
β”‚   β”‚   β”œβ”€β”€ MySet.test.ts
β”‚   β”‚   β”œβ”€β”€ MyTree.test.ts
β”‚   β”‚   β”œβ”€β”€ MyBST.test.ts
β”‚   β”‚   β”œβ”€β”€ MyAVLTree.test.ts
β”‚   β”‚   β”œβ”€β”€ MyRedBlackTree.test.ts
β”‚   β”‚   β”œβ”€β”€ MyGraph.test.ts
β”‚   β”‚   β”œβ”€β”€ MyHeap.test.ts
β”‚   β”‚   └── MyTrie.test.ts
β”‚   └── index.ts
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ jest.config.js
└── README.md

πŸ’» Usage Examples

Linked List

import { MyLinkedList } from 'dst-typescript-collection';

const list = new MyLinkedList<number>();
list.append(1);
list.append(2);
list.prepend(0);
console.log(list.toArray()); // [0, 1, 2]

Hash Map

import { MyHashMap } from 'dst-typescript-collection';

const map = new MyHashMap<string, number>();
map.put('key1', 1);
map.put('key2', 2);
console.log(map.get('key1')); // 1

Concurrent Hash Map

import { MyConcurrentHashMap } from 'dst-typescript-collection';

const concurrentMap = new MyConcurrentHashMap<string, number>();

// All operations are async
await concurrentMap.put('key1', 1);
await concurrentMap.put('key2', 2);
console.log(await concurrentMap.get('key1')); // 1

// Safe for concurrent operations
const promises = [];
for (let i = 0; i < 100; i++) {
  promises.push(concurrentMap.put(`key${i}`, i));
}
await Promise.all(promises);
console.log(await concurrentMap.getSize()); // 100

Stack

import { MyStack } from 'dst-typescript-collection';

const stack = new MyStack<number>();
stack.push(1);
stack.push(2);
console.log(stack.pop()); // 2

Queue

import { MyQueue } from 'dst-typescript-collection';

const queue = new MyQueue<number>();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // 1

Set

import { MySet } from 'dst-typescript-collection';

const set = new MySet<number>();
set.add(1);
set.add(2);
set.add(1); // Duplicate, won't be added
console.log(set.size()); // 2

Tree

import { MyTree } from 'dst-typescript-collection';

const tree = new MyTree<number>();
tree.addToRoot(1);
tree.addChild(1, 2);
tree.addChild(1, 3);
console.log(tree.preorder()); // [1, 2, 3]

Binary Search Tree

import { MyBST } from 'dst-typescript-collection';

const bst = new MyBST<number>();
bst.insert(5);
bst.insert(3);
bst.insert(7);
console.log(bst.inorder()); // [3, 5, 7] (sorted)
console.log(bst.findMin()); // 3
console.log(bst.findMax()); // 7
console.log(bst.hasLoop()); // false (no loops in normal BST)

AVL Tree

import { MyAVLTree } from 'dst-typescript-collection';

const avl = new MyAVLTree<number>();
avl.insert(5);
avl.insert(3);
avl.insert(7);
avl.insert(1);
console.log(avl.inorder()); // [1, 3, 5, 7] (sorted)
console.log(avl.isBalanced()); // true (always balanced)
console.log(avl.getNodeBalanceFactor(5)); // 0 (balanced)

Red-Black Tree

import { MyRedBlackTree } from 'dst-typescript-collection';

const rbt = new MyRedBlackTree<number>();
rbt.insert(10);
rbt.insert(5);
rbt.insert(15);
rbt.insert(3);
rbt.insert(7);
console.log(rbt.inorder()); // [3, 5, 7, 10, 15] (sorted)
console.log(rbt.isValidRedBlack()); // true (validates RB properties)
console.log(rbt.getNodeColor(10)); // 'BLACK' (root is black)
console.log(rbt.isRed(5)); // true (some nodes are red)

Graph

import { MyGraph } from 'dst-typescript-collection';

const graph = new MyGraph<string>();
graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B', 5);
console.log(graph.hasPath('A', 'B')); // true

Heap

import { MyHeap } from 'dst-typescript-collection';

const heap = new MyHeap<number>(); // Min heap
heap.insert(3);
heap.insert(1);
heap.insert(2);
console.log(heap.peek()); // 1

Trie

import { MyTrie } from 'dst-typescript-collection';

const trie = new MyTrie();
trie.insert('hello');
trie.insert('world');
console.log(trie.search('hello')); // true
console.log(trie.startsWith('hel')); // true

πŸ”§ Development

Adding New Data Structures

  1. Create a new file in src/DataStructures/
  2. Implement the data structure with TypeScript
  3. Add comprehensive tests in src/Test/
  4. Export the class from src/index.ts
  5. Run tests to ensure everything works

Running Tests

# Run all tests
npm test

# Run specific test file
npm test -- MyLinkedList.test.ts

# Run tests with verbose output
npm test -- --verbose

πŸ“Š Performance

All data structures are optimized for:

  • Time Complexity: Efficient algorithms implemented
  • Space Complexity: Memory-efficient implementations
  • Type Safety: Full TypeScript support with generics
  • Error Handling: Comprehensive error checking

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the ISC License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built with TypeScript for type safety
  • Tested with Jest for comprehensive coverage
  • Inspired by classic data structures and algorithms

Happy Coding! πŸš€