Skip to content

List of type-safe and commonly used Data structures which are not provided natively by Javascript/Typescript

License

Notifications You must be signed in to change notification settings

mandy8055/data-structures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

data-structures

A comprehensive collection of generic data structure implementations which are not supported natively by the for TypeScript/JavaScript, and published on JSR.

JSR JSR Score codecov CI

Features

  • 🎯 Type-safe implementations with TypeScript generics
  • 📦 Zero dependencies
  • 🧪 Comprehensive test coverage
  • 📚 Well-documented API
  • 🚀 Optimized performance
  • 🛡️ Error handling built-in

Installation

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';

Available Data Structures and their detailed documentations

  • 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.

Error Handling

The library includes custom error types:

  • EmptyStructureError: For operations on empty structures
  • IndexOutOfBoundsError: For invalid index access
  • InvalidOperationsError: For performing invalid operations

Contribution

Contributions are welcome! Please feel free to submit a Pull Request after going through the Contributing Guidelines.

License

MIT License - feel free to use this in your own projects!

About

List of type-safe and commonly used Data structures which are not provided natively by Javascript/Typescript

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published