data-structure-typed 2.4.3 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.github/workflows/release.yml +27 -0
  2. package/CHANGELOG.md +24 -1
  3. package/README.md +70 -51
  4. package/dist/cjs/index.cjs +486 -167
  5. package/dist/cjs-legacy/index.cjs +487 -165
  6. package/dist/esm/index.mjs +486 -168
  7. package/dist/esm-legacy/index.mjs +487 -166
  8. package/dist/types/common/error.d.ts +23 -0
  9. package/dist/types/common/index.d.ts +1 -0
  10. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +15 -5
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +7 -1
  14. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
  15. package/dist/types/data-structures/graph/directed-graph.d.ts +3 -2
  16. package/dist/types/data-structures/graph/undirected-graph.d.ts +16 -2
  17. package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
  18. package/dist/types/data-structures/heap/heap.d.ts +3 -7
  19. package/dist/types/data-structures/queue/deque.d.ts +41 -1
  20. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
  21. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  22. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  23. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  24. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  25. package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
  26. package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
  27. package/dist/umd/data-structure-typed.js +486 -164
  28. package/dist/umd/data-structure-typed.min.js +6 -4
  29. package/package.json +2 -2
  30. package/src/common/error.ts +60 -0
  31. package/src/common/index.ts +2 -0
  32. package/src/data-structures/base/iterable-element-base.ts +5 -4
  33. package/src/data-structures/binary-tree/binary-indexed-tree.ts +6 -5
  34. package/src/data-structures/binary-tree/binary-tree.ts +121 -49
  35. package/src/data-structures/binary-tree/bst.ts +12 -4
  36. package/src/data-structures/binary-tree/red-black-tree.ts +20 -0
  37. package/src/data-structures/binary-tree/tree-map.ts +8 -7
  38. package/src/data-structures/binary-tree/tree-multi-map.ts +4 -4
  39. package/src/data-structures/binary-tree/tree-multi-set.ts +10 -9
  40. package/src/data-structures/binary-tree/tree-set.ts +7 -6
  41. package/src/data-structures/graph/abstract-graph.ts +124 -19
  42. package/src/data-structures/graph/directed-graph.ts +8 -4
  43. package/src/data-structures/graph/map-graph.ts +1 -1
  44. package/src/data-structures/graph/undirected-graph.ts +99 -4
  45. package/src/data-structures/hash/hash-map.ts +19 -6
  46. package/src/data-structures/heap/heap.ts +21 -17
  47. package/src/data-structures/heap/max-heap.ts +2 -3
  48. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  49. package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
  50. package/src/data-structures/matrix/matrix.ts +9 -10
  51. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -3
  52. package/src/data-structures/queue/deque.ts +72 -4
  53. package/src/data-structures/stack/stack.ts +1 -1
  54. package/src/data-structures/trie/trie.ts +12 -6
  55. package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
  56. package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
  57. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
  58. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
  59. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  60. package/src/types/data-structures/queue/deque.ts +7 -0
  61. package/src/types/data-structures/stack/stack.ts +1 -1
  62. package/src/utils/utils.ts +4 -2
