graph-typed 1.39.6 → 1.41.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/data-structures/binary-tree/avl-tree.js +0 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -11
- package/dist/data-structures/binary-tree/binary-tree.d.ts +13 -20
- package/dist/data-structures/binary-tree/binary-tree.js +30 -31
- package/dist/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/data-structures/binary-tree/bst.js +4 -4
- package/dist/data-structures/binary-tree/rb-tree.d.ts +95 -11
- package/dist/data-structures/binary-tree/rb-tree.js +379 -18
- package/dist/data-structures/binary-tree/segment-tree.d.ts +10 -26
- package/dist/data-structures/binary-tree/segment-tree.js +10 -58
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +6 -6
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -24
- package/dist/data-structures/graph/abstract-graph.js +4 -43
- package/dist/data-structures/graph/directed-graph.d.ts +4 -10
- package/dist/data-structures/graph/directed-graph.js +2 -20
- package/dist/data-structures/graph/map-graph.d.ts +4 -10
- package/dist/data-structures/graph/map-graph.js +2 -20
- package/dist/data-structures/graph/undirected-graph.d.ts +1 -8
- package/dist/data-structures/graph/undirected-graph.js +1 -14
- package/dist/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/data-structures/hash/coordinate-map.js +0 -3
- package/dist/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/data-structures/hash/coordinate-set.js +0 -3
- package/dist/data-structures/hash/hash-map.d.ts +8 -14
- package/dist/data-structures/hash/hash-map.js +4 -22
- package/dist/data-structures/hash/hash-table.d.ts +6 -9
- package/dist/data-structures/hash/hash-table.js +0 -9
- package/dist/data-structures/heap/heap.d.ts +12 -6
- package/dist/data-structures/heap/heap.js +40 -22
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
- package/dist/data-structures/linked-list/doubly-linked-list.js +18 -42
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -11
- package/dist/data-structures/linked-list/singly-linked-list.js +17 -35
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +29 -10
- package/dist/data-structures/linked-list/skip-linked-list.js +62 -17
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +4 -4
- package/dist/data-structures/queue/deque.d.ts +8 -12
- package/dist/data-structures/queue/deque.js +31 -43
- package/dist/data-structures/queue/queue.d.ts +20 -5
- package/dist/data-structures/queue/queue.js +35 -18
- package/dist/data-structures/stack/stack.d.ts +2 -1
- package/dist/data-structures/stack/stack.js +10 -7
- package/dist/data-structures/tree/tree.d.ts +3 -9
- package/dist/data-structures/tree/tree.js +3 -21
- package/dist/data-structures/trie/trie.d.ts +6 -12
- package/dist/data-structures/trie/trie.js +6 -24
- package/dist/interfaces/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -7
- package/dist/types/data-structures/binary-tree/rb-tree.js +11 -6
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +2 -4
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
- package/src/data-structures/binary-tree/binary-tree.ts +40 -43
- package/src/data-structures/binary-tree/bst.ts +9 -10
- package/src/data-structures/binary-tree/rb-tree.ts +415 -355
- package/src/data-structures/binary-tree/segment-tree.ts +16 -83
- package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
- package/src/data-structures/graph/abstract-graph.ts +21 -67
- package/src/data-structures/graph/directed-graph.ts +13 -39
- package/src/data-structures/graph/map-graph.ts +7 -32
- package/src/data-structures/graph/undirected-graph.ts +9 -26
- package/src/data-structures/hash/coordinate-map.ts +0 -4
- package/src/data-structures/hash/coordinate-set.ts +0 -4
- package/src/data-structures/hash/hash-map.ts +13 -37
- package/src/data-structures/hash/hash-table.ts +6 -18
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +58 -30
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
- package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
- package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +38 -53
- package/src/data-structures/queue/queue.ts +38 -20
- package/src/data-structures/stack/stack.ts +13 -9
- package/src/data-structures/tree/tree.ts +7 -33
- package/src/data-structures/trie/trie.ts +14 -40
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
|
@@ -48,7 +48,6 @@ class AVLTree extends bst_1.BST {
|
|
|
48
48
|
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
49
49
|
*/
|
|
50
50
|
add(keyOrNode, value) {
|
|
51
|
-
// TODO support node as a param
|
|
52
51
|
const inserted = super.add(keyOrNode, value);
|
|
53
52
|
if (inserted)
|
|
54
53
|
this._balancePath(inserted);
|
|
@@ -13,13 +13,10 @@ export declare class BinaryIndexedTree {
|
|
|
13
13
|
});
|
|
14
14
|
protected _freqMap: Record<number, number>;
|
|
15
15
|
get freqMap(): Record<number, number>;
|
|
16
|
-
set freqMap(value: Record<number, number>);
|
|
17
16
|
protected _msb: number;
|
|
18
17
|
get msb(): number;
|
|
19
|
-
set msb(value: number);
|
|
20
18
|
protected _negativeCount: number;
|
|
21
19
|
get negativeCount(): number;
|
|
22
|
-
set negativeCount(value: number);
|
|
23
20
|
get freq(): number;
|
|
24
21
|
get max(): number;
|
|
25
22
|
/**
|
|
@@ -26,21 +26,12 @@ class BinaryIndexedTree {
|
|
|
26
26
|
get freqMap() {
|
|
27
27
|
return this._freqMap;
|
|
28
28
|
}
|
|
29
|
-
set freqMap(value) {
|
|
30
|
-
this._freqMap = value;
|
|
31
|
-
}
|
|
32
29
|
get msb() {
|
|
33
30
|
return this._msb;
|
|
34
31
|
}
|
|
35
|
-
set msb(value) {
|
|
36
|
-
this._msb = value;
|
|
37
|
-
}
|
|
38
32
|
get negativeCount() {
|
|
39
33
|
return this._negativeCount;
|
|
40
34
|
}
|
|
41
|
-
set negativeCount(value) {
|
|
42
|
-
this._negativeCount = value;
|
|
43
|
-
}
|
|
44
35
|
get freq() {
|
|
45
36
|
return this._freq;
|
|
46
37
|
}
|
|
@@ -198,10 +189,10 @@ class BinaryIndexedTree {
|
|
|
198
189
|
*/
|
|
199
190
|
_updateNegativeCount(freqCur, freqNew) {
|
|
200
191
|
if (freqCur < 0 && freqNew >= 0) {
|
|
201
|
-
this.
|
|
192
|
+
this._negativeCount--;
|
|
202
193
|
}
|
|
203
194
|
else if (freqCur >= 0 && freqNew < 0) {
|
|
204
|
-
this.
|
|
195
|
+
this._negativeCount++;
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
198
|
/**
|
|
@@ -32,7 +32,7 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
32
32
|
* @param {V} value - The value stored in the node.
|
|
33
33
|
*/
|
|
34
34
|
constructor(key: BTNKey, value?: V);
|
|
35
|
-
|
|
35
|
+
protected _left: N | null | undefined;
|
|
36
36
|
/**
|
|
37
37
|
* Get the left child node.
|
|
38
38
|
*/
|
|
@@ -42,7 +42,7 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
42
42
|
* @param {N | null | undefined} v - The left child node.
|
|
43
43
|
*/
|
|
44
44
|
set left(v: N | null | undefined);
|
|
45
|
-
|
|
45
|
+
protected _right: N | null | undefined;
|
|
46
46
|
/**
|
|
47
47
|
* Get the right child node.
|
|
48
48
|
*/
|
|
@@ -63,27 +63,18 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
63
63
|
* @template N - The type of the binary tree's nodes.
|
|
64
64
|
*/
|
|
65
65
|
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> implements IBinaryTree<V, N> {
|
|
66
|
+
iterationType: IterationType;
|
|
66
67
|
/**
|
|
67
68
|
* Creates a new instance of BinaryTree.
|
|
68
69
|
* @param {BinaryTreeOptions} [options] - The options for the binary tree.
|
|
69
70
|
*/
|
|
70
71
|
constructor(options?: BinaryTreeOptions);
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Get the iteration type used in the binary tree.
|
|
74
|
-
*/
|
|
75
|
-
get iterationType(): IterationType;
|
|
76
|
-
/**
|
|
77
|
-
* Set the iteration type for the binary tree.
|
|
78
|
-
* @param {IterationType} v - The new iteration type to set.
|
|
79
|
-
*/
|
|
80
|
-
set iterationType(v: IterationType);
|
|
81
|
-
private _root;
|
|
72
|
+
protected _root: N | null;
|
|
82
73
|
/**
|
|
83
74
|
* Get the root node of the binary tree.
|
|
84
75
|
*/
|
|
85
76
|
get root(): N | null;
|
|
86
|
-
|
|
77
|
+
protected _size: number;
|
|
87
78
|
/**
|
|
88
79
|
* Get the number of nodes in the binary tree.
|
|
89
80
|
*/
|
|
@@ -310,6 +301,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
310
301
|
* @returns The function `getPredecessor` returns the predecessor node of the given node `node`.
|
|
311
302
|
*/
|
|
312
303
|
getPredecessor(node: N): N;
|
|
304
|
+
/**
|
|
305
|
+
* The function `getSuccessor` returns the next node in a binary tree given a node `x`, or `null` if
|
|
306
|
+
* `x` is the last node.
|
|
307
|
+
* @param {N} x - N - a node in a binary tree
|
|
308
|
+
* @returns The function `getSuccessor` returns a value of type `N` (the successor node), or `null`
|
|
309
|
+
* if there is no successor, or `undefined` if the input `x` is `undefined`.
|
|
310
|
+
*/
|
|
311
|
+
getSuccessor(x: N): N | null | undefined;
|
|
313
312
|
/**
|
|
314
313
|
* The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
|
|
315
314
|
* algorithm and returns an array of values obtained by applying a callback function to each node.
|
|
@@ -361,10 +360,4 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
361
360
|
* type `N` or `null`.
|
|
362
361
|
*/
|
|
363
362
|
protected _setRoot(v: N | null): void;
|
|
364
|
-
/**
|
|
365
|
-
* The function sets the value of the protected property "_size" to the given number.
|
|
366
|
-
* @param {number} v - The parameter "v" is a number that represents the size value that we want to
|
|
367
|
-
* set.
|
|
368
|
-
*/
|
|
369
|
-
protected _setSize(v: number): void;
|
|
370
363
|
}
|
|
@@ -87,27 +87,14 @@ class BinaryTree {
|
|
|
87
87
|
* @param {BinaryTreeOptions} [options] - The options for the binary tree.
|
|
88
88
|
*/
|
|
89
89
|
constructor(options) {
|
|
90
|
-
this.
|
|
90
|
+
this.iterationType = types_1.IterationType.ITERATIVE;
|
|
91
91
|
this._root = null;
|
|
92
92
|
this._size = 0;
|
|
93
93
|
if (options !== undefined) {
|
|
94
94
|
const { iterationType = types_1.IterationType.ITERATIVE } = options;
|
|
95
|
-
this.
|
|
95
|
+
this.iterationType = iterationType;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Get the iteration type used in the binary tree.
|
|
100
|
-
*/
|
|
101
|
-
get iterationType() {
|
|
102
|
-
return this._iterationType;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Set the iteration type for the binary tree.
|
|
106
|
-
* @param {IterationType} v - The new iteration type to set.
|
|
107
|
-
*/
|
|
108
|
-
set iterationType(v) {
|
|
109
|
-
this._iterationType = v;
|
|
110
|
-
}
|
|
111
98
|
/**
|
|
112
99
|
* Get the root node of the binary tree.
|
|
113
100
|
*/
|
|
@@ -133,7 +120,7 @@ class BinaryTree {
|
|
|
133
120
|
* Clear the binary tree, removing all nodes.
|
|
134
121
|
*/
|
|
135
122
|
clear() {
|
|
136
|
-
this.
|
|
123
|
+
this._setRoot(null);
|
|
137
124
|
this._size = 0;
|
|
138
125
|
}
|
|
139
126
|
/**
|
|
@@ -197,10 +184,10 @@ class BinaryTree {
|
|
|
197
184
|
else {
|
|
198
185
|
this._setRoot(needInsert);
|
|
199
186
|
if (needInsert !== null) {
|
|
200
|
-
this.
|
|
187
|
+
this._size = 1;
|
|
201
188
|
}
|
|
202
189
|
else {
|
|
203
|
-
this.
|
|
190
|
+
this._size = 0;
|
|
204
191
|
}
|
|
205
192
|
inserted = this.root;
|
|
206
193
|
}
|
|
@@ -297,7 +284,7 @@ class BinaryTree {
|
|
|
297
284
|
}
|
|
298
285
|
}
|
|
299
286
|
}
|
|
300
|
-
this.
|
|
287
|
+
this._size = this.size - 1;
|
|
301
288
|
bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
302
289
|
return bstDeletedResult;
|
|
303
290
|
}
|
|
@@ -826,7 +813,7 @@ class BinaryTree {
|
|
|
826
813
|
const ans = [];
|
|
827
814
|
if (iterationType === types_1.IterationType.RECURSIVE) {
|
|
828
815
|
const queue = new queue_1.Queue([beginRoot]);
|
|
829
|
-
|
|
816
|
+
const traverse = (level) => {
|
|
830
817
|
if (queue.size === 0)
|
|
831
818
|
return;
|
|
832
819
|
const current = queue.shift();
|
|
@@ -836,7 +823,7 @@ class BinaryTree {
|
|
|
836
823
|
if (current.right)
|
|
837
824
|
queue.push(current.right);
|
|
838
825
|
traverse(level + 1);
|
|
839
|
-
}
|
|
826
|
+
};
|
|
840
827
|
traverse(0);
|
|
841
828
|
}
|
|
842
829
|
else {
|
|
@@ -921,6 +908,24 @@ class BinaryTree {
|
|
|
921
908
|
return node;
|
|
922
909
|
}
|
|
923
910
|
}
|
|
911
|
+
/**
|
|
912
|
+
* The function `getSuccessor` returns the next node in a binary tree given a node `x`, or `null` if
|
|
913
|
+
* `x` is the last node.
|
|
914
|
+
* @param {N} x - N - a node in a binary tree
|
|
915
|
+
* @returns The function `getSuccessor` returns a value of type `N` (the successor node), or `null`
|
|
916
|
+
* if there is no successor, or `undefined` if the input `x` is `undefined`.
|
|
917
|
+
*/
|
|
918
|
+
getSuccessor(x) {
|
|
919
|
+
if (x.right) {
|
|
920
|
+
return this.getLeftMost(x.right);
|
|
921
|
+
}
|
|
922
|
+
let y = x.parent;
|
|
923
|
+
while (y && y && x === y.right) {
|
|
924
|
+
x = y;
|
|
925
|
+
y = y.parent;
|
|
926
|
+
}
|
|
927
|
+
return y;
|
|
928
|
+
}
|
|
924
929
|
// --- start additional methods ---
|
|
925
930
|
/**
|
|
926
931
|
* The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
|
|
@@ -1050,10 +1055,12 @@ class BinaryTree {
|
|
|
1050
1055
|
}
|
|
1051
1056
|
else {
|
|
1052
1057
|
if (node.left) {
|
|
1058
|
+
// @ts-ignore
|
|
1053
1059
|
yield* this[Symbol.iterator](node.left);
|
|
1054
1060
|
}
|
|
1055
1061
|
yield node.key;
|
|
1056
1062
|
if (node.right) {
|
|
1063
|
+
// @ts-ignore
|
|
1057
1064
|
yield* this[Symbol.iterator](node.right);
|
|
1058
1065
|
}
|
|
1059
1066
|
}
|
|
@@ -1093,14 +1100,14 @@ class BinaryTree {
|
|
|
1093
1100
|
if (parent.left === undefined) {
|
|
1094
1101
|
parent.left = newNode;
|
|
1095
1102
|
if (newNode) {
|
|
1096
|
-
this.
|
|
1103
|
+
this._size = this.size + 1;
|
|
1097
1104
|
}
|
|
1098
1105
|
return parent.left;
|
|
1099
1106
|
}
|
|
1100
1107
|
else if (parent.right === undefined) {
|
|
1101
1108
|
parent.right = newNode;
|
|
1102
1109
|
if (newNode) {
|
|
1103
|
-
this.
|
|
1110
|
+
this._size = this.size + 1;
|
|
1104
1111
|
}
|
|
1105
1112
|
return parent.right;
|
|
1106
1113
|
}
|
|
@@ -1124,13 +1131,5 @@ class BinaryTree {
|
|
|
1124
1131
|
}
|
|
1125
1132
|
this._root = v;
|
|
1126
1133
|
}
|
|
1127
|
-
/**
|
|
1128
|
-
* The function sets the value of the protected property "_size" to the given number.
|
|
1129
|
-
* @param {number} v - The parameter "v" is a number that represents the size value that we want to
|
|
1130
|
-
* set.
|
|
1131
|
-
*/
|
|
1132
|
-
_setSize(v) {
|
|
1133
|
-
this._size = v;
|
|
1134
|
-
}
|
|
1135
1134
|
}
|
|
1136
1135
|
exports.BinaryTree = BinaryTree;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { BSTComparator, BSTNodeNested, BSTOptions, BTNCallback, BTNKey } from '../../types';
|
|
9
9
|
import { CP, IterationType } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -43,7 +43,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
|
|
|
43
43
|
/**
|
|
44
44
|
* The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
|
|
45
45
|
* maintaining balance.
|
|
46
|
-
* @param {[BTNKey | N,
|
|
46
|
+
* @param {[BTNKey | N, V][]} keysOrNodes - The `arr` parameter in the `addMany` function
|
|
47
47
|
* represents an array of keys or nodes that need to be added to the binary search tree. It can be an
|
|
48
48
|
* array of `BTNKey` or `N` (which represents the node type in the binary search tree) or
|
|
49
49
|
* `null
|
|
@@ -63,7 +63,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
63
63
|
}
|
|
64
64
|
if (this.root === null) {
|
|
65
65
|
this._setRoot(newNode);
|
|
66
|
-
this.
|
|
66
|
+
this._size = this.size + 1;
|
|
67
67
|
inserted = this.root;
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
@@ -87,7 +87,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
87
87
|
}
|
|
88
88
|
//Add to the left of the current node
|
|
89
89
|
cur.left = newNode;
|
|
90
|
-
this.
|
|
90
|
+
this._size = this.size + 1;
|
|
91
91
|
traversing = false;
|
|
92
92
|
inserted = cur.left;
|
|
93
93
|
}
|
|
@@ -105,7 +105,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
105
105
|
}
|
|
106
106
|
//Add to the right of the current node
|
|
107
107
|
cur.right = newNode;
|
|
108
|
-
this.
|
|
108
|
+
this._size = this.size + 1;
|
|
109
109
|
traversing = false;
|
|
110
110
|
inserted = cur.right;
|
|
111
111
|
}
|
|
@@ -126,7 +126,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
126
126
|
/**
|
|
127
127
|
* The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
|
|
128
128
|
* maintaining balance.
|
|
129
|
-
* @param {[BTNKey | N,
|
|
129
|
+
* @param {[BTNKey | N, V][]} keysOrNodes - The `arr` parameter in the `addMany` function
|
|
130
130
|
* represents an array of keys or nodes that need to be added to the binary search tree. It can be an
|
|
131
131
|
* array of `BTNKey` or `N` (which represents the node type in the binary search tree) or
|
|
132
132
|
* `null
|
|
@@ -1,13 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
set color(value: RBColor);
|
|
1
|
+
export declare class RBTreeNode {
|
|
2
|
+
key: number;
|
|
3
|
+
parent: RBTreeNode;
|
|
4
|
+
left: RBTreeNode;
|
|
5
|
+
right: RBTreeNode;
|
|
6
|
+
color: number;
|
|
7
|
+
constructor();
|
|
9
8
|
}
|
|
10
|
-
export declare class
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
9
|
+
export declare class RedBlackTree {
|
|
10
|
+
constructor();
|
|
11
|
+
protected _root: RBTreeNode;
|
|
12
|
+
get root(): RBTreeNode;
|
|
13
|
+
protected _NIL: RBTreeNode;
|
|
14
|
+
get NIL(): RBTreeNode;
|
|
15
|
+
/**
|
|
16
|
+
* The `insert` function inserts a new node with a given key into a red-black tree and fixes any
|
|
17
|
+
* violations of the red-black tree properties.
|
|
18
|
+
* @param {number} key - The key parameter is a number that represents the value to be inserted into
|
|
19
|
+
* the RBTree.
|
|
20
|
+
* @returns The function does not explicitly return anything.
|
|
21
|
+
*/
|
|
22
|
+
insert(key: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* The `delete` function in TypeScript is used to remove a node with a specific key from a red-black
|
|
25
|
+
* tree.
|
|
26
|
+
* @param {RBTreeNode} node - The `node` parameter is of type `RBTreeNode` and represents the current
|
|
27
|
+
* node being processed in the delete operation.
|
|
28
|
+
* @returns The `delete` function does not return anything. It has a return type of `void`.
|
|
29
|
+
*/
|
|
30
|
+
delete(key: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* The function `getNode` is a recursive depth-first search algorithm that searches for a node with a
|
|
33
|
+
* given key in a red-black tree.
|
|
34
|
+
* @param {number} key - The key parameter is a number that represents the value we are searching for
|
|
35
|
+
* in the RBTree.
|
|
36
|
+
* @param beginRoot - The `beginRoot` parameter is an optional parameter that represents the starting
|
|
37
|
+
* point for the search in the binary search tree. If no value is provided for `beginRoot`, it
|
|
38
|
+
* defaults to the root of the binary search tree (`this.root`).
|
|
39
|
+
* @returns a RBTreeNode.
|
|
40
|
+
*/
|
|
41
|
+
getNode(key: number, beginRoot?: RBTreeNode): RBTreeNode;
|
|
42
|
+
/**
|
|
43
|
+
* The function returns the leftmost node in a red-black tree.
|
|
44
|
+
* @param {RBTreeNode} node - The parameter "node" is of type RBTreeNode, which represents a node in
|
|
45
|
+
* a Red-Black Tree.
|
|
46
|
+
* @returns The leftmost node in the given RBTreeNode.
|
|
47
|
+
*/
|
|
48
|
+
getLeftMost(node: RBTreeNode): RBTreeNode;
|
|
49
|
+
/**
|
|
50
|
+
* The function returns the rightmost node in a red-black tree.
|
|
51
|
+
* @param {RBTreeNode} node - The parameter "node" is of type RBTreeNode.
|
|
52
|
+
* @returns the rightmost node in a red-black tree.
|
|
53
|
+
*/
|
|
54
|
+
getRightMost(node: RBTreeNode): RBTreeNode;
|
|
55
|
+
/**
|
|
56
|
+
* The function returns the successor of a given node in a red-black tree.
|
|
57
|
+
* @param {RBTreeNode} x - RBTreeNode - The node for which we want to find the successor.
|
|
58
|
+
* @returns the successor of the given RBTreeNode.
|
|
59
|
+
*/
|
|
60
|
+
getSuccessor(x: RBTreeNode): RBTreeNode;
|
|
61
|
+
/**
|
|
62
|
+
* The function returns the predecessor of a given node in a red-black tree.
|
|
63
|
+
* @param {RBTreeNode} x - The parameter `x` is of type `RBTreeNode`, which represents a node in a
|
|
64
|
+
* Red-Black Tree.
|
|
65
|
+
* @returns the predecessor of the given RBTreeNode 'x'.
|
|
66
|
+
*/
|
|
67
|
+
getPredecessor(x: RBTreeNode): RBTreeNode;
|
|
68
|
+
/**
|
|
69
|
+
* The function performs a left rotation on a red-black tree node.
|
|
70
|
+
* @param {RBTreeNode} x - The parameter `x` is a RBTreeNode object.
|
|
71
|
+
*/
|
|
72
|
+
protected _leftRotate(x: RBTreeNode): void;
|
|
73
|
+
/**
|
|
74
|
+
* The function performs a right rotation on a red-black tree node.
|
|
75
|
+
* @param {RBTreeNode} x - x is a RBTreeNode, which represents the node that needs to be right
|
|
76
|
+
* rotated.
|
|
77
|
+
*/
|
|
78
|
+
protected _rightRotate(x: RBTreeNode): void;
|
|
79
|
+
/**
|
|
80
|
+
* The _fixDelete function is used to rebalance the Red-Black Tree after a node deletion.
|
|
81
|
+
* @param {RBTreeNode} x - The parameter `x` is of type `RBTreeNode`, which represents a node in a
|
|
82
|
+
* red-black tree.
|
|
83
|
+
*/
|
|
84
|
+
protected _fixDelete(x: RBTreeNode): void;
|
|
85
|
+
/**
|
|
86
|
+
* The function `_rbTransplant` replaces one node in a red-black tree with another node.
|
|
87
|
+
* @param {RBTreeNode} u - The parameter "u" represents a RBTreeNode object.
|
|
88
|
+
* @param {RBTreeNode} v - The parameter "v" is a RBTreeNode object.
|
|
89
|
+
*/
|
|
90
|
+
protected _rbTransplant(u: RBTreeNode, v: RBTreeNode): void;
|
|
91
|
+
/**
|
|
92
|
+
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
|
|
93
|
+
* @param {RBTreeNode} k - The parameter `k` is a RBTreeNode object, which represents a node in a
|
|
94
|
+
* red-black tree.
|
|
95
|
+
*/
|
|
96
|
+
protected _fixInsert(k: RBTreeNode): void;
|
|
13
97
|
}
|