data-structure-typed 2.5.2 → 2.6.0
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/.husky/pre-commit +3 -0
- package/CHANGELOG.md +3 -1
- package/MIGRATION.md +217 -0
- package/README.md +80 -8
- package/README_CN.md +569 -143
- package/SPECIFICATION.md +44 -14
- package/SPECIFICATION.zh-CN.md +44 -14
- package/dist/cjs/binary-tree.cjs +5841 -1678
- package/dist/cjs/graph.cjs +422 -14
- package/dist/cjs/hash.cjs +95 -7
- package/dist/cjs/heap.cjs +174 -16
- package/dist/cjs/index.cjs +7751 -2449
- package/dist/cjs/linked-list.cjs +443 -2
- package/dist/cjs/matrix.cjs +56 -0
- package/dist/cjs/priority-queue.cjs +172 -14
- package/dist/cjs/queue.cjs +435 -0
- package/dist/cjs/stack.cjs +103 -4
- package/dist/cjs/trie.cjs +106 -0
- package/dist/cjs-legacy/binary-tree.cjs +5933 -1772
- package/dist/cjs-legacy/graph.cjs +422 -14
- package/dist/cjs-legacy/hash.cjs +95 -7
- package/dist/cjs-legacy/heap.cjs +174 -16
- package/dist/cjs-legacy/index.cjs +8154 -2854
- package/dist/cjs-legacy/linked-list.cjs +443 -2
- package/dist/cjs-legacy/matrix.cjs +56 -0
- package/dist/cjs-legacy/priority-queue.cjs +172 -14
- package/dist/cjs-legacy/queue.cjs +435 -0
- package/dist/cjs-legacy/stack.cjs +103 -4
- package/dist/cjs-legacy/trie.cjs +106 -0
- package/dist/esm/binary-tree.mjs +5841 -1678
- package/dist/esm/graph.mjs +422 -14
- package/dist/esm/hash.mjs +95 -7
- package/dist/esm/heap.mjs +174 -16
- package/dist/esm/index.mjs +7751 -2449
- package/dist/esm/linked-list.mjs +443 -2
- package/dist/esm/matrix.mjs +56 -0
- package/dist/esm/priority-queue.mjs +172 -14
- package/dist/esm/queue.mjs +435 -0
- package/dist/esm/stack.mjs +103 -4
- package/dist/esm/trie.mjs +106 -0
- package/dist/esm-legacy/binary-tree.mjs +5933 -1772
- package/dist/esm-legacy/graph.mjs +422 -14
- package/dist/esm-legacy/hash.mjs +95 -7
- package/dist/esm-legacy/heap.mjs +174 -16
- package/dist/esm-legacy/index.mjs +8154 -2854
- package/dist/esm-legacy/linked-list.mjs +443 -2
- package/dist/esm-legacy/matrix.mjs +56 -0
- package/dist/esm-legacy/priority-queue.mjs +172 -14
- package/dist/esm-legacy/queue.mjs +435 -0
- package/dist/esm-legacy/stack.mjs +103 -4
- package/dist/esm-legacy/trie.mjs +106 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/data-structure-typed.js +7784 -2484
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
- package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +143 -155
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +46 -42
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
- package/docs-site-docusaurus/docs/api/classes/Queue.md +111 -59
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
- package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
- package/docs-site-docusaurus/docs/guide/faq.md +53 -0
- package/docs-site-docusaurus/docs/guide/guides.md +8 -9
- package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
- package/docs-site-docusaurus/docs/guide/overview.md +131 -17
- package/docs-site-docusaurus/src/pages/index.tsx +4 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/jest.integration.config.js +1 -2
- package/package.json +10 -7
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
|
@@ -191,6 +191,38 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
191
191
|
return false;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
196
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
197
|
+
* @param element - Element to search for (uses `===`).
|
|
198
|
+
* @returns `true` if found.
|
|
199
|
+
*/
|
|
200
|
+
includes(element: E): boolean {
|
|
201
|
+
return this.has(element);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
206
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
207
|
+
*/
|
|
208
|
+
*entries(): IterableIterator<[number, E]> {
|
|
209
|
+
let index = 0;
|
|
210
|
+
for (const value of this) {
|
|
211
|
+
yield [index++, value];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
217
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
218
|
+
*/
|
|
219
|
+
*keys(): IterableIterator<number> {
|
|
220
|
+
let index = 0;
|
|
221
|
+
for (const _ of this) {
|
|
222
|
+
yield index++;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
194
226
|
reduce(callbackfn: ReduceElementCallback<E, R>): E;
|
|
195
227
|
reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
|
|
196
228
|
reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
|
|
@@ -327,6 +327,17 @@ export abstract class LinearBase<
|
|
|
327
327
|
*/
|
|
328
328
|
abstract reverse(): this;
|
|
329
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
332
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
333
|
+
* @returns A new reversed instance.
|
|
334
|
+
*/
|
|
335
|
+
toReversed(): this {
|
|
336
|
+
const cloned = this.clone();
|
|
337
|
+
cloned.reverse();
|
|
338
|
+
return cloned as this;
|
|
339
|
+
}
|
|
340
|
+
|
|
330
341
|
/**
|
|
331
342
|
* Append one element or node to the tail.
|
|
332
343
|
* @param elementOrNode - Element or node.
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
import { BST } from './bst';
|
|
10
10
|
import type {
|
|
11
11
|
AVLTreeOptions,
|
|
12
|
-
BinaryTreeDeleteResult,
|
|
13
12
|
BinaryTreeOptions,
|
|
14
13
|
BSTNOptKeyOrNode,
|
|
15
14
|
EntryCallback,
|
|
@@ -471,6 +470,34 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
471
470
|
|
|
472
471
|
|
|
473
472
|
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
474
501
|
|
|
475
502
|
|
|
476
503
|
|
|
@@ -600,6 +627,27 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
600
627
|
|
|
601
628
|
|
|
602
629
|
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
603
651
|
|
|
604
652
|
|
|
605
653
|
|
|
@@ -630,15 +678,15 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
630
678
|
*/
|
|
631
679
|
override delete(
|
|
632
680
|
keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
633
|
-
):
|
|
634
|
-
const deletedResults =
|
|
681
|
+
): boolean {
|
|
682
|
+
const deletedResults = this._deleteInternal(keyNodeOrEntry);
|
|
635
683
|
// After deletion, balance the path from the parent of the *physically deleted* node.
|
|
636
684
|
for (const { needBalanced } of deletedResults) {
|
|
637
685
|
if (needBalanced) {
|
|
638
|
-
this._balancePath(needBalanced);
|
|
686
|
+
this._balancePath(needBalanced as AVLTreeNode<K, V>);
|
|
639
687
|
}
|
|
640
688
|
}
|
|
641
|
-
return deletedResults;
|
|
689
|
+
return deletedResults.length > 0;
|
|
642
690
|
}
|
|
643
691
|
|
|
644
692
|
/**
|
|
@@ -693,6 +741,20 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
693
741
|
|
|
694
742
|
|
|
695
743
|
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
696
758
|
|
|
697
759
|
|
|
698
760
|
|
|
@@ -830,6 +892,27 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
830
892
|
|
|
831
893
|
|
|
832
894
|
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
833
916
|
|
|
834
917
|
|
|
835
918
|
|
|
@@ -103,6 +103,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
106
120
|
|
|
107
121
|
|
|
108
122
|
|
|
@@ -180,6 +194,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
180
194
|
|
|
181
195
|
|
|
182
196
|
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
183
211
|
|
|
184
212
|
|
|
185
213
|
|
|
@@ -257,6 +285,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
257
285
|
|
|
258
286
|
|
|
259
287
|
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
260
302
|
|
|
261
303
|
|
|
262
304
|
|
|
@@ -334,6 +376,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
334
376
|
|
|
335
377
|
|
|
336
378
|
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
337
393
|
|
|
338
394
|
|
|
339
395
|
|
|
@@ -409,6 +465,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
409
465
|
|
|
410
466
|
|
|
411
467
|
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
412
482
|
|
|
413
483
|
|
|
414
484
|
|
|
@@ -492,6 +562,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
492
562
|
|
|
493
563
|
|
|
494
564
|
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
495
579
|
|
|
496
580
|
|
|
497
581
|
|
|
@@ -552,6 +636,13 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
552
636
|
|
|
553
637
|
|
|
554
638
|
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
555
646
|
|
|
556
647
|
|
|
557
648
|
|
|
@@ -621,6 +712,13 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
621
712
|
|
|
622
713
|
|
|
623
714
|
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
624
722
|
|
|
625
723
|
|
|
626
724
|
|