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
|
@@ -158,6 +158,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
158
158
|
for (const ele of this) if (ele === element) return true;
|
|
159
159
|
return false;
|
|
160
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
163
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
164
|
+
* @param element - Element to search for (uses `===`).
|
|
165
|
+
* @returns `true` if found.
|
|
166
|
+
*/
|
|
167
|
+
includes(element) {
|
|
168
|
+
return this.has(element);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
172
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
173
|
+
*/
|
|
174
|
+
*entries() {
|
|
175
|
+
let index = 0;
|
|
176
|
+
for (const value of this) {
|
|
177
|
+
yield [index++, value];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
182
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
183
|
+
*/
|
|
184
|
+
*keys() {
|
|
185
|
+
let index = 0;
|
|
186
|
+
for (const _ of this) {
|
|
187
|
+
yield index++;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
161
190
|
/**
|
|
162
191
|
* Reduces all elements to a single accumulated value.
|
|
163
192
|
*
|
|
@@ -283,6 +312,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
283
312
|
|
|
284
313
|
|
|
285
314
|
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
286
322
|
|
|
287
323
|
|
|
288
324
|
|
|
@@ -343,6 +379,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
343
379
|
|
|
344
380
|
|
|
345
381
|
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
346
389
|
|
|
347
390
|
|
|
348
391
|
|
|
@@ -392,6 +435,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
392
435
|
|
|
393
436
|
|
|
394
437
|
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
395
445
|
|
|
396
446
|
|
|
397
447
|
|
|
@@ -441,6 +491,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
441
491
|
|
|
442
492
|
|
|
443
493
|
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
444
501
|
|
|
445
502
|
|
|
446
503
|
|
|
@@ -499,6 +556,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
499
556
|
|
|
500
557
|
|
|
501
558
|
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
502
566
|
|
|
503
567
|
|
|
504
568
|
|
|
@@ -572,6 +636,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
572
636
|
|
|
573
637
|
|
|
574
638
|
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
575
646
|
|
|
576
647
|
|
|
577
648
|
|
|
@@ -588,18 +659,18 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
588
659
|
*/
|
|
589
660
|
delete(element) {
|
|
590
661
|
const idx = this._indexOfByEquals(element);
|
|
591
|
-
return this.deleteAt(idx);
|
|
662
|
+
return this.deleteAt(idx) !== void 0;
|
|
592
663
|
}
|
|
593
664
|
/**
|
|
594
665
|
* Delete the element at an index.
|
|
595
666
|
* @remarks Time O(N), Space O(1)
|
|
596
667
|
* @param index - Zero-based index from the bottom.
|
|
597
|
-
* @returns
|
|
668
|
+
* @returns The removed element, or undefined if the index is out of range.
|
|
598
669
|
*/
|
|
599
670
|
deleteAt(index) {
|
|
600
|
-
if (index < 0 || index >= this.elements.length) return
|
|
671
|
+
if (index < 0 || index >= this.elements.length) return void 0;
|
|
601
672
|
const spliced = this.elements.splice(index, 1);
|
|
602
|
-
return spliced
|
|
673
|
+
return spliced[0];
|
|
603
674
|
}
|
|
604
675
|
/**
|
|
605
676
|
* Delete the first element that satisfies a predicate.
|
|
@@ -645,6 +716,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
645
716
|
|
|
646
717
|
|
|
647
718
|
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
648
726
|
|
|
649
727
|
|
|
650
728
|
|
|
@@ -691,6 +769,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
691
769
|
|
|
692
770
|
|
|
693
771
|
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
694
779
|
|
|
695
780
|
|
|
696
781
|
|
|
@@ -743,6 +828,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
743
828
|
|
|
744
829
|
|
|
745
830
|
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
746
838
|
|
|
747
839
|
|
|
748
840
|
|
|
@@ -815,6 +907,13 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
815
907
|
|
|
816
908
|
|
|
817
909
|
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
818
917
|
|
|
819
918
|
|
|
820
919
|
|
package/dist/esm-legacy/trie.mjs
CHANGED
|
@@ -183,6 +183,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
183
183
|
for (const ele of this) if (ele === element) return true;
|
|
184
184
|
return false;
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
188
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
189
|
+
* @param element - Element to search for (uses `===`).
|
|
190
|
+
* @returns `true` if found.
|
|
191
|
+
*/
|
|
192
|
+
includes(element) {
|
|
193
|
+
return this.has(element);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
197
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
198
|
+
*/
|
|
199
|
+
*entries() {
|
|
200
|
+
let index = 0;
|
|
201
|
+
for (const value of this) {
|
|
202
|
+
yield [index++, value];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
207
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
208
|
+
*/
|
|
209
|
+
*keys() {
|
|
210
|
+
let index = 0;
|
|
211
|
+
for (const _ of this) {
|
|
212
|
+
yield index++;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
186
215
|
/**
|
|
187
216
|
* Reduces all elements to a single accumulated value.
|
|
188
217
|
*
|
|
@@ -410,6 +439,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
410
439
|
|
|
411
440
|
|
|
412
441
|
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
413
449
|
|
|
414
450
|
|
|
415
451
|
|
|
@@ -482,6 +518,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
482
518
|
|
|
483
519
|
|
|
484
520
|
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
485
528
|
|
|
486
529
|
|
|
487
530
|
|
|
@@ -541,6 +584,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
541
584
|
|
|
542
585
|
|
|
543
586
|
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
544
594
|
|
|
545
595
|
|
|
546
596
|
|
|
@@ -595,6 +645,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
595
645
|
|
|
596
646
|
|
|
597
647
|
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
598
655
|
|
|
599
656
|
|
|
600
657
|
|
|
@@ -641,6 +698,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
641
698
|
|
|
642
699
|
|
|
643
700
|
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
644
708
|
|
|
645
709
|
|
|
646
710
|
|
|
@@ -691,6 +755,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
691
755
|
|
|
692
756
|
|
|
693
757
|
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
694
765
|
|
|
695
766
|
|
|
696
767
|
|
|
@@ -823,6 +894,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
823
894
|
|
|
824
895
|
|
|
825
896
|
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
826
904
|
|
|
827
905
|
|
|
828
906
|
|
|
@@ -899,6 +977,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
899
977
|
|
|
900
978
|
|
|
901
979
|
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
902
987
|
|
|
903
988
|
|
|
904
989
|
|
|
@@ -958,6 +1043,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
958
1043
|
|
|
959
1044
|
|
|
960
1045
|
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
961
1053
|
|
|
962
1054
|
|
|
963
1055
|
|
|
@@ -1035,6 +1127,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
1035
1127
|
|
|
1036
1128
|
|
|
1037
1129
|
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1038
1137
|
|
|
1039
1138
|
|
|
1040
1139
|
|
|
@@ -1085,6 +1184,13 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
1085
1184
|
|
|
1086
1185
|
|
|
1087
1186
|
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1088
1194
|
|
|
1089
1195
|
|
|
1090
1196
|
|
|
@@ -118,6 +118,23 @@ export declare abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
118
118
|
* Time O(n) in the worst case. Space O(1).
|
|
119
119
|
*/
|
|
120
120
|
has(element: E): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
123
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
124
|
+
* @param element - Element to search for (uses `===`).
|
|
125
|
+
* @returns `true` if found.
|
|
126
|
+
*/
|
|
127
|
+
includes(element: E): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
130
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
131
|
+
*/
|
|
132
|
+
entries(): IterableIterator<[number, E]>;
|
|
133
|
+
/**
|
|
134
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
135
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
136
|
+
*/
|
|
137
|
+
keys(): IterableIterator<number>;
|
|
121
138
|
reduce(callbackfn: ReduceElementCallback<E, R>): E;
|
|
122
139
|
reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
|
|
123
140
|
reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
|
|
@@ -173,6 +173,12 @@ export declare abstract class LinearBase<E, R = any, NODE extends LinkedListNode
|
|
|
173
173
|
* @remarks Time O(n), Space O(1)
|
|
174
174
|
*/
|
|
175
175
|
abstract reverse(): this;
|
|
176
|
+
/**
|
|
177
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
178
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
179
|
+
* @returns A new reversed instance.
|
|
180
|
+
*/
|
|
181
|
+
toReversed(): this;
|
|
176
182
|
/**
|
|
177
183
|
* Append one element or node to the tail.
|
|
178
184
|
* @param elementOrNode - Element or node.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST } from './bst';
|
|
9
|
-
import type { AVLTreeOptions,
|
|
9
|
+
import type { AVLTreeOptions, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
12
12
|
* Represents a Node in an AVL (Adelson-Velsky and Landis) Tree.
|
|
@@ -378,6 +378,34 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
378
378
|
|
|
379
379
|
|
|
380
380
|
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
381
409
|
|
|
382
410
|
|
|
383
411
|
|
|
@@ -497,6 +525,27 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
497
525
|
|
|
498
526
|
|
|
499
527
|
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
500
549
|
|
|
501
550
|
|
|
502
551
|
|
|
@@ -525,7 +574,7 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
525
574
|
* console.log(avl.has(3)); // false;
|
|
526
575
|
* console.log(avl.size); // 6;
|
|
527
576
|
*/
|
|
528
|
-
delete(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined):
|
|
577
|
+
delete(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
529
578
|
/**
|
|
530
579
|
* Rebuilds the tree to be perfectly balanced.
|
|
531
580
|
* @remarks AVL trees are already height-balanced, but this makes them *perfectly* balanced (minimal height and all leaves at N or N-1).
|
|
@@ -578,6 +627,20 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
578
627
|
|
|
579
628
|
|
|
580
629
|
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
581
644
|
|
|
582
645
|
|
|
583
646
|
|
|
@@ -687,6 +750,27 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
687
750
|
|
|
688
751
|
|
|
689
752
|
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
690
774
|
|
|
691
775
|
|
|
692
776
|
|
|
@@ -76,6 +76,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
79
93
|
|
|
80
94
|
|
|
81
95
|
|
|
@@ -149,6 +163,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
149
163
|
|
|
150
164
|
|
|
151
165
|
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
152
180
|
|
|
153
181
|
|
|
154
182
|
|
|
@@ -221,6 +249,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
221
249
|
|
|
222
250
|
|
|
223
251
|
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
224
266
|
|
|
225
267
|
|
|
226
268
|
|
|
@@ -294,6 +336,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
294
336
|
|
|
295
337
|
|
|
296
338
|
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
297
353
|
|
|
298
354
|
|
|
299
355
|
|
|
@@ -365,6 +421,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
365
421
|
|
|
366
422
|
|
|
367
423
|
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
368
438
|
|
|
369
439
|
|
|
370
440
|
|
|
@@ -439,6 +509,20 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
439
509
|
|
|
440
510
|
|
|
441
511
|
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
442
526
|
|
|
443
527
|
|
|
444
528
|
|
|
@@ -484,6 +568,13 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
484
568
|
|
|
485
569
|
|
|
486
570
|
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
487
578
|
|
|
488
579
|
|
|
489
580
|
|
|
@@ -524,6 +615,13 @@ export declare class BinaryIndexedTree implements Iterable<number> {
|
|
|
524
615
|
|
|
525
616
|
|
|
526
617
|
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
527
625
|
|
|
528
626
|
|
|
529
627
|
|