data-structure-typed 2.5.1 → 2.5.3
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/CHANGELOG.md +5 -1
- package/MIGRATION.md +169 -0
- package/README.md +135 -23
- package/README_CN.md +551 -143
- package/SPECIFICATION.md +20 -14
- package/SPECIFICATION.zh-CN.md +20 -14
- package/dist/cjs/binary-tree.cjs +6460 -1591
- package/dist/cjs/graph.cjs +440 -20
- package/dist/cjs/hash.cjs +125 -22
- package/dist/cjs/heap.cjs +196 -47
- package/dist/cjs/index.cjs +8486 -2429
- package/dist/cjs/linked-list.cjs +456 -31
- package/dist/cjs/matrix.cjs +79 -9
- package/dist/cjs/priority-queue.cjs +193 -44
- package/dist/cjs/queue.cjs +391 -2
- package/dist/cjs/stack.cjs +92 -6
- package/dist/cjs/trie.cjs +122 -28
- package/dist/cjs-legacy/binary-tree.cjs +6484 -1612
- package/dist/cjs-legacy/graph.cjs +440 -20
- package/dist/cjs-legacy/hash.cjs +125 -22
- package/dist/cjs-legacy/heap.cjs +196 -47
- package/dist/cjs-legacy/index.cjs +8654 -2594
- package/dist/cjs-legacy/linked-list.cjs +456 -31
- package/dist/cjs-legacy/matrix.cjs +79 -9
- package/dist/cjs-legacy/priority-queue.cjs +193 -44
- package/dist/cjs-legacy/queue.cjs +391 -2
- package/dist/cjs-legacy/stack.cjs +92 -6
- package/dist/cjs-legacy/trie.cjs +122 -28
- package/dist/esm/binary-tree.mjs +6460 -1591
- package/dist/esm/graph.mjs +440 -20
- package/dist/esm/hash.mjs +125 -22
- package/dist/esm/heap.mjs +196 -47
- package/dist/esm/index.mjs +8486 -2430
- package/dist/esm/linked-list.mjs +456 -31
- package/dist/esm/matrix.mjs +79 -9
- package/dist/esm/priority-queue.mjs +193 -44
- package/dist/esm/queue.mjs +391 -2
- package/dist/esm/stack.mjs +92 -6
- package/dist/esm/trie.mjs +122 -28
- package/dist/esm-legacy/binary-tree.mjs +6484 -1612
- package/dist/esm-legacy/graph.mjs +440 -20
- package/dist/esm-legacy/hash.mjs +125 -22
- package/dist/esm-legacy/heap.mjs +196 -47
- package/dist/esm-legacy/index.mjs +8654 -2595
- package/dist/esm-legacy/linked-list.mjs +456 -31
- package/dist/esm-legacy/matrix.mjs +79 -9
- package/dist/esm-legacy/priority-queue.mjs +193 -44
- package/dist/esm-legacy/queue.mjs +391 -2
- package/dist/esm-legacy/stack.mjs +92 -6
- package/dist/esm-legacy/trie.mjs +122 -28
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +98 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +112 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +214 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +294 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +155 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +48 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1370 -323
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1329 -316
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +1116 -295
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1330 -326
- package/dist/types/data-structures/graph/directed-graph.d.ts +80 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +72 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +95 -6
- package/dist/types/data-structures/heap/heap.d.ts +154 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +143 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +144 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +64 -0
- package/dist/types/data-structures/queue/deque.d.ts +142 -0
- package/dist/types/data-structures/queue/queue.d.ts +109 -0
- package/dist/types/data-structures/stack/stack.d.ts +82 -2
- package/dist/types/data-structures/trie/trie.d.ts +96 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- 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/umd/data-structure-typed.js +8623 -2564
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +696 -194
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +71 -71
- package/docs-site-docusaurus/docs/api/classes/BST.md +639 -189
- 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 +148 -160
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +105 -91
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +104 -74
- 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 +51 -51
- 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 +33 -33
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +50 -50
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +78 -78
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +82 -82
- 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 +112 -60
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +708 -206
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +79 -79
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +44 -44
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +236 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +162 -46
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +232 -32
- package/docs-site-docusaurus/docs/api/classes/Trie.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +81 -81
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -5
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -3
- package/docs-site-docusaurus/docs/guide/faq.md +233 -0
- package/docs-site-docusaurus/docs/guide/guides.md +43 -58
- package/docs-site-docusaurus/docs/guide/installation.md +2 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +75 -176
- package/docs-site-docusaurus/docs/guide/overview.md +132 -11
- package/docs-site-docusaurus/docs/guide/performance.md +2 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +31 -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 +1 -1
- package/docs-site-docusaurus/src/pages/index.tsx +55 -2
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/llms.txt +37 -0
- package/package.json +65 -56
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- 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 +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -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 +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- 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/.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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparator, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodePredicate, OptNode, RBTNColor } from '../../types';
|
|
9
9
|
import { BinaryTree } from './binary-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { Range } from '../../common';
|
|
@@ -254,6 +254,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
254
254
|
*/
|
|
255
255
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
|
|
256
256
|
protected _root?: BSTNode<K, V>;
|
|
257
|
+
protected _enableOrderStatistic: boolean;
|
|
257
258
|
/**
|
|
258
259
|
* Gets the root node of the tree.
|
|
259
260
|
* @remarks Time O(1)
|
|
@@ -355,6 +356,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
355
356
|
|
|
356
357
|
|
|
357
358
|
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
358
375
|
|
|
359
376
|
|
|
360
377
|
|
|
@@ -419,6 +436,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
419
436
|
|
|
420
437
|
|
|
421
438
|
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
422
455
|
|
|
423
456
|
|
|
424
457
|
|
|
@@ -486,6 +519,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
486
519
|
|
|
487
520
|
|
|
488
521
|
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
489
538
|
|
|
490
539
|
|
|
491
540
|
|
|
@@ -507,7 +556,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
507
556
|
* // Level-order grouping
|
|
508
557
|
* const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
509
558
|
* const levels = bst.listLevels(node => node.key);
|
|
510
|
-
* console.log(levels
|
|
559
|
+
* console.log(levels); // toBeInstanceOf;
|
|
511
560
|
* console.log(levels[0].length); // 1; // root level has 1 node
|
|
512
561
|
* const allKeys = levels.flat().sort((a, b) => a - b);
|
|
513
562
|
* console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -564,6 +613,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
564
613
|
|
|
565
614
|
|
|
566
615
|
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
567
632
|
|
|
568
633
|
|
|
569
634
|
|
|
@@ -626,6 +691,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
626
691
|
|
|
627
692
|
|
|
628
693
|
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
629
710
|
|
|
630
711
|
|
|
631
712
|
|
|
@@ -675,6 +756,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
675
756
|
|
|
676
757
|
|
|
677
758
|
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
678
767
|
|
|
679
768
|
|
|
680
769
|
|
|
@@ -691,6 +780,69 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
691
780
|
*/
|
|
692
781
|
rangeSearch(range: Range<K> | [K, K]): (K | undefined)[];
|
|
693
782
|
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
783
|
+
/**
|
|
784
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
785
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
786
|
+
* Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
787
|
+
*
|
|
788
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
789
|
+
* @returns The key at position k, or `undefined` if out of bounds.
|
|
790
|
+
* @example
|
|
791
|
+
* // Order-statistic on BST
|
|
792
|
+
* const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
793
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
794
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
795
|
+
* console.log(tree.getRank(30)); // 2;
|
|
796
|
+
*/
|
|
797
|
+
getByRank(k: number): K | undefined;
|
|
798
|
+
/**
|
|
799
|
+
* Returns the element at the k-th position in tree order and applies a callback.
|
|
800
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
801
|
+
*
|
|
802
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
803
|
+
* @param callback - Callback to apply to the found node.
|
|
804
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
805
|
+
* @returns The callback result, or `undefined` if out of bounds.
|
|
806
|
+
*/
|
|
807
|
+
getByRank<C extends NodeCallback<BSTNode<K, V>>>(k: number, callback: C, iterationType?: IterationType): ReturnType<C> | undefined;
|
|
808
|
+
/**
|
|
809
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
810
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
811
|
+
* Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
812
|
+
*
|
|
813
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry `[K, V]`, or predicate to find.
|
|
814
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
815
|
+
*/
|
|
816
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): number;
|
|
817
|
+
/**
|
|
818
|
+
* Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
819
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
820
|
+
*
|
|
821
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate to find.
|
|
822
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
823
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
824
|
+
*/
|
|
825
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, iterationType: IterationType): number;
|
|
826
|
+
/**
|
|
827
|
+
* Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
828
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
829
|
+
*
|
|
830
|
+
* @param start - Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
831
|
+
* @param end - End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
832
|
+
* @returns Array of keys in tree order within the specified range.
|
|
833
|
+
*/
|
|
834
|
+
rangeByRank(start: number, end: number): (K | undefined)[];
|
|
835
|
+
/**
|
|
836
|
+
* Returns elements by position range in tree order with callback and optional iteration type.
|
|
837
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
838
|
+
*
|
|
839
|
+
* @param start - Start rank (inclusive, 0-indexed).
|
|
840
|
+
* @param end - End rank (inclusive, 0-indexed).
|
|
841
|
+
* @param callback - Callback to apply to each node in the range.
|
|
842
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
843
|
+
* @returns Array of callback results for nodes in the rank range.
|
|
844
|
+
*/
|
|
845
|
+
rangeByRank<C extends NodeCallback<BSTNode<K, V>>>(start: number, end: number, callback: C, iterationType?: IterationType): ReturnType<C>[];
|
|
694
846
|
/**
|
|
695
847
|
* Adds a new node to the BST based on key comparison.
|
|
696
848
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -762,6 +914,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
762
914
|
|
|
763
915
|
|
|
764
916
|
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
765
941
|
|
|
766
942
|
|
|
767
943
|
|
|
@@ -836,6 +1012,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
836
1012
|
|
|
837
1013
|
|
|
838
1014
|
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
839
1031
|
|
|
840
1032
|
|
|
841
1033
|
|
|
@@ -888,6 +1080,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
888
1080
|
|
|
889
1081
|
|
|
890
1082
|
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
891
1091
|
|
|
892
1092
|
|
|
893
1093
|
|
|
@@ -938,6 +1138,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
938
1138
|
|
|
939
1139
|
|
|
940
1140
|
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
941
1149
|
|
|
942
1150
|
|
|
943
1151
|
|
|
@@ -987,6 +1195,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
987
1195
|
|
|
988
1196
|
|
|
989
1197
|
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
990
1206
|
|
|
991
1207
|
|
|
992
1208
|
|
|
@@ -1037,6 +1253,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1037
1253
|
|
|
1038
1254
|
|
|
1039
1255
|
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1040
1264
|
|
|
1041
1265
|
|
|
1042
1266
|
|
|
@@ -1087,6 +1311,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1087
1311
|
|
|
1088
1312
|
|
|
1089
1313
|
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1090
1322
|
|
|
1091
1323
|
|
|
1092
1324
|
|
|
@@ -1132,6 +1364,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1132
1364
|
|
|
1133
1365
|
|
|
1134
1366
|
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1135
1375
|
|
|
1136
1376
|
|
|
1137
1377
|
|
|
@@ -1201,6 +1441,22 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1201
1441
|
|
|
1202
1442
|
|
|
1203
1443
|
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1204
1460
|
|
|
1205
1461
|
|
|
1206
1462
|
|
|
@@ -1261,7 +1517,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1261
1517
|
* - Value: true if the deletion succeeded, false if it failed (e.g., key not found during deletion phase).
|
|
1262
1518
|
* - If no nodes match the search criteria, the returned map is empty.
|
|
1263
1519
|
*/
|
|
1264
|
-
deleteWhere(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType):
|
|
1520
|
+
deleteWhere(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
1265
1521
|
/**
|
|
1266
1522
|
* (Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
1267
1523
|
* @remarks Time O(1) Space O(1)
|
|
@@ -1388,6 +1644,41 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1388
1644
|
*
|
|
1389
1645
|
* @param v - The node to set as root.
|
|
1390
1646
|
*/
|
|
1647
|
+
/**
|
|
1648
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
1649
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
1650
|
+
*/
|
|
1651
|
+
protected _updateCount(node: BSTNode<K, V>): void;
|
|
1652
|
+
/**
|
|
1653
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
1654
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
1655
|
+
*/
|
|
1656
|
+
protected _updateCountAlongPath(node: OptNode<BSTNode<K, V>>): void;
|
|
1657
|
+
/**
|
|
1658
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
1659
|
+
* @remarks Time O(log n), Space O(1)
|
|
1660
|
+
*/
|
|
1661
|
+
protected _getByRankIterative(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1662
|
+
/**
|
|
1663
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
1664
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1665
|
+
*/
|
|
1666
|
+
protected _getByRankRecursive(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1667
|
+
/**
|
|
1668
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
1669
|
+
* @remarks Time O(log n), Space O(1)
|
|
1670
|
+
*/
|
|
1671
|
+
protected _getRankIterative(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1672
|
+
/**
|
|
1673
|
+
* (Protected) Computes the rank of a key recursively.
|
|
1674
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1675
|
+
*/
|
|
1676
|
+
protected _getRankRecursive(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1677
|
+
/**
|
|
1678
|
+
* (Protected) Finds the in-order successor of a node.
|
|
1679
|
+
* @remarks Time O(log n), Space O(1)
|
|
1680
|
+
*/
|
|
1681
|
+
protected _next(node: BSTNode<K, V>): BSTNode<K, V> | undefined;
|
|
1391
1682
|
protected _setRoot(v: OptNode<BSTNode<K, V>>): void;
|
|
1392
1683
|
/**
|
|
1393
1684
|
* (Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { BTNRep, CRUD, EntryCallback, FamilyPosition, NodePredicate, RBTNColor, IterationType, RedBlackTreeOptions } from '../../types';
|
|
9
9
|
import { BST } from './bst';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
export declare class RedBlackTreeNode<K = any, V = any> {
|
|
@@ -217,13 +217,40 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
217
217
|
*/
|
|
218
218
|
isNode(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is RedBlackTreeNode<K, V>;
|
|
219
219
|
/**
|
|
220
|
-
* Remove all nodes
|
|
220
|
+
* Remove all nodes, clear the key→value store (if in map mode) and internal caches.
|
|
221
221
|
* @remarks Time O(n), Space O(1)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
227
254
|
|
|
228
255
|
|
|
229
256
|
|
|
@@ -540,6 +567,38 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
540
567
|
|
|
541
568
|
|
|
542
569
|
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
543
602
|
|
|
544
603
|
|
|
545
604
|
|
|
@@ -682,6 +741,38 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
682
741
|
|
|
683
742
|
|
|
684
743
|
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
685
776
|
|
|
686
777
|
|
|
687
778
|
|
|
@@ -710,7 +801,7 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
710
801
|
* console.log(rbt.has(5)); // false;
|
|
711
802
|
* console.log(rbt.size); // 4;
|
|
712
803
|
*/
|
|
713
|
-
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>):
|
|
804
|
+
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>): boolean;
|
|
714
805
|
/**
|
|
715
806
|
* Transform entries into a like-kind red-black tree with possibly different key/value types.
|
|
716
807
|
* @remarks Time O(n) average, Space O(n)
|
|
@@ -790,6 +881,30 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
790
881
|
|
|
791
882
|
|
|
792
883
|
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
793
908
|
|
|
794
909
|
|
|
795
910
|
|
|
@@ -914,6 +1029,38 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
914
1029
|
|
|
915
1030
|
|
|
916
1031
|
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
917
1064
|
|
|
918
1065
|
|
|
919
1066
|
|
|
@@ -67,6 +67,14 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
70
78
|
|
|
71
79
|
|
|
72
80
|
|
|
@@ -124,6 +132,14 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
124
132
|
|
|
125
133
|
|
|
126
134
|
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
127
143
|
|
|
128
144
|
|
|
129
145
|
|
|
@@ -177,6 +193,14 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
177
193
|
|
|
178
194
|
|
|
179
195
|
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
180
204
|
|
|
181
205
|
|
|
182
206
|
|
|
@@ -225,6 +249,14 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
225
249
|
|
|
226
250
|
|
|
227
251
|
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
228
260
|
|
|
229
261
|
|
|
230
262
|
|
|
@@ -268,6 +300,14 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
268
300
|
|
|
269
301
|
|
|
270
302
|
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
271
311
|
|
|
272
312
|
|
|
273
313
|
|
|
@@ -314,6 +354,14 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
314
354
|
|
|
315
355
|
|
|
316
356
|
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
317
365
|
|
|
318
366
|
|
|
319
367
|
|