@@ -0,0 +1,27 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ release:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - name: Create GitHub Release
21
+ uses: softprops/action-gh-release@v1
22
+ with:
23
+ generate_release_notes: true
24
+ draft: false
25
+ prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
26
+ env:
27
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -8,7 +8,30 @@ All notable changes to this project will be documented in this file.
8
8
  - [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
9
9
  - [`auto-changelog`](https://github.com/CookPete/auto-changelog)
10
10
 
11
- ## [v2.4.3](https://github.com/zrwusa/data-structure-typed/compare/v2.2.3...main) (upcoming)
11
+ ## [v2.4.5](https://github.com/zrwusa/data-structure-typed/compare/v2.4.3...main) (upcoming)
12
+
13
+ ### Changes
14
+
15
+ - fix(binary-tree): null nodes no longer count toward size [`#70`](https://github.com/zrwusa/data-structure-typed/pull/70)
16
+ - feat(graph): add biconnected components and cycle detection for undirected graph [`#77`](https://github.com/zrwusa/data-structure-typed/pull/77)
17
+ - fix(rbt): override perfectlyBalance to preserve RBT invariants [`#79`](https://github.com/zrwusa/data-structure-typed/pull/79)
18
+ - feat(bst): support Date keys in default comparator [`#107`](https://github.com/zrwusa/data-structure-typed/pull/107)
19
+ - refactor(binary-tree): iterative _displayAux to prevent stack overflow on deep trees [`#104`](https://github.com/zrwusa/data-structure-typed/pull/104)
20
+ - fix(binary-tree): leaves() iterative mode uses DFS stack to match recursive order [`#102`](https://github.com/zrwusa/data-structure-typed/pull/102)
21
+ - refactor: migrate all throw sites to ERR message templates [`#130`](https://github.com/zrwusa/data-structure-typed/pull/130)
22
+ - refactor: lightweight centralized error messages via ERR templates [`#130`](https://github.com/zrwusa/data-structure-typed/pull/130)
23
+ - feat: centralized error handling with DSTError/DSTRangeError/DSTTypeError [`#130`](https://github.com/zrwusa/data-structure-typed/pull/130)
24
+ - refactor(deque): improve auto-compact with counter + element-based ratio [`#92`](https://github.com/zrwusa/data-structure-typed/pull/92)
25
+ - perf(deque): optimize auto-compact with counter-based checking and element ratio [`#92`](https://github.com/zrwusa/data-structure-typed/pull/92)
26
+ - feat(deque): add compact() method and autoCompactRatio option [`#92`](https://github.com/zrwusa/data-structure-typed/pull/92)
27
+ - fix(deque): add constructor overloads for better type inference [`#97`](https://github.com/zrwusa/data-structure-typed/pull/97)
28
+ - test(graph): add edge case tests for visual output [`#113`](https://github.com/zrwusa/data-structure-typed/pull/113)
29
+ - test(graph): add visual output tests for DirectedGraph and UndirectedGraph [`#113`](https://github.com/zrwusa/data-structure-typed/pull/113)
30
+ - feat(graph): add print, toVisual, and toDot methods for all graphs [`#113`](https://github.com/zrwusa/data-structure-typed/pull/113)
31
+ - fix(hash-map): deleteAt/deleteWhere now removes entry from hash table [`#99`](https://github.com/zrwusa/data-structure-typed/pull/99)
32
+ - fix(deque): shrinkToFit now updates _bucketCount and handles single-bucket case [`#98`](https://github.com/zrwusa/data-structure-typed/pull/98)
33
+
34
+ ## [v2.4.3](https://github.com/zrwusa/data-structure-typed/compare/v2.2.3...v2.4.3) (3 March 2026)
12
35
 
13
36
  ## [v2.2.3](https://github.com/zrwusa/data-structure-typed/compare/v2.2.2...v2.2.3) (6 January 2026)
14
37
 
package/README.md CHANGED
@@ -4,6 +4,8 @@ English | [简体中文](./README_CN.md)
4
4
 
5
5
  A comprehensive TypeScript data structures library with production-ready implementations.
6
6
 
7
+ **We TypeScript/JavaScript devs want something like C++'s `STL`, Java's `java.util` Collections, or Python's `collections` — but with an API that feels as intuitive and ergonomic as JavaScript's native `Array`.** If that's what you're looking for, you're in the right place. This is a zero-dependency library, and you can also install individual data structure packages separately if you prefer a more modular setup.
8
+
7
9
  ![npm](https://img.shields.io/npm/dm/data-structure-typed)
8
10
  ![GitHub contributors](https://img.shields.io/github/contributors/zrwusa/data-structure-typed)
9
11
  ![GITHUB Star](https://img.shields.io/github/stars/zrwusa/data-structure-typed)
@@ -12,19 +14,55 @@ A comprehensive TypeScript data structures library with production-ready impleme
12
14
  ![NPM](https://img.shields.io/npm/l/data-structure-typed)
13
15
  ![npm](https://img.shields.io/npm/v/data-structure-typed)
14
16
 
15
- **📚 [Installation](#-installation) • [Quick Start](#-quick-start-30-seconds) • [Full Docs](#-documentation) • [API Reference](./docs/REFERENCE.md) • [Playground](#playground) [Examples](./docs/GUIDES.md)**
17
+ **📦 [Installation](#-installation) • 🎮 [Playground](#-playground) • ⚡ [Quick Start](#-quick-start-30-seconds) • 📖 [Docs](#-documentation) • 📋 [API](./docs/REFERENCE.md) • 💡 [Examples](./docs/GUIDES.md)**
16
18
 
17
19
  ---
18
20
 
19
21
  ## Table of Contents
20
22
 
21
- 1. [Who Should Use This?](#-who-should-use-this)
22
- 2. [Why Not Just Array or Map?](#-why-not-just-array-or-map)
23
- 3. [Key Features](#-key-features)
24
- 4. [Installation](#-installation)
25
- 5. [Quick Start](#-quick-start-30-seconds)
26
- 6. [Data Structures](#-data-structures-available)
27
- 7. [Documentation](#-documentation)
23
+ 1. [Installation](#-installation)
24
+ 2. [Playground](#-playground)
25
+ 3. [Quick Start](#-quick-start-30-seconds)
26
+ 4. [Who Should Use This?](#-who-should-use-this)
27
+ 5. [Why Not Just Array or Map?](#-why-not-just-array-or-map)
28
+ 6. [Key Features](#-key-features)
29
+ 7. [Data Structures](#-data-structures-available)
30
+ 8. [Documentation](#-documentation)
31
+
32
+ ---
33
+
34
+ ## 📦 Installation
35
+
36
+ ```bash
37
+ npm i data-structure-typed
38
+ ```
39
+
40
+ ```bash
41
+ yarn add data-structure-typed
42
+ ```
43
+
44
+ ```bash
45
+ pnpm add data-structure-typed
46
+ ```
47
+
48
+ ### Individual Packages
49
+
50
+ Use only what you need:
51
+
52
+ ```bash
53
+ npm i heap-typed deque-typed red-black-tree-typed
54
+ ```
55
+
56
+ ---
57
+
58
+ ## 🎮 Playground
59
+
60
+ Try it instantly:
61
+
62
+ - [Node.js TypeScript](https://stackblitz.com/edit/stackblitz-starters-e1vdy3zw?file=src%2Findex.ts)
63
+ - [Node.js JavaScript](https://stackblitz.com/edit/stackblitz-starters-oczhrfzn?file=src%2Findex.js)
64
+ - [React TypeScript](https://stackblitz.com/edit/vitejs-vite-7bva1zhd?file=src%2FApp.tsx)
65
+ - [NestJS](https://stackblitz.com/edit/nestjs-typescript-starter-q9n7okgc?file=src%2Fproduct%2Fservices%2Fproduct-price-index.service.ts)
28
66
 
29
67
  ---
30
68
 
@@ -92,7 +130,30 @@ for (let i = 0; i < 100000; i++) {
92
130
 
93
131
  - **Tree-shakable** ESM / CJS / legacy builds
94
132
 
95
- 📊 [Full benchmarks →](./docs/benchmark.html)
133
+ [//]: # (No deletion!!! Start of README Performance Section)
134
+
135
+ | Data Structure | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
136
+ |----------------|-----------|----------|-------------|----------|---------------|
137
+ | Queue | 1M push | 26.93 | 23.83 | 1.70 | 27.59 |
138
+ | Deque | 1M push | 9.77 | 26.81 | 1.76 | 7.79 |
139
+ | DoublyLinkedList | 100k push | 5.70 | 2.40 | 5.70 | 1.90 |
140
+ | SinglyLinkedList | 100K unshift & shift | 3.77 | 1958.39 | 4.80 | - |
141
+ | PriorityQueue | 100K add | 4.00 | - | 1.05 | 4.96 |
142
+ | TreeSet | 1M add | 962.76 | - | 462.00 | 640.31 |
143
+ | TreeMap | 1M set | 996.95 | - | 512.00 | 624.82 |
144
+ | TreeMultiSet | 1M add (TreeMultiSet expanded iteration) | 218.78 | - | 752.00 | - |
145
+ | TreeMultiMap | 1M add (TreeMultiMap bucketed) | 387.80 | - | 731.00 | - |
146
+ | RedBlackTree | 1M get | 108.02 | - | 52.97 | - |
147
+ | BST | 10K add randomly | 5.50 | - | - | - |
148
+ | BinaryTree | 1K add randomly | 9.77 | - | - | - |
149
+ | HashMap | 1M set | 146.17 | 144.83 | 76.26 | 94.16 |
150
+ | Trie | 100K add | 141.10 | - | - | - |
151
+ | DirectedGraph | 1K addVertex | 0.05 | - | - | - |
152
+ | Stack | 1M push | 46.38 | 30.28 | 1.65 | 32.38 |
153
+
154
+ [//]: # (No deletion!!! End of README Performance Section)
155
+
156
+ 📊 [Full benchmarks →](./docs/PERFORMANCE.md) | [Interactive report →](./docs/benchmark.html)
96
157
 
97
158
  ---
98
159
 
@@ -144,30 +205,6 @@ const set = new Set(tree); // Set constructor
144
205
 
145
206
  ---
146
207
 
147
- ## 📥 Installation
148
-
149
- ```bash
150
- pnpm add data-structure-typed
151
- ```
152
-
153
- ```bash
154
- npm i data-structure-typed --save
155
- ```
156
-
157
- ```bash
158
- yarn add data-structure-typed
159
- ```
160
-
161
- ### Individual Packages
162
-
163
- Use only what you need:
164
-
165
- ```bash
166
- pnpm add heap-typed deque-typed red-black-tree-typed
167
- ```
168
-
169
- ---
170
-
171
208
  ## 💡 When Should I Consider This Library?
172
209
 
173
210
  ✅ **When you need:**
@@ -494,24 +531,6 @@ const tree = new RedBlackTree([5, 2, 8]);
494
531
  console.log([...tree]); // [2, 5, 8] - Automatically sorted!
495
532
  ```
496
533
 
497
- ## Playground
498
-
499
- 🏃🏻‍♀️ Try it instantly:
500
-
501
- - [Node.js TypeScript](https://stackblitz.com/edit/stackblitz-starters-e1vdy3zw?file=src%2Findex.ts)
502
- - [Node.js JavaScript](https://stackblitz.com/edit/stackblitz-starters-oczhrfzn?file=src%2Findex.js)
503
- - [React TypeScript](https://stackblitz.com/edit/vitejs-vite-7bva1zhd?file=src%2FApp.tsx)
504
- - [NestJS](https://stackblitz.com/edit/nestjs-typescript-starter-q9n7okgc?file=src%2Fproduct%2Fservices%2Fproduct-price-index.service.ts)
505
-
506
-
507
- ### Step 4: Learn More
508
-
509
- 👉 Check [CONCEPTS.md](./docs/CONCEPTS.md) for core concepts
510
- 👉 See [GUIDES.md](./docs/GUIDES.md) for production examples
511
- 👉 Read [REFERENCE.md](./docs/REFERENCE.md) for complete API
512
-
513
- ---
514
-
515
534
  ## 📊 Comparison Chart
516
535
 
517
536
  ```