trie-typed 2.1.1 → 2.2.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/dist/cjs/index.cjs +797 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs-legacy/index.cjs +795 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +792 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm-legacy/index.mjs +790 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +345 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +467 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +262 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +244 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +332 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/trie-typed.js +802 -0
- package/dist/umd/trie-typed.js.map +1 -0
- package/dist/umd/trie-typed.min.js +9 -0
- package/dist/umd/trie-typed.min.js.map +1 -0
- package/package.json +43 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +107 -16
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +103 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
- package/src/data-structures/binary-tree/tree-counter.ts +105 -14
- package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +1 -1
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +71 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -28
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -12,7 +12,9 @@ import type {
|
|
|
12
12
|
BTNOptKeyOrNull,
|
|
13
13
|
ElemOf,
|
|
14
14
|
EntryCallback,
|
|
15
|
-
|
|
15
|
+
FamilyPosition,
|
|
16
|
+
IterationType,
|
|
17
|
+
RBTNColor
|
|
16
18
|
} from '../../types';
|
|
17
19
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
18
20
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -23,8 +25,10 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
23
25
|
* @template K
|
|
24
26
|
* @template V
|
|
25
27
|
*/
|
|
26
|
-
export class AVLTreeMultiMapNode<K = any, V = any>
|
|
27
|
-
|
|
28
|
+
export class AVLTreeMultiMapNode<K = any, V = any> {
|
|
29
|
+
key: K;
|
|
30
|
+
value?: V[];
|
|
31
|
+
parent?: AVLTreeMultiMapNode<K, V> = undefined;
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Create an AVLTreeMultiMap node with a value bucket.
|
|
@@ -33,18 +37,19 @@ export class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K, V[]> {
|
|
|
33
37
|
* @param value - Initial array of values.
|
|
34
38
|
* @returns New AVLTreeMultiMapNode instance.
|
|
35
39
|
*/
|
|
36
|
-
constructor(key: K, value: V[]) {
|
|
37
|
-
|
|
40
|
+
constructor(key: K, value: V[] = []) {
|
|
41
|
+
this.key = key;
|
|
42
|
+
this.value = value;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
_left?: AVLTreeMultiMapNode<K, V> | null | undefined = undefined;
|
|
41
46
|
|
|
42
47
|
/**
|
|
43
48
|
* Get the left child pointer.
|
|
44
49
|
* @remarks Time O(1), Space O(1)
|
|
45
50
|
* @returns Left child node, or null/undefined.
|
|
46
51
|
*/
|
|
47
|
-
|
|
52
|
+
get left(): AVLTreeMultiMapNode<K, V> | null | undefined {
|
|
48
53
|
return this._left;
|
|
49
54
|
}
|
|
50
55
|
|
|
@@ -54,21 +59,21 @@ export class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K, V[]> {
|
|
|
54
59
|
* @param v - New left child node, or null/undefined.
|
|
55
60
|
* @returns void
|
|
56
61
|
*/
|
|
57
|
-
|
|
62
|
+
set left(v: AVLTreeMultiMapNode<K, V> | null | undefined) {
|
|
58
63
|
if (v) {
|
|
59
64
|
v.parent = this;
|
|
60
65
|
}
|
|
61
66
|
this._left = v;
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
_right?: AVLTreeMultiMapNode<K, V> | null | undefined = undefined;
|
|
65
70
|
|
|
66
71
|
/**
|
|
67
72
|
* Get the right child pointer.
|
|
68
73
|
* @remarks Time O(1), Space O(1)
|
|
69
74
|
* @returns Right child node, or null/undefined.
|
|
70
75
|
*/
|
|
71
|
-
|
|
76
|
+
get right(): AVLTreeMultiMapNode<K, V> | null | undefined {
|
|
72
77
|
return this._right;
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -78,12 +83,98 @@ export class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K, V[]> {
|
|
|
78
83
|
* @param v - New right child node, or null/undefined.
|
|
79
84
|
* @returns void
|
|
80
85
|
*/
|
|
81
|
-
|
|
86
|
+
set right(v: AVLTreeMultiMapNode<K, V> | null | undefined) {
|
|
82
87
|
if (v) {
|
|
83
88
|
v.parent = this;
|
|
84
89
|
}
|
|
85
90
|
this._right = v;
|
|
86
91
|
}
|
|
92
|
+
|
|
93
|
+
_height: number = 0;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
97
|
+
* @remarks Time O(1), Space O(1)
|
|
98
|
+
*
|
|
99
|
+
* @returns The height.
|
|
100
|
+
*/
|
|
101
|
+
get height(): number {
|
|
102
|
+
return this._height;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sets the height of the node.
|
|
107
|
+
* @remarks Time O(1), Space O(1)
|
|
108
|
+
*
|
|
109
|
+
* @param value - The new height.
|
|
110
|
+
*/
|
|
111
|
+
set height(value: number) {
|
|
112
|
+
this._height = value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_color: RBTNColor = 'BLACK';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
119
|
+
* @remarks Time O(1), Space O(1)
|
|
120
|
+
*
|
|
121
|
+
* @returns The node's color.
|
|
122
|
+
*/
|
|
123
|
+
get color(): RBTNColor {
|
|
124
|
+
return this._color;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sets the color of the node.
|
|
129
|
+
* @remarks Time O(1), Space O(1)
|
|
130
|
+
*
|
|
131
|
+
* @param value - The new color.
|
|
132
|
+
*/
|
|
133
|
+
set color(value: RBTNColor) {
|
|
134
|
+
this._color = value;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_count: number = 1;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
141
|
+
* @remarks Time O(1), Space O(1)
|
|
142
|
+
*
|
|
143
|
+
* @returns The subtree node count.
|
|
144
|
+
*/
|
|
145
|
+
get count(): number {
|
|
146
|
+
return this._count;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Sets the count of nodes in the subtree.
|
|
151
|
+
* @remarks Time O(1), Space O(1)
|
|
152
|
+
*
|
|
153
|
+
* @param value - The new count.
|
|
154
|
+
*/
|
|
155
|
+
set count(value: number) {
|
|
156
|
+
this._count = value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gets the position of the node relative to its parent.
|
|
161
|
+
* @remarks Time O(1), Space O(1)
|
|
162
|
+
*
|
|
163
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
164
|
+
*/
|
|
165
|
+
get familyPosition(): FamilyPosition {
|
|
166
|
+
if (!this.parent) {
|
|
167
|
+
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (this.parent.left === this) {
|
|
171
|
+
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
172
|
+
} else if (this.parent.right === this) {
|
|
173
|
+
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return 'MAL_NODE';
|
|
177
|
+
}
|
|
87
178
|
}
|
|
88
179
|
|
|
89
180
|
/**
|
|
@@ -113,10 +204,23 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
113
204
|
}
|
|
114
205
|
}
|
|
115
206
|
|
|
116
|
-
override
|
|
207
|
+
override createNode(key: K, value: V[] = []): AVLTreeMultiMapNode<K, V> {
|
|
117
208
|
return new AVLTreeMultiMapNode<K, V>(key, this._isMapMode ? [] : value);
|
|
118
209
|
}
|
|
119
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Checks if the given item is a `AVLTreeMultiMapNode` instance.
|
|
213
|
+
* @remarks Time O(1), Space O(1)
|
|
214
|
+
*
|
|
215
|
+
* @param keyNodeOrEntry - The item to check.
|
|
216
|
+
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
217
|
+
*/
|
|
218
|
+
override isNode(
|
|
219
|
+
keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
220
|
+
): keyNodeOrEntry is AVLTreeMultiMapNode<K, V> {
|
|
221
|
+
return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
222
|
+
}
|
|
223
|
+
|
|
120
224
|
override add(
|
|
121
225
|
keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
122
226
|
): boolean;
|
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { BST
|
|
9
|
+
import { BST } from './bst';
|
|
10
10
|
import type {
|
|
11
11
|
AVLTreeOptions,
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BinaryTreeOptions,
|
|
14
14
|
BSTNOptKeyOrNode,
|
|
15
15
|
EntryCallback,
|
|
16
|
-
|
|
16
|
+
FamilyPosition,
|
|
17
|
+
IterationType,
|
|
18
|
+
RBTNColor
|
|
17
19
|
} from '../../types';
|
|
18
20
|
import { BSTOptions } from '../../types';
|
|
19
21
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -25,8 +27,10 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
25
27
|
* @template K - The type of the key.
|
|
26
28
|
* @template V - The type of the value.
|
|
27
29
|
*/
|
|
28
|
-
export class AVLTreeNode<K = any, V = any>
|
|
29
|
-
|
|
30
|
+
export class AVLTreeNode<K = any, V = any> {
|
|
31
|
+
key: K;
|
|
32
|
+
value?: V;
|
|
33
|
+
parent?: AVLTreeNode<K, V> = undefined;
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
36
|
* Creates an instance of AVLTreeNode.
|
|
@@ -36,10 +40,11 @@ export class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
36
40
|
* @param [value] - The value associated with the key.
|
|
37
41
|
*/
|
|
38
42
|
constructor(key: K, value?: V) {
|
|
39
|
-
|
|
43
|
+
this.key = key;
|
|
44
|
+
this.value = value;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
_left?: AVLTreeNode<K, V> | null | undefined = undefined;
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
50
|
* Gets the left child of the node.
|
|
@@ -47,7 +52,7 @@ export class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
47
52
|
*
|
|
48
53
|
* @returns The left child.
|
|
49
54
|
*/
|
|
50
|
-
|
|
55
|
+
get left(): AVLTreeNode<K, V> | null | undefined {
|
|
51
56
|
return this._left;
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -57,14 +62,14 @@ export class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
57
62
|
*
|
|
58
63
|
* @param v - The node to set as the left child.
|
|
59
64
|
*/
|
|
60
|
-
|
|
65
|
+
set left(v: AVLTreeNode<K, V> | null | undefined) {
|
|
61
66
|
if (v) {
|
|
62
67
|
v.parent = this;
|
|
63
68
|
}
|
|
64
69
|
this._left = v;
|
|
65
70
|
}
|
|
66
71
|
|
|
67
|
-
|
|
72
|
+
_right?: AVLTreeNode<K, V> | null | undefined = undefined;
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
75
|
* Gets the right child of the node.
|
|
@@ -72,7 +77,7 @@ export class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
72
77
|
*
|
|
73
78
|
* @returns The right child.
|
|
74
79
|
*/
|
|
75
|
-
|
|
80
|
+
get right(): AVLTreeNode<K, V> | null | undefined {
|
|
76
81
|
return this._right;
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -82,12 +87,98 @@ export class AVLTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
82
87
|
*
|
|
83
88
|
* @param v - The node to set as the right child.
|
|
84
89
|
*/
|
|
85
|
-
|
|
90
|
+
set right(v: AVLTreeNode<K, V> | null | undefined) {
|
|
86
91
|
if (v) {
|
|
87
92
|
v.parent = this;
|
|
88
93
|
}
|
|
89
94
|
this._right = v;
|
|
90
95
|
}
|
|
96
|
+
|
|
97
|
+
_height: number = 0;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
101
|
+
* @remarks Time O(1), Space O(1)
|
|
102
|
+
*
|
|
103
|
+
* @returns The height.
|
|
104
|
+
*/
|
|
105
|
+
get height(): number {
|
|
106
|
+
return this._height;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sets the height of the node.
|
|
111
|
+
* @remarks Time O(1), Space O(1)
|
|
112
|
+
*
|
|
113
|
+
* @param value - The new height.
|
|
114
|
+
*/
|
|
115
|
+
set height(value: number) {
|
|
116
|
+
this._height = value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_color: RBTNColor = 'BLACK';
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
123
|
+
* @remarks Time O(1), Space O(1)
|
|
124
|
+
*
|
|
125
|
+
* @returns The node's color.
|
|
126
|
+
*/
|
|
127
|
+
get color(): RBTNColor {
|
|
128
|
+
return this._color;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Sets the color of the node.
|
|
133
|
+
* @remarks Time O(1), Space O(1)
|
|
134
|
+
*
|
|
135
|
+
* @param value - The new color.
|
|
136
|
+
*/
|
|
137
|
+
set color(value: RBTNColor) {
|
|
138
|
+
this._color = value;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_count: number = 1;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
145
|
+
* @remarks Time O(1), Space O(1)
|
|
146
|
+
*
|
|
147
|
+
* @returns The subtree node count.
|
|
148
|
+
*/
|
|
149
|
+
get count(): number {
|
|
150
|
+
return this._count;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sets the count of nodes in the subtree.
|
|
155
|
+
* @remarks Time O(1), Space O(1)
|
|
156
|
+
*
|
|
157
|
+
* @param value - The new count.
|
|
158
|
+
*/
|
|
159
|
+
set count(value: number) {
|
|
160
|
+
this._count = value;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Gets the position of the node relative to its parent.
|
|
165
|
+
* @remarks Time O(1), Space O(1)
|
|
166
|
+
*
|
|
167
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
168
|
+
*/
|
|
169
|
+
get familyPosition(): FamilyPosition {
|
|
170
|
+
if (!this.parent) {
|
|
171
|
+
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (this.parent.left === this) {
|
|
175
|
+
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
176
|
+
} else if (this.parent.right === this) {
|
|
177
|
+
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return 'MAL_NODE';
|
|
181
|
+
}
|
|
91
182
|
}
|
|
92
183
|
|
|
93
184
|
/**
|
|
@@ -196,7 +287,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
196
287
|
* @param [value] - The value for the new node.
|
|
197
288
|
* @returns The newly created AVLTreeNode.
|
|
198
289
|
*/
|
|
199
|
-
override
|
|
290
|
+
override createNode(key: K, value?: V): AVLTreeNode<K, V> {
|
|
200
291
|
return new AVLTreeNode<K, V>(key, this._isMapMode ? undefined : value) as AVLTreeNode<K, V>;
|
|
201
292
|
}
|
|
202
293
|
|
|
@@ -327,7 +418,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
327
418
|
*/
|
|
328
419
|
protected override _createInstance<TK = K, TV = V, TR = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this {
|
|
329
420
|
const Ctor = this.constructor as unknown as new (
|
|
330
|
-
iter?: Iterable<TK |
|
|
421
|
+
iter?: Iterable<TK | AVLTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>,
|
|
331
422
|
opts?: BSTOptions<TK, TV, TR>
|
|
332
423
|
) => this;
|
|
333
424
|
return new Ctor([], { ...this._snapshotOptions<TK, TV, TR>(), ...(options ?? {}) }) as unknown as this;
|
|
@@ -343,11 +434,11 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
343
434
|
* @returns A new AVLTree.
|
|
344
435
|
*/
|
|
345
436
|
protected override _createLike<TK = K, TV = V, TR = R>(
|
|
346
|
-
iter: Iterable<TK |
|
|
437
|
+
iter: Iterable<TK | AVLTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR> = [],
|
|
347
438
|
options?: Partial<BSTOptions<TK, TV, TR>>
|
|
348
439
|
): AVLTree<TK, TV, TR> {
|
|
349
440
|
const Ctor = this.constructor as unknown as new (
|
|
350
|
-
iter?: Iterable<TK |
|
|
441
|
+
iter?: Iterable<TK | AVLTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>,
|
|
351
442
|
opts?: BSTOptions<TK, TV, TR>
|
|
352
443
|
) => AVLTree<TK, TV, TR>;
|
|
353
444
|
return new Ctor(iter, { ...this._snapshotOptions<TK, TV, TR>(), ...(options ?? {}) });
|
|
@@ -370,7 +461,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
370
461
|
|
|
371
462
|
if (srcNodeEnsured && destNodeEnsured) {
|
|
372
463
|
const { key, value, height } = destNodeEnsured;
|
|
373
|
-
const tempNode = this.
|
|
464
|
+
const tempNode = this.createNode(key, value);
|
|
374
465
|
|
|
375
466
|
if (tempNode) {
|
|
376
467
|
tempNode.height = height;
|
|
@@ -390,7 +390,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
390
390
|
* @param [value] - The value for the new node (used if not in Map mode).
|
|
391
391
|
* @returns The newly created node.
|
|
392
392
|
*/
|
|
393
|
-
|
|
393
|
+
createNode(key: K, value?: V): BinaryTreeNode<K, V> {
|
|
394
394
|
return new BinaryTreeNode<K, V>(key, this._isMapMode ? undefined : value);
|
|
395
395
|
}
|
|
396
396
|
|
|
@@ -2019,10 +2019,10 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2019
2019
|
if (key === undefined) return [undefined, undefined];
|
|
2020
2020
|
else if (key === null) return [null, undefined];
|
|
2021
2021
|
const finalValue = value ?? entryValue;
|
|
2022
|
-
return [this.
|
|
2022
|
+
return [this.createNode(key, finalValue), finalValue];
|
|
2023
2023
|
}
|
|
2024
2024
|
|
|
2025
|
-
return [this.
|
|
2025
|
+
return [this.createNode(keyNodeOrEntry, value), value];
|
|
2026
2026
|
}
|
|
2027
2027
|
|
|
2028
2028
|
/**
|
|
@@ -2147,7 +2147,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2147
2147
|
|
|
2148
2148
|
if (srcNode && destNode) {
|
|
2149
2149
|
const { key, value } = destNode;
|
|
2150
|
-
const tempNode = this.
|
|
2150
|
+
const tempNode = this.createNode(key, value); // Use a temp node to hold dest properties
|
|
2151
2151
|
|
|
2152
2152
|
if (tempNode) {
|
|
2153
2153
|
// Copy src to dest
|
|
@@ -16,12 +16,14 @@ import type {
|
|
|
16
16
|
CP,
|
|
17
17
|
DFSOrderPattern,
|
|
18
18
|
EntryCallback,
|
|
19
|
+
FamilyPosition,
|
|
19
20
|
IterationType,
|
|
20
21
|
NodeCallback,
|
|
21
22
|
NodePredicate,
|
|
22
|
-
OptNode
|
|
23
|
+
OptNode,
|
|
24
|
+
RBTNColor
|
|
23
25
|
} from '../../types';
|
|
24
|
-
import { BinaryTree
|
|
26
|
+
import { BinaryTree } from './binary-tree';
|
|
25
27
|
import { IBinaryTree } from '../../interfaces';
|
|
26
28
|
import { Queue } from '../queue';
|
|
27
29
|
import { isComparable } from '../../utils';
|
|
@@ -33,8 +35,10 @@ import { Range } from '../../common';
|
|
|
33
35
|
* @template K - The type of the key.
|
|
34
36
|
* @template V - The type of the value.
|
|
35
37
|
*/
|
|
36
|
-
export class BSTNode<K = any, V = any>
|
|
37
|
-
|
|
38
|
+
export class BSTNode<K = any, V = any> {
|
|
39
|
+
key: K;
|
|
40
|
+
value?: V;
|
|
41
|
+
parent?: BSTNode<K, V> = undefined;
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Creates an instance of BSTNode.
|
|
@@ -44,10 +48,11 @@ export class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
44
48
|
* @param [value] - The value associated with the key.
|
|
45
49
|
*/
|
|
46
50
|
constructor(key: K, value?: V) {
|
|
47
|
-
|
|
51
|
+
this.key = key;
|
|
52
|
+
this.value = value;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
_left?: BSTNode<K, V> | null | undefined = undefined;
|
|
51
56
|
|
|
52
57
|
/**
|
|
53
58
|
* Gets the left child of the node.
|
|
@@ -55,7 +60,7 @@ export class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
55
60
|
*
|
|
56
61
|
* @returns The left child.
|
|
57
62
|
*/
|
|
58
|
-
|
|
63
|
+
get left(): BSTNode<K, V> | null | undefined {
|
|
59
64
|
return this._left;
|
|
60
65
|
}
|
|
61
66
|
|
|
@@ -65,12 +70,12 @@ export class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
65
70
|
*
|
|
66
71
|
* @param v - The node to set as the left child.
|
|
67
72
|
*/
|
|
68
|
-
|
|
73
|
+
set left(v: BSTNode<K, V> | null | undefined) {
|
|
69
74
|
if (v) v.parent = this;
|
|
70
75
|
this._left = v;
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
|
|
78
|
+
_right?: BSTNode<K, V> | null | undefined = undefined;
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
81
|
* Gets the right child of the node.
|
|
@@ -78,7 +83,7 @@ export class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
78
83
|
*
|
|
79
84
|
* @returns The right child.
|
|
80
85
|
*/
|
|
81
|
-
|
|
86
|
+
get right(): BSTNode<K, V> | null | undefined {
|
|
82
87
|
return this._right;
|
|
83
88
|
}
|
|
84
89
|
|
|
@@ -88,10 +93,96 @@ export class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
88
93
|
*
|
|
89
94
|
* @param v - The node to set as the right child.
|
|
90
95
|
*/
|
|
91
|
-
|
|
96
|
+
set right(v: BSTNode<K, V> | null | undefined) {
|
|
92
97
|
if (v) v.parent = this;
|
|
93
98
|
this._right = v;
|
|
94
99
|
}
|
|
100
|
+
|
|
101
|
+
_height: number = 0;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
105
|
+
* @remarks Time O(1), Space O(1)
|
|
106
|
+
*
|
|
107
|
+
* @returns The height.
|
|
108
|
+
*/
|
|
109
|
+
get height(): number {
|
|
110
|
+
return this._height;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Sets the height of the node.
|
|
115
|
+
* @remarks Time O(1), Space O(1)
|
|
116
|
+
*
|
|
117
|
+
* @param value - The new height.
|
|
118
|
+
*/
|
|
119
|
+
set height(value: number) {
|
|
120
|
+
this._height = value;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
_color: RBTNColor = 'BLACK';
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
127
|
+
* @remarks Time O(1), Space O(1)
|
|
128
|
+
*
|
|
129
|
+
* @returns The node's color.
|
|
130
|
+
*/
|
|
131
|
+
get color(): RBTNColor {
|
|
132
|
+
return this._color;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Sets the color of the node.
|
|
137
|
+
* @remarks Time O(1), Space O(1)
|
|
138
|
+
*
|
|
139
|
+
* @param value - The new color.
|
|
140
|
+
*/
|
|
141
|
+
set color(value: RBTNColor) {
|
|
142
|
+
this._color = value;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
_count: number = 1;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
149
|
+
* @remarks Time O(1), Space O(1)
|
|
150
|
+
*
|
|
151
|
+
* @returns The subtree node count.
|
|
152
|
+
*/
|
|
153
|
+
get count(): number {
|
|
154
|
+
return this._count;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Sets the count of nodes in the subtree.
|
|
159
|
+
* @remarks Time O(1), Space O(1)
|
|
160
|
+
*
|
|
161
|
+
* @param value - The new count.
|
|
162
|
+
*/
|
|
163
|
+
set count(value: number) {
|
|
164
|
+
this._count = value;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Gets the position of the node relative to its parent.
|
|
169
|
+
* @remarks Time O(1), Space O(1)
|
|
170
|
+
*
|
|
171
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
172
|
+
*/
|
|
173
|
+
get familyPosition(): FamilyPosition {
|
|
174
|
+
if (!this.parent) {
|
|
175
|
+
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (this.parent.left === this) {
|
|
179
|
+
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
180
|
+
} else if (this.parent.right === this) {
|
|
181
|
+
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return 'MAL_NODE';
|
|
185
|
+
}
|
|
95
186
|
}
|
|
96
187
|
|
|
97
188
|
/**
|
|
@@ -268,7 +359,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
268
359
|
* @param [value] - The value for the new node (used if not in Map mode).
|
|
269
360
|
* @returns The newly created BSTNode.
|
|
270
361
|
*/
|
|
271
|
-
override
|
|
362
|
+
override createNode(key: K, value?: V): BSTNode<K, V> {
|
|
272
363
|
return new BSTNode<K, V>(key, this._isMapMode ? undefined : value);
|
|
273
364
|
}
|
|
274
365
|
|