data-structure-typed 2.5.0 → 2.5.2
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.
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +5 -1
- package/README.md +124 -29
- package/dist/cjs/binary-tree.cjs +26282 -0
- package/dist/cjs/graph.cjs +5422 -0
- package/dist/cjs/hash.cjs +1310 -0
- package/dist/cjs/heap.cjs +1602 -0
- package/dist/cjs/index.cjs +31257 -14673
- package/dist/cjs/linked-list.cjs +4576 -0
- package/dist/cjs/matrix.cjs +1080 -0
- package/dist/cjs/priority-queue.cjs +1376 -0
- package/dist/cjs/queue.cjs +4264 -0
- package/dist/cjs/stack.cjs +907 -0
- package/dist/cjs/trie.cjs +1223 -0
- package/dist/cjs-legacy/binary-tree.cjs +26319 -0
- package/dist/cjs-legacy/graph.cjs +5420 -0
- package/dist/cjs-legacy/hash.cjs +1310 -0
- package/dist/cjs-legacy/heap.cjs +1599 -0
- package/dist/cjs-legacy/index.cjs +31268 -14679
- package/dist/cjs-legacy/linked-list.cjs +4582 -0
- package/dist/cjs-legacy/matrix.cjs +1083 -0
- package/dist/cjs-legacy/priority-queue.cjs +1374 -0
- package/dist/cjs-legacy/queue.cjs +4262 -0
- package/dist/cjs-legacy/stack.cjs +907 -0
- package/dist/cjs-legacy/trie.cjs +1222 -0
- package/dist/esm/binary-tree.mjs +26267 -0
- package/dist/esm/graph.mjs +5409 -0
- package/dist/esm/hash.mjs +1307 -0
- package/dist/esm/heap.mjs +1596 -0
- package/dist/esm/index.mjs +31254 -14674
- package/dist/esm/linked-list.mjs +4569 -0
- package/dist/esm/matrix.mjs +1076 -0
- package/dist/esm/priority-queue.mjs +1372 -0
- package/dist/esm/queue.mjs +4260 -0
- package/dist/esm/stack.mjs +905 -0
- package/dist/esm/trie.mjs +1220 -0
- package/dist/esm-legacy/binary-tree.mjs +26304 -0
- package/dist/esm-legacy/graph.mjs +5407 -0
- package/dist/esm-legacy/hash.mjs +1307 -0
- package/dist/esm-legacy/heap.mjs +1593 -0
- package/dist/esm-legacy/index.mjs +31265 -14680
- package/dist/esm-legacy/linked-list.mjs +4575 -0
- package/dist/esm-legacy/matrix.mjs +1079 -0
- package/dist/esm-legacy/priority-queue.mjs +1370 -0
- package/dist/esm-legacy/queue.mjs +4258 -0
- package/dist/esm-legacy/stack.mjs +905 -0
- package/dist/esm-legacy/trie.mjs +1219 -0
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +31196 -14608
- package/dist/umd/data-structure-typed.min.js +11 -5
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6644 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +6293 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6888 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1389 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +615 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
- package/docs-site-docusaurus/docs/guide/faq.md +180 -0
- package/docs-site-docusaurus/docs/guide/guides.md +597 -0
- package/docs-site-docusaurus/docs/guide/installation.md +62 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
- package/docs-site-docusaurus/docs/guide/overview.md +645 -0
- package/docs-site-docusaurus/docs/guide/performance.md +835 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +120 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/llms.txt +37 -0
- package/package.json +159 -55
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +287 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
- package/src/data-structures/binary-tree/binary-tree.ts +581 -6
- package/src/data-structures/binary-tree/bst.ts +922 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
- package/src/data-structures/binary-tree/segment-tree.ts +139 -2
- package/src/data-structures/binary-tree/tree-map.ts +3300 -495
- package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
- package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
- package/src/data-structures/binary-tree/tree-set.ts +3122 -440
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +230 -0
- package/src/data-structures/graph/undirected-graph.ts +207 -0
- package/src/data-structures/hash/hash-map.ts +270 -19
- package/src/data-structures/heap/heap.ts +326 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
- package/src/data-structures/matrix/matrix.ts +194 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +350 -5
- package/src/data-structures/queue/queue.ts +276 -0
- package/src/data-structures/stack/stack.ts +230 -0
- package/src/data-structures/trie/trie.ts +283 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
package/llms.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# data-structure-typed
|
|
2
|
+
|
|
3
|
+
> A production-ready TypeScript/JavaScript data structures library with zero dependencies.
|
|
4
|
+
|
|
5
|
+
## What it is
|
|
6
|
+
A comprehensive collection of 20+ data structures for TypeScript and JavaScript, with a unified API that feels like native Array. Includes Heap, Priority Queue, Deque, Trie, Graph, Red-Black Tree, TreeMap, TreeSet, SkipList, Segment Tree, Binary Indexed Tree, Matrix, and more.
|
|
7
|
+
|
|
8
|
+
## Key capabilities
|
|
9
|
+
- TreeMap / TreeSet: Sorted key-value and key-only collections (Red-Black Tree backed)
|
|
10
|
+
- Order-statistic operations: getRank(key), getByRank(k), rangeByRank(start, end)
|
|
11
|
+
- NavigableMap API: floor, ceiling, higher, lower, rangeSearch
|
|
12
|
+
- Priority Queue / Heap: MinHeap, MaxHeap, custom comparators
|
|
13
|
+
- Graph algorithms: Dijkstra, Bellman-Ford, Floyd-Warshall, Tarjan, topological sort, DFS, BFS
|
|
14
|
+
- Trie: Prefix search, autocomplete
|
|
15
|
+
- All structures support: forEach, filter, map, reduce, every, some, find, entries, keys, values
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
npm i data-structure-typed
|
|
19
|
+
|
|
20
|
+
## Links
|
|
21
|
+
- Documentation: https://data-structure-typed-docs.vercel.app/
|
|
22
|
+
- GitHub: https://github.com/zrwusa/data-structure-typed
|
|
23
|
+
- npm: https://www.npmjs.com/package/data-structure-typed
|
|
24
|
+
- Quick Start: https://data-structure-typed-docs.vercel.app/docs/guide/quick-start
|
|
25
|
+
- API Reference: https://data-structure-typed-docs.vercel.app/docs/api/
|
|
26
|
+
- Guides: https://data-structure-typed-docs.vercel.app/docs/guide/guides
|
|
27
|
+
- FAQ: https://github.com/zrwusa/data-structure-typed#-faq
|
|
28
|
+
|
|
29
|
+
## Common questions
|
|
30
|
+
- Does JavaScript have TreeMap? → Use TreeMap from this library (Red-Black Tree backed, sorted iteration, rank queries)
|
|
31
|
+
- Priority queue in TypeScript? → Use Heap, MinHeap, MaxHeap, or MinPriorityQueue/MaxPriorityQueue
|
|
32
|
+
- Sorted set / ordered set in JS? → Use TreeSet (maintains sorted order, supports floor/ceiling/range)
|
|
33
|
+
- How to find kth element efficiently? → Use getByRank(k) with enableOrderStatistic: true
|
|
34
|
+
- Alternative to repeatedly sorting arrays? → Use TreeMap/TreeSet for O(log n) insert with maintained order
|
|
35
|
+
- Bundle size? → ~143KB UMD min, tree-shakeable subpath imports (18KB–315KB per category)
|
|
36
|
+
- Zero dependencies? → Yes
|
|
37
|
+
- Production ready? → Yes, 2600+ tests, 99%+ coverage
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "2.5.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.5.2",
|
|
4
|
+
"description": "Production-ready TypeScript data structures: Heap, Deque, Trie, Graph, Red-Black Tree, TreeMap, TreeSet, and more. Zero dependencies, type-safe, with getRank/getByRank/rangeByRank support.",
|
|
5
5
|
"browser": "dist/umd/data-structure-typed.min.js",
|
|
6
6
|
"umd:main": "dist/umd/data-structure-typed.min.js",
|
|
7
7
|
"main": "dist/cjs/index.cjs",
|
|
@@ -30,7 +30,98 @@
|
|
|
30
30
|
"types": "./dist/types/index.d.ts",
|
|
31
31
|
"import": "./dist/esm-legacy/index.mjs",
|
|
32
32
|
"require": "./dist/cjs-legacy/index.cjs"
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"./binary-tree": {
|
|
35
|
+
"types": "./dist/types/data-structures/binary-tree/index.d.ts",
|
|
36
|
+
"node": {
|
|
37
|
+
"import": "./dist/esm/binary-tree.mjs",
|
|
38
|
+
"require": "./dist/cjs/binary-tree.cjs"
|
|
39
|
+
},
|
|
40
|
+
"import": "./dist/esm-legacy/binary-tree.mjs",
|
|
41
|
+
"require": "./dist/cjs-legacy/binary-tree.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./graph": {
|
|
44
|
+
"types": "./dist/types/data-structures/graph/index.d.ts",
|
|
45
|
+
"node": {
|
|
46
|
+
"import": "./dist/esm/graph.mjs",
|
|
47
|
+
"require": "./dist/cjs/graph.cjs"
|
|
48
|
+
},
|
|
49
|
+
"import": "./dist/esm-legacy/graph.mjs",
|
|
50
|
+
"require": "./dist/cjs-legacy/graph.cjs"
|
|
51
|
+
},
|
|
52
|
+
"./hash": {
|
|
53
|
+
"types": "./dist/types/data-structures/hash/index.d.ts",
|
|
54
|
+
"node": {
|
|
55
|
+
"import": "./dist/esm/hash.mjs",
|
|
56
|
+
"require": "./dist/cjs/hash.cjs"
|
|
57
|
+
},
|
|
58
|
+
"import": "./dist/esm-legacy/hash.mjs",
|
|
59
|
+
"require": "./dist/cjs-legacy/hash.cjs"
|
|
60
|
+
},
|
|
61
|
+
"./heap": {
|
|
62
|
+
"types": "./dist/types/data-structures/heap/index.d.ts",
|
|
63
|
+
"node": {
|
|
64
|
+
"import": "./dist/esm/heap.mjs",
|
|
65
|
+
"require": "./dist/cjs/heap.cjs"
|
|
66
|
+
},
|
|
67
|
+
"import": "./dist/esm-legacy/heap.mjs",
|
|
68
|
+
"require": "./dist/cjs-legacy/heap.cjs"
|
|
69
|
+
},
|
|
70
|
+
"./linked-list": {
|
|
71
|
+
"types": "./dist/types/data-structures/linked-list/index.d.ts",
|
|
72
|
+
"node": {
|
|
73
|
+
"import": "./dist/esm/linked-list.mjs",
|
|
74
|
+
"require": "./dist/cjs/linked-list.cjs"
|
|
75
|
+
},
|
|
76
|
+
"import": "./dist/esm-legacy/linked-list.mjs",
|
|
77
|
+
"require": "./dist/cjs-legacy/linked-list.cjs"
|
|
78
|
+
},
|
|
79
|
+
"./matrix": {
|
|
80
|
+
"types": "./dist/types/data-structures/matrix/index.d.ts",
|
|
81
|
+
"node": {
|
|
82
|
+
"import": "./dist/esm/matrix.mjs",
|
|
83
|
+
"require": "./dist/cjs/matrix.cjs"
|
|
84
|
+
},
|
|
85
|
+
"import": "./dist/esm-legacy/matrix.mjs",
|
|
86
|
+
"require": "./dist/cjs-legacy/matrix.cjs"
|
|
87
|
+
},
|
|
88
|
+
"./priority-queue": {
|
|
89
|
+
"types": "./dist/types/data-structures/priority-queue/index.d.ts",
|
|
90
|
+
"node": {
|
|
91
|
+
"import": "./dist/esm/priority-queue.mjs",
|
|
92
|
+
"require": "./dist/cjs/priority-queue.cjs"
|
|
93
|
+
},
|
|
94
|
+
"import": "./dist/esm-legacy/priority-queue.mjs",
|
|
95
|
+
"require": "./dist/cjs-legacy/priority-queue.cjs"
|
|
96
|
+
},
|
|
97
|
+
"./queue": {
|
|
98
|
+
"types": "./dist/types/data-structures/queue/index.d.ts",
|
|
99
|
+
"node": {
|
|
100
|
+
"import": "./dist/esm/queue.mjs",
|
|
101
|
+
"require": "./dist/cjs/queue.cjs"
|
|
102
|
+
},
|
|
103
|
+
"import": "./dist/esm-legacy/queue.mjs",
|
|
104
|
+
"require": "./dist/cjs-legacy/queue.cjs"
|
|
105
|
+
},
|
|
106
|
+
"./stack": {
|
|
107
|
+
"types": "./dist/types/data-structures/stack/index.d.ts",
|
|
108
|
+
"node": {
|
|
109
|
+
"import": "./dist/esm/stack.mjs",
|
|
110
|
+
"require": "./dist/cjs/stack.cjs"
|
|
111
|
+
},
|
|
112
|
+
"import": "./dist/esm-legacy/stack.mjs",
|
|
113
|
+
"require": "./dist/cjs-legacy/stack.cjs"
|
|
114
|
+
},
|
|
115
|
+
"./trie": {
|
|
116
|
+
"types": "./dist/types/data-structures/trie/index.d.ts",
|
|
117
|
+
"node": {
|
|
118
|
+
"import": "./dist/esm/trie.mjs",
|
|
119
|
+
"require": "./dist/cjs/trie.cjs"
|
|
120
|
+
},
|
|
121
|
+
"import": "./dist/esm-legacy/trie.mjs",
|
|
122
|
+
"require": "./dist/cjs-legacy/trie.cjs"
|
|
123
|
+
},
|
|
124
|
+
"./package.json": "./package.json"
|
|
34
125
|
},
|
|
35
126
|
"sideEffects": false,
|
|
36
127
|
"engines": {
|
|
@@ -38,45 +129,45 @@
|
|
|
38
129
|
"npm": ">=6.14.0"
|
|
39
130
|
},
|
|
40
131
|
"scripts": {
|
|
41
|
-
"build": "npm run build:
|
|
132
|
+
"build": "npm run build:node && npm run build:types && npm run build:umd",
|
|
42
133
|
"build:node": "tsup",
|
|
43
134
|
"build:umd": "tsup --config tsup.umd.config.js",
|
|
44
135
|
"build:types": "rm -rf dist/types && tsc -p tsconfig.types.json",
|
|
45
|
-
"build:ecut": "npm run build:node && npm run build:types && npm run build:umd",
|
|
46
136
|
"build:leetcode": "tsup --config tsup.leetcode.config.js",
|
|
47
137
|
"build:typedoc-plugin": "tsc scripts/typedoc-plugin-example-rewrite.ts --outDir scripts --esModuleInterop --module commonjs --target es2020 --moduleResolution node --skipLibCheck",
|
|
48
|
-
"build:docs": "npm run gen:examples && npm run generate:schema && npm run build:typedoc-plugin && typedoc --plugin ./scripts/typedoc-plugin-example-rewrite.js --out docs/api ./src",
|
|
49
|
-
"build:docs-class": "npm run gen:examples && npm run build:typedoc-plugin && typedoc --plugin ./scripts/typedoc-plugin-example-rewrite.js --out docs/api ./src/data-structures",
|
|
50
138
|
"gen:examples": "ts-node scripts/test-to-example.ts",
|
|
51
|
-
"
|
|
52
|
-
"test": "
|
|
139
|
+
"generate:schema": "ts-node scripts/generate-schema.ts",
|
|
140
|
+
"test": "jest --runInBand",
|
|
141
|
+
"test:coverage": "jest --runInBand --coverage",
|
|
53
142
|
"test:integration": "npm run update:subs && jest --config jest.integration.config.js && tsc test/integration/compile.test.ts && node test/integration/compile.mjs",
|
|
54
|
-
"test:perf": "npm run build
|
|
143
|
+
"test:perf": "npm run build && NODE_OPTIONS='--expose-gc --max-old-space-size=8192' node test/performance/benchmark-runner-enhanced.mjs",
|
|
55
144
|
"test:perf:report": "node test/performance/reportor-enhanced.mjs",
|
|
56
|
-
"test:coverage": "jest --runInBand --coverage",
|
|
57
145
|
"check": "npm run check:src && npm run check:test",
|
|
58
146
|
"check:src": "tsc --noEmit",
|
|
59
147
|
"check:test": "tsc -p tsconfig.test.json --noEmit",
|
|
60
148
|
"check:circular-refs": "dependency-cruiser src",
|
|
149
|
+
"lint": "npm run lint:src && npm run lint:test",
|
|
61
150
|
"lint:src": "eslint --fix 'src/**/*.{js,ts}'",
|
|
62
151
|
"lint:test": "eslint --fix 'test/**/*.{js,ts}'",
|
|
63
|
-
"
|
|
64
|
-
"inspect": "npm run build && npm run check && npm run lint",
|
|
152
|
+
"format": "npm run format:src && npm run format:test",
|
|
65
153
|
"format:src": "prettier --write 'src/**/*.{js,ts}'",
|
|
66
154
|
"format:test": "prettier --write 'test/**/*.{js,ts}'",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
155
|
+
"inspect": "npm run build && npm run check && npm run lint",
|
|
156
|
+
"ci": "env && git fetch --tags && npm run update:subs && npm run inspect && npm run test:coverage && npm run changelog",
|
|
157
|
+
"docs:api": "npm run gen:examples && npm run build:typedoc-plugin && cd docs-site-docusaurus && npx typedoc --options typedoc.json && node sort-protected.mjs",
|
|
158
|
+
"docs:dev": "cd docs-site-docusaurus && npm run start",
|
|
159
|
+
"docs:build": "cd docs-site-docusaurus && rm -rf docs/api && npx typedoc --options typedoc.json && node sort-protected.mjs && npm run build",
|
|
160
|
+
"docs:preview": "cd docs-site-docusaurus && npm run serve",
|
|
70
161
|
"update:subs": "npm i avl-tree-typed binary-tree-typed bst-typed heap-typed data-structure-typed --save-dev",
|
|
71
162
|
"install:all-subs": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multimap-typed trie-typed undirected-graph-typed queue-typed --save-dev",
|
|
72
|
-
"changelog": "auto-changelog",
|
|
73
|
-
"coverage:badge": "istanbul-badges-readme",
|
|
74
|
-
"toc": "doctoc README.md",
|
|
75
163
|
"copy:to-subs": "sh scripts/copy_to_all_subs.sh",
|
|
76
164
|
"publish:subs": "npm run copy:to-subs && sh scripts/publish_all_subs.sh",
|
|
77
165
|
"publish:docs": "sh scripts/publish_docs.sh",
|
|
78
166
|
"publish:all": "npm run ci && npm publish && npm run publish:docs && npm run check:exist-latest && npm run publish:subs",
|
|
79
|
-
"
|
|
167
|
+
"check:exist-latest": "sh scripts/check_exist_remotely.sh",
|
|
168
|
+
"changelog": "auto-changelog",
|
|
169
|
+
"coverage:badge": "istanbul-badges-readme",
|
|
170
|
+
"toc": "doctoc README.md"
|
|
80
171
|
},
|
|
81
172
|
"repository": {
|
|
82
173
|
"type": "git",
|
|
@@ -102,11 +193,11 @@
|
|
|
102
193
|
"@typescript-eslint/eslint-plugin": "^8.12.1",
|
|
103
194
|
"@typescript-eslint/parser": "^8.12.1",
|
|
104
195
|
"auto-changelog": "^2.5.0",
|
|
105
|
-
"avl-tree-typed": "^
|
|
196
|
+
"avl-tree-typed": "^2.5.1",
|
|
106
197
|
"benchmark": "^2.1.4",
|
|
107
|
-
"binary-tree-typed": "^
|
|
108
|
-
"bst-typed": "^
|
|
109
|
-
"data-structure-typed": "^2.
|
|
198
|
+
"binary-tree-typed": "^2.5.1",
|
|
199
|
+
"bst-typed": "^2.5.1",
|
|
200
|
+
"data-structure-typed": "^2.5.1",
|
|
110
201
|
"dependency-cruiser": "^16.5.0",
|
|
111
202
|
"doctoc": "^2.2.1",
|
|
112
203
|
"eslint": "^9.13.0",
|
|
@@ -115,7 +206,7 @@
|
|
|
115
206
|
"eslint-import-resolver-typescript": "^3.6.3",
|
|
116
207
|
"eslint-plugin-import": "^2.31.0",
|
|
117
208
|
"fast-glob": "^3.3.2",
|
|
118
|
-
"heap-typed": "^
|
|
209
|
+
"heap-typed": "^2.5.1",
|
|
119
210
|
"istanbul-badges-readme": "^1.9.0",
|
|
120
211
|
"jest": "^29.7.0",
|
|
121
212
|
"js-sdsl": "^4.4.2",
|
|
@@ -125,63 +216,76 @@
|
|
|
125
216
|
"ts-morph": "^27.0.2",
|
|
126
217
|
"ts-node": "^10.9.2",
|
|
127
218
|
"tsup": "^8.5.1",
|
|
128
|
-
"typedoc": "^0.
|
|
129
|
-
"
|
|
219
|
+
"typedoc": "^0.28.18",
|
|
220
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
221
|
+
"typescript": "~5.9"
|
|
130
222
|
},
|
|
131
223
|
"keywords": [
|
|
132
|
-
"data structures
|
|
133
|
-
"
|
|
224
|
+
"data structures",
|
|
225
|
+
"typescript",
|
|
226
|
+
"javascript",
|
|
227
|
+
"data structures library",
|
|
134
228
|
"typescript data structures",
|
|
135
229
|
"javascript data structures",
|
|
136
|
-
"
|
|
137
|
-
"algorithm library",
|
|
230
|
+
"binary tree",
|
|
138
231
|
"binary search tree",
|
|
232
|
+
"BST",
|
|
139
233
|
"AVL tree",
|
|
140
234
|
"red black tree",
|
|
141
235
|
"tree map",
|
|
142
236
|
"tree set",
|
|
237
|
+
"treemap javascript",
|
|
238
|
+
"treeset javascript",
|
|
239
|
+
"sorted map",
|
|
240
|
+
"sorted set",
|
|
241
|
+
"ordered map",
|
|
242
|
+
"ordered set",
|
|
143
243
|
"tree multi map",
|
|
144
244
|
"tree multi set",
|
|
145
|
-
"balanced tree",
|
|
146
|
-
"binary tree",
|
|
147
|
-
"BST",
|
|
148
|
-
"graph algorithm",
|
|
149
|
-
"directed graph",
|
|
150
|
-
"undirected graph",
|
|
151
245
|
"heap",
|
|
152
|
-
"priority queue",
|
|
153
246
|
"min heap",
|
|
154
247
|
"max heap",
|
|
248
|
+
"priority queue",
|
|
155
249
|
"queue",
|
|
156
250
|
"deque",
|
|
251
|
+
"double ended queue",
|
|
157
252
|
"stack",
|
|
158
253
|
"linked list",
|
|
159
254
|
"singly linked list",
|
|
160
255
|
"doubly linked list",
|
|
256
|
+
"skip list",
|
|
161
257
|
"trie",
|
|
258
|
+
"prefix tree",
|
|
259
|
+
"graph",
|
|
260
|
+
"directed graph",
|
|
261
|
+
"undirected graph",
|
|
162
262
|
"hash map",
|
|
163
263
|
"hash table",
|
|
164
|
-
"tree
|
|
165
|
-
"tree
|
|
166
|
-
"tree
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
"
|
|
173
|
-
"
|
|
174
|
-
"dijkstra
|
|
264
|
+
"segment tree",
|
|
265
|
+
"binary indexed tree",
|
|
266
|
+
"fenwick tree",
|
|
267
|
+
"matrix",
|
|
268
|
+
"rank query",
|
|
269
|
+
"range query",
|
|
270
|
+
"order statistic tree",
|
|
271
|
+
"getRank",
|
|
272
|
+
"getByRank",
|
|
273
|
+
"rangeByRank",
|
|
274
|
+
"dijkstra",
|
|
175
275
|
"bellman ford",
|
|
176
|
-
"floyd warshall",
|
|
177
|
-
"tarjan algorithm",
|
|
178
276
|
"topological sort",
|
|
277
|
+
"DFS",
|
|
278
|
+
"BFS",
|
|
179
279
|
"leetcode",
|
|
180
280
|
"coding interview",
|
|
181
|
-
"algorithm
|
|
182
|
-
"
|
|
183
|
-
"
|
|
281
|
+
"algorithm",
|
|
282
|
+
"zero dependency",
|
|
283
|
+
"production ready",
|
|
284
|
+
"type safe",
|
|
285
|
+
"ES6",
|
|
184
286
|
"CommonJS",
|
|
185
|
-
"
|
|
287
|
+
"UMD",
|
|
288
|
+
"collection",
|
|
289
|
+
"sorted collection"
|
|
186
290
|
]
|
|
187
291
|
}
|
package/src/common/error.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized error dispatch.
|
|
3
|
+
* All library errors go through this function for consistent messaging and easy grep.
|
|
4
|
+
* @remarks Always throws — data structure errors are never recoverable.
|
|
5
|
+
* @param ErrorClass - The error constructor (Error, TypeError, RangeError, etc.)
|
|
6
|
+
* @param message - The error message.
|
|
7
|
+
*/
|
|
8
|
+
export function raise(
|
|
9
|
+
ErrorClass: new (msg: string) => Error,
|
|
10
|
+
message: string
|
|
11
|
+
): never {
|
|
12
|
+
throw new ErrorClass(message);
|
|
13
|
+
}
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* Centralized error message templates.
|
|
3
17
|
* Keep using native Error/TypeError/RangeError — this only standardizes messages.
|
|
@@ -56,5 +70,9 @@ export const ERR = {
|
|
|
56
70
|
'Matrix: Must be rectangular for transposition.',
|
|
57
71
|
|
|
58
72
|
matrixRowMismatch: (expected: number, got: number) =>
|
|
59
|
-
`Matrix: Expected row length ${expected}, but got ${got}
|
|
73
|
+
`Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
74
|
+
|
|
75
|
+
// Order statistic
|
|
76
|
+
orderStatisticNotEnabled: (method: string, ctx?: string) =>
|
|
77
|
+
`${ctx ? ctx + ': ' : ''}${method}() requires enableOrderStatistic: true.`
|
|
60
78
|
} as const;
|
package/src/common/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
|
|
2
|
+
import { raise } from '../../common';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Base class that makes a data structure iterable and provides common
|
|
@@ -25,7 +26,7 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
25
26
|
if (options) {
|
|
26
27
|
const { toElementFn } = options;
|
|
27
28
|
if (typeof toElementFn === 'function') this._toElementFn = toElementFn;
|
|
28
|
-
else if (toElementFn)
|
|
29
|
+
else if (toElementFn) raise(TypeError, 'toElementFn must be a function type');
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -224,7 +225,7 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
224
225
|
acc = initialValue as U;
|
|
225
226
|
} else {
|
|
226
227
|
const first = iter.next();
|
|
227
|
-
if (first.done)
|
|
228
|
+
if (first.done) raise(TypeError, 'Reduce of empty structure with no initial value');
|
|
228
229
|
acc = first.value as unknown as U;
|
|
229
230
|
index = 1;
|
|
230
231
|
}
|
|
@@ -19,7 +19,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
19
19
|
* @returns Iterator of `[K, V]`.
|
|
20
20
|
* @remarks Time O(n) to iterate, Space O(1)
|
|
21
21
|
*/
|
|
22
|
-
*[Symbol.iterator](...args:
|
|
22
|
+
*[Symbol.iterator](...args: unknown[]): IterableIterator<[K, V]> {
|
|
23
23
|
yield* this._getIterator(...args);
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -63,7 +63,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
63
63
|
* @returns `true` if all pass; otherwise `false`.
|
|
64
64
|
* @remarks Time O(n), Space O(1)
|
|
65
65
|
*/
|
|
66
|
-
every(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
66
|
+
every(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): boolean {
|
|
67
67
|
let index = 0;
|
|
68
68
|
for (const item of this) {
|
|
69
69
|
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
@@ -80,7 +80,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
80
80
|
* @returns `true` if any passes; otherwise `false`.
|
|
81
81
|
* @remarks Time O(n), Space O(1)
|
|
82
82
|
*/
|
|
83
|
-
some(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
83
|
+
some(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): boolean {
|
|
84
84
|
let index = 0;
|
|
85
85
|
for (const item of this) {
|
|
86
86
|
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
@@ -96,7 +96,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
96
96
|
* @param thisArg - Optional `this` for callback.
|
|
97
97
|
* @remarks Time O(n), Space O(1)
|
|
98
98
|
*/
|
|
99
|
-
forEach(callbackfn: EntryCallback<K, V, void>, thisArg?:
|
|
99
|
+
forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: unknown): void {
|
|
100
100
|
let index = 0;
|
|
101
101
|
for (const item of this) {
|
|
102
102
|
const [key, value] = item;
|
|
@@ -111,7 +111,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
111
111
|
* @returns Matching `[key, value]` or `undefined`.
|
|
112
112
|
* @remarks Time O(n), Space O(1)
|
|
113
113
|
*/
|
|
114
|
-
find(callbackfn: EntryCallback<K, V, boolean>, thisArg?:
|
|
114
|
+
find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: unknown): [K, V] | undefined {
|
|
115
115
|
let index = 0;
|
|
116
116
|
for (const item of this) {
|
|
117
117
|
const [key, value] = item;
|
|
@@ -228,19 +228,19 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
228
228
|
* Map entries using an implementation-specific strategy.
|
|
229
229
|
* @remarks Time O(n), Space O(n)
|
|
230
230
|
*/
|
|
231
|
-
abstract map(...args:
|
|
231
|
+
abstract map(...args: unknown[]): unknown;
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* Filter entries and return the same-species structure.
|
|
235
235
|
* @returns A new instance of the same concrete class (`this` type).
|
|
236
236
|
* @remarks Time O(n), Space O(n)
|
|
237
237
|
*/
|
|
238
|
-
abstract filter(...args:
|
|
238
|
+
abstract filter(...args: unknown[]): this;
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
241
|
* Underlying iterator for the default iteration protocol.
|
|
242
242
|
* @returns Iterator of `[K, V]`.
|
|
243
243
|
* @remarks Time O(n), Space O(1)
|
|
244
244
|
*/
|
|
245
|
-
protected abstract _getIterator(...args:
|
|
245
|
+
protected abstract _getIterator(...args: unknown[]): IterableIterator<[K, V]>;
|
|
246
246
|
}
|
|
@@ -148,7 +148,7 @@ export abstract class LinearBase<
|
|
|
148
148
|
* @returns Index or `-1`.
|
|
149
149
|
* @remarks Time O(n), Space O(1)
|
|
150
150
|
*/
|
|
151
|
-
findIndex(predicate: ElementCallback<E, R, boolean>, thisArg?:
|
|
151
|
+
findIndex(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): number {
|
|
152
152
|
for (let i = 0; i < this.length; i++) {
|
|
153
153
|
const item = this.at(i);
|
|
154
154
|
if (item !== undefined && predicate.call(thisArg, item, i, this)) return i;
|
|
@@ -389,7 +389,7 @@ export abstract class LinearBase<
|
|
|
389
389
|
* @returns Iterator of elements from tail to head.
|
|
390
390
|
* @remarks Time O(n), Space O(1)
|
|
391
391
|
*/
|
|
392
|
-
protected abstract _getReverseIterator(...args:
|
|
392
|
+
protected abstract _getReverseIterator(...args: unknown[]): IterableIterator<E>;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/**
|
|
@@ -621,7 +621,7 @@ export abstract class LinearLinkedBase<
|
|
|
621
621
|
* @returns Iterator over nodes.
|
|
622
622
|
* @remarks Time O(n), Space O(1)
|
|
623
623
|
*/
|
|
624
|
-
protected abstract _getNodeIterator(...args:
|
|
624
|
+
protected abstract _getNodeIterator(...args: unknown[]): IterableIterator<NODE>;
|
|
625
625
|
|
|
626
626
|
/**
|
|
627
627
|
* Get previous node of a given node.
|