data-structures
A comprehensive collection of type-safe, zero-dependency data structure implementations for TypeScript/JavaScript.
Why Use This Library?
- 🎯 Type Safety: Full TypeScript support with generics for complete type safety
- 📦 Zero Dependencies: No external dependencies - lightweight and secure
- ⚡ Performance: Optimized implementations with documented time complexities
- 🧪 Well Tested: Comprehensive test coverage (>85%)
- 🌲 Tree Shakeable: Import only what you need - minimal bundle impact
- 📚 Well Documented: Extensive documentation with examples
- 🔄 Dual Published: Available on both JSR and npm for maximum compatibility
Quick Start
Get started in seconds:
npm install @msnkr/data-structures
import { Queue, LRUCache } from '@msnkr/data-structures';
// FIFO Queue
const queue = new Queue<number>();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // 1
// LRU Cache
const cache = new LRUCache<string, number>({ capacity: 100 });
cache.put('key', 42);
console.log(cache.get('key')); // 42
Available Data Structures
Queues
- Queue - FIFO queue with O(1) enqueue/dequeue operations
- Deque - Double-ended queue with O(1) operations at both ends
- PriorityQueue - Priority-based queue backed by binary heap
Lists
- LinkedList - Singly linked list with O(1) insertions at ends
- DoublyLinkedList - Bidirectional linked list with reverse iteration
Heaps
- BinaryHeap - MinHeap and MaxHeap implementations with O(log n) operations
Trees
- Trie - Prefix tree for efficient string operations and autocomplete
- RedBlackTree - Self-balancing binary search tree with guaranteed O(log n)
Maps & Caches
- SortedMap - Key-value map with sorted keys (Red-Black Tree backed)
- BiDirectionalMap - One-to-one bidirectional mapping with O(1) lookups
- LRUCache - Least Recently Used cache with automatic eviction
Next Steps
📖 Learn the Basics
Get familiar with installation and basic usage.
📚 API Reference
Explore complete API documentation for all 11 data structures above!
Community & Support
- GitHub: mandy8055/data-structures
- Issues: Report bugs or request features
- Discussions: Join the community
License
MIT License - feel free to use this in your own projects!