A comprehensive collection of generic data structure implementations which are not supported natively by the for TypeScript/JavaScript, and published on JSR.
- 🎯 Type-safe implementations with TypeScript generics
- 📦 Zero dependencies
- 🧪 Comprehensive test coverage
- 📚 Well-documented API
- 🚀 Optimized performance
- 🛡️ Error handling built-in
import {
LinkedList,
DoublyLinkedList,
Deque,
Queue,
MinHeap,
MaxHeap,
Trie,
PriorityQueue,
SortedMap,
RedBlackTree,
BiDirectionalMap,
LRUCache,
} from 'jsr:@mskr/data-structures';
// or if you want to use it with esm.sh
// import * as ds from 'https://esm.sh/jsr/@mskr/data-structures';
// import { ... } from 'https://esm.sh/jsr/@mskr/data-structures';
- LinkedList: Singly linked list implementation
- DoublyLinkedList: Doubly linked list with bidirectional traversal
- Deque: For efficient support of insertion and removal of elements from both ends.
- Queue: A First-In-First-Out (FIFO) queue implementation that efficiently supports insertion at the back and removal from the front.
- Trie: For efficient storage and retrieval of strings while supporting associated values.
- Binary Heap: Binary heap implementation that provides both Min Heap and Max Heap variants with efficient operations.
- PriorityQueue: Implementation backed by a binary heap, where elements are dequeued based on their priority.
- RedBlackTree: Implementation providing self-balancing binary search tree operations
- SortedMap: A generic key-value map that maintains its entries sorted by key using a Red-Black Tree.
- BiDirectional Map: maintains one-to-one mappings between two sets of elements. Each key maps to a unique value, and each value maps to a unique key.
- LRU Cache: implementation that provides efficient O(1) operations for both accessing and storing elements, with automatic eviction of least recently used items when capacity is reached.
The library includes custom error types:
EmptyStructureError
: For operations on empty structuresIndexOutOfBoundsError
: For invalid index accessInvalidOperationsError
: For performing invalid operations
Contributions are welcome! Please feel free to submit a Pull Request after going through the Contributing Guidelines.
MIT License - feel free to use this in your own projects!