red-black-tree-typed 1.53.6 → 1.54.1
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/README.md +52 -0
- package/dist/common/index.d.ts +12 -0
- package/dist/common/index.js +28 -0
- package/dist/data-structures/base/iterable-entry-base.js +4 -4
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -331
- package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
- package/dist/data-structures/binary-tree/avl-tree.js +131 -71
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +309 -208
- package/dist/data-structures/binary-tree/binary-tree.js +382 -300
- package/dist/data-structures/binary-tree/bst.d.ts +245 -127
- package/dist/data-structures/binary-tree/bst.js +366 -163
- package/dist/data-structures/binary-tree/index.d.ts +3 -1
- package/dist/data-structures/binary-tree/index.js +3 -1
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
- package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +181 -108
- package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/data-structures/binary-tree/tree-counter.js +444 -0
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
- package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/data-structures/graph/directed-graph.js +3 -0
- package/dist/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/data-structures/graph/map-graph.js +3 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/data-structures/graph/undirected-graph.js +3 -0
- package/dist/data-structures/hash/hash-map.d.ts +31 -1
- package/dist/data-structures/hash/hash-map.js +35 -5
- package/dist/data-structures/heap/heap.d.ts +26 -9
- package/dist/data-structures/heap/heap.js +37 -17
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +64 -19
- package/dist/data-structures/linked-list/doubly-linked-list.js +92 -31
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +48 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +74 -27
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/data-structures/matrix/matrix.js +3 -0
- package/dist/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/data-structures/matrix/navigator.js +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/data-structures/queue/deque.d.ts +37 -8
- package/dist/data-structures/queue/deque.js +73 -29
- package/dist/data-structures/queue/queue.d.ts +41 -1
- package/dist/data-structures/queue/queue.js +51 -9
- package/dist/data-structures/stack/stack.d.ts +27 -10
- package/dist/data-structures/stack/stack.js +39 -20
- package/dist/data-structures/trie/trie.d.ts +111 -10
- package/dist/data-structures/trie/trie.js +123 -18
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/interfaces/binary-tree.d.ts +8 -8
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/index.js +2 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
- package/dist/types/utils/utils.d.ts +10 -6
- package/dist/utils/utils.js +4 -2
- package/package.json +2 -2
- package/src/common/index.ts +25 -0
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +152 -373
- package/src/data-structures/binary-tree/avl-tree.ts +164 -106
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +563 -447
- package/src/data-structures/binary-tree/bst.ts +433 -237
- package/src/data-structures/binary-tree/index.ts +3 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +224 -146
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/hash/hash-map.ts +37 -7
- package/src/data-structures/heap/heap.ts +72 -49
- package/src/data-structures/linked-list/doubly-linked-list.ts +186 -118
- package/src/data-structures/linked-list/singly-linked-list.ts +81 -28
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +123 -17
- package/src/index.ts +4 -3
- package/src/interfaces/binary-tree.ts +10 -21
- package/src/types/data-structures/base/base.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -6
- package/src/types/data-structures/binary-tree/bst.ts +8 -7
- package/src/types/data-structures/binary-tree/index.ts +3 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
- package/src/types/utils/utils.ts +16 -10
- package/src/utils/utils.ts +4 -2
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -205
- package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
|
@@ -3,6 +3,8 @@ export * from './bst';
|
|
|
3
3
|
export * from './binary-indexed-tree';
|
|
4
4
|
export * from './segment-tree';
|
|
5
5
|
export * from './avl-tree';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './red-black-tree';
|
|
7
7
|
export * from './avl-tree-multi-map';
|
|
8
8
|
export * from './tree-multi-map';
|
|
9
|
+
export * from './tree-counter';
|
|
10
|
+
export * from './avl-tree-counter';
|
|
@@ -19,6 +19,8 @@ __exportStar(require("./bst"), exports);
|
|
|
19
19
|
__exportStar(require("./binary-indexed-tree"), exports);
|
|
20
20
|
__exportStar(require("./segment-tree"), exports);
|
|
21
21
|
__exportStar(require("./avl-tree"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./red-black-tree"), exports);
|
|
23
23
|
__exportStar(require("./avl-tree-multi-map"), exports);
|
|
24
24
|
__exportStar(require("./tree-multi-map"), exports);
|
|
25
|
+
__exportStar(require("./tree-counter"), exports);
|
|
26
|
+
__exportStar(require("./avl-tree-counter"), exports);
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { BinaryTreeDeleteResult, BTNRep, CRUD, EntryCallback, OptNodeOrNull, RBTNColor, RedBlackTreeOptions } from '../../types';
|
|
2
|
+
import { BST, BSTNode } from './bst';
|
|
3
|
+
import { IBinaryTree } from '../../interfaces';
|
|
4
|
+
export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor initializes a node with a key, value, and color for a Red-Black Tree.
|
|
7
|
+
* @param {K} key - The `key` parameter is a key of type `K` that is used to identify the node in a
|
|
8
|
+
* Red-Black Tree data structure.
|
|
9
|
+
* @param {V} [value] - The `value` parameter in the constructor is an optional parameter of type
|
|
10
|
+
* `V`. It represents the value associated with the key in the data structure being constructed.
|
|
11
|
+
* @param {RBTNColor} [color=BLACK] - The `color` parameter in the constructor is used to specify the
|
|
12
|
+
* color of the node in a Red-Black Tree. It has a default value of 'BLACK' if not provided
|
|
13
|
+
* explicitly.
|
|
14
|
+
*/
|
|
15
|
+
constructor(key: K, value?: V, color?: RBTNColor);
|
|
16
|
+
parent?: RedBlackTreeNode<K, V>;
|
|
17
|
+
_left?: OptNodeOrNull<RedBlackTreeNode<K, V>>;
|
|
18
|
+
get left(): OptNodeOrNull<RedBlackTreeNode<K, V>>;
|
|
19
|
+
set left(v: OptNodeOrNull<RedBlackTreeNode<K, V>>);
|
|
20
|
+
_right?: OptNodeOrNull<RedBlackTreeNode<K, V>>;
|
|
21
|
+
get right(): OptNodeOrNull<RedBlackTreeNode<K, V>>;
|
|
22
|
+
set right(v: OptNodeOrNull<RedBlackTreeNode<K, V>>);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high but the query efficiency is slightly lower.
|
|
26
|
+
* 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
|
|
27
|
+
* @example
|
|
28
|
+
* // Find elements in a range
|
|
29
|
+
* const bst = new RedBlackTree<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
30
|
+
* console.log(bst.search(new Range(5, 10))); // [5, 10, 7]
|
|
31
|
+
* console.log(bst.search(new Range(4, 12))); // [5, 10, 12, 7]
|
|
32
|
+
* console.log(bst.search(new Range(15, 20))); // [15, 18]
|
|
33
|
+
* @example
|
|
34
|
+
* // using Red-Black Tree as a price-based index for stock data
|
|
35
|
+
* // Define the structure of individual stock records
|
|
36
|
+
* interface StockRecord {
|
|
37
|
+
* price: number; // Stock price (key for indexing)
|
|
38
|
+
* symbol: string; // Stock ticker symbol
|
|
39
|
+
* volume: number; // Trade volume
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // Simulate stock market data as it might come from an external feed
|
|
43
|
+
* const marketStockData: StockRecord[] = [
|
|
44
|
+
* { price: 142.5, symbol: 'AAPL', volume: 1000000 },
|
|
45
|
+
* { price: 335.2, symbol: 'MSFT', volume: 800000 },
|
|
46
|
+
* { price: 3285.04, symbol: 'AMZN', volume: 500000 },
|
|
47
|
+
* { price: 267.98, symbol: 'META', volume: 750000 },
|
|
48
|
+
* { price: 234.57, symbol: 'GOOGL', volume: 900000 }
|
|
49
|
+
* ];
|
|
50
|
+
*
|
|
51
|
+
* // Extend the stock record type to include metadata for database usage
|
|
52
|
+
* type StockTableRecord = StockRecord & { lastUpdated: Date };
|
|
53
|
+
*
|
|
54
|
+
* // Create a Red-Black Tree to index stock records by price
|
|
55
|
+
* // Simulates a database index with stock price as the key for quick lookups
|
|
56
|
+
* const priceIndex = new RedBlackTree<number, StockTableRecord, StockRecord>(marketStockData, {
|
|
57
|
+
* toEntryFn: stockRecord => [
|
|
58
|
+
* stockRecord.price, // Use stock price as the key
|
|
59
|
+
* {
|
|
60
|
+
* ...stockRecord,
|
|
61
|
+
* lastUpdated: new Date() // Add a timestamp for when the record was indexed
|
|
62
|
+
* }
|
|
63
|
+
* ]
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Query the stock with the highest price
|
|
67
|
+
* const highestPricedStock = priceIndex.getRightMost();
|
|
68
|
+
* console.log(priceIndex.get(highestPricedStock)?.symbol); // 'AMZN' // Amazon has the highest price
|
|
69
|
+
*
|
|
70
|
+
* // Query stocks within a specific price range (200 to 400)
|
|
71
|
+
* const stocksInRange = priceIndex.rangeSearch(
|
|
72
|
+
* [200, 400], // Price range
|
|
73
|
+
* node => priceIndex.get(node)?.symbol // Extract stock symbols for the result
|
|
74
|
+
* );
|
|
75
|
+
* console.log(stocksInRange); // ['GOOGL', 'MSFT', 'META']
|
|
76
|
+
*/
|
|
77
|
+
export declare class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends BST<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
|
|
78
|
+
/**
|
|
79
|
+
* This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
|
|
80
|
+
* raw data.
|
|
81
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
82
|
+
* iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
|
|
83
|
+
* is used to initialize the Red-Black Tree with keys, nodes, entries, or
|
|
84
|
+
* @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
|
|
85
|
+
* V, R>`. It is an optional parameter that allows you to specify additional options for the
|
|
86
|
+
* RedBlackTree class. These options could include configuration settings, behavior customization, or
|
|
87
|
+
* any other parameters that are specific to
|
|
88
|
+
*/
|
|
89
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, RedBlackTreeNode<K, V>> | R>, options?: RedBlackTreeOptions<K, V, R>);
|
|
90
|
+
protected _root: RedBlackTreeNode<K, V> | undefined;
|
|
91
|
+
get root(): RedBlackTreeNode<K, V> | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Time Complexity: O(1)
|
|
94
|
+
* Space Complexity: O(1)
|
|
95
|
+
*
|
|
96
|
+
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
97
|
+
* @param {K} key - The key parameter represents the key value of the node being created. It is of
|
|
98
|
+
* type K, which is a generic type that can be replaced with any specific type when using the
|
|
99
|
+
* function.
|
|
100
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
101
|
+
* associated with the key in the node. It is not required and can be omitted if you only need to
|
|
102
|
+
* create a node with a key.
|
|
103
|
+
* @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
|
|
104
|
+
* in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
|
|
105
|
+
* set to "BLACK" if not specified.
|
|
106
|
+
* @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
|
|
107
|
+
* returned.
|
|
108
|
+
*/
|
|
109
|
+
createNode(key: K, value?: V, color?: RBTNColor): RedBlackTreeNode<K, V>;
|
|
110
|
+
/**
|
|
111
|
+
* Time Complexity: O(1)
|
|
112
|
+
* Space Complexity: O(1)
|
|
113
|
+
*
|
|
114
|
+
* The function creates a new Red-Black Tree with the specified options.
|
|
115
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
116
|
+
* configuration options for creating the Red-Black Tree. It has the following properties:
|
|
117
|
+
* @returns a new instance of a RedBlackTree object.
|
|
118
|
+
*/
|
|
119
|
+
createTree(options?: RedBlackTreeOptions<K, V, R>): RedBlackTree<K, V, R, MK, MV, MR>;
|
|
120
|
+
/**
|
|
121
|
+
* Time Complexity: O(1)
|
|
122
|
+
* Space Complexity: O(1)
|
|
123
|
+
*
|
|
124
|
+
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
125
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
126
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
|
|
127
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
128
|
+
* an instance of the `RedBlackTreeNode` class.
|
|
129
|
+
*/
|
|
130
|
+
isNode(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>): keyNodeOrEntry is RedBlackTreeNode<K, V>;
|
|
131
|
+
/**
|
|
132
|
+
* Time Complexity: O(1)
|
|
133
|
+
* Space Complexity: O(1)
|
|
134
|
+
*
|
|
135
|
+
* The "clear" function sets the root node of a data structure to a sentinel value and resets the
|
|
136
|
+
* size counter to zero.
|
|
137
|
+
*/
|
|
138
|
+
clear(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Time Complexity: O(log n)
|
|
141
|
+
* Space Complexity: O(log n)
|
|
142
|
+
*
|
|
143
|
+
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
144
|
+
* added.
|
|
145
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
146
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
|
|
147
|
+
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
148
|
+
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
149
|
+
* structure.
|
|
150
|
+
* @returns The method is returning a boolean value. If a new node is successfully added to the tree,
|
|
151
|
+
* the method returns true. If the node already exists and its value is updated, the method also
|
|
152
|
+
* returns true. If the node cannot be added or updated, the method returns false.
|
|
153
|
+
*/
|
|
154
|
+
add(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>, value?: V): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Time Complexity: O(log n)
|
|
157
|
+
* Space Complexity: O(log n)
|
|
158
|
+
*
|
|
159
|
+
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
160
|
+
* a given predicate and maintain the binary search tree properties.
|
|
161
|
+
* @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
162
|
+
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
163
|
+
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
164
|
+
* function that determines which node(s) should be deleted.
|
|
165
|
+
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>`
|
|
166
|
+
* objects. Each object in the array contains information about the deleted node and whether
|
|
167
|
+
* balancing is needed.
|
|
168
|
+
*/
|
|
169
|
+
delete(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[];
|
|
170
|
+
/**
|
|
171
|
+
* Time Complexity: O(n)
|
|
172
|
+
* Space Complexity: O(n)
|
|
173
|
+
*
|
|
174
|
+
* The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
|
|
175
|
+
* applying a callback to each entry in the original tree.
|
|
176
|
+
* @param callback - A function that will be called for each entry in the tree, with parameters
|
|
177
|
+
* representing the key, value, index, and the tree itself. It should return an entry for the new
|
|
178
|
+
* tree.
|
|
179
|
+
* @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
|
|
180
|
+
* MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
|
|
181
|
+
* Tree that will be created during the mapping process. These options could include things like
|
|
182
|
+
* custom comparators
|
|
183
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
184
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
185
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
186
|
+
* or
|
|
187
|
+
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
188
|
+
* provided callback function.
|
|
189
|
+
*/
|
|
190
|
+
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: RedBlackTreeOptions<MK, MV, MR>, thisArg?: any): RedBlackTree<MK, MV, MR>;
|
|
191
|
+
/**
|
|
192
|
+
* Time Complexity: O(n)
|
|
193
|
+
* Space Complexity: O(n)
|
|
194
|
+
*
|
|
195
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
196
|
+
* structure.
|
|
197
|
+
* @returns The `cloned` object is being returned.
|
|
198
|
+
*/
|
|
199
|
+
clone(): RedBlackTree<K, V, R, MK, MV, MR>;
|
|
200
|
+
/**
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(1)
|
|
203
|
+
*
|
|
204
|
+
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
205
|
+
* root.
|
|
206
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
|
|
207
|
+
*/
|
|
208
|
+
protected _setRoot(v: RedBlackTreeNode<K, V> | undefined): void;
|
|
209
|
+
/**
|
|
210
|
+
* Time Complexity: O(1)
|
|
211
|
+
* Space Complexity: O(1)
|
|
212
|
+
*
|
|
213
|
+
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
214
|
+
* @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
215
|
+
* the data structure.
|
|
216
|
+
* @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
|
|
217
|
+
* data structure.
|
|
218
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
219
|
+
* superclass, with the `oldNode` and `newNode` parameters.
|
|
220
|
+
*/
|
|
221
|
+
protected _replaceNode(oldNode: RedBlackTreeNode<K, V>, newNode: RedBlackTreeNode<K, V>): RedBlackTreeNode<K, V>;
|
|
222
|
+
/**
|
|
223
|
+
* Time Complexity: O(log n)
|
|
224
|
+
* Space Complexity: O(log n)
|
|
225
|
+
*
|
|
226
|
+
* The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
|
|
227
|
+
* maintain the red-black tree properties.
|
|
228
|
+
* @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
|
|
229
|
+
* binary search tree.
|
|
230
|
+
* @returns a string value indicating the result of the insertion operation. It can return either
|
|
231
|
+
* 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
|
|
232
|
+
* was created and inserted into the tree.
|
|
233
|
+
*/
|
|
234
|
+
protected _insert(node: RedBlackTreeNode<K, V>): CRUD;
|
|
235
|
+
/**
|
|
236
|
+
* Time Complexity: O(1)
|
|
237
|
+
* Space Complexity: O(1)
|
|
238
|
+
*
|
|
239
|
+
* The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
|
|
240
|
+
* @param {RedBlackTreeNode<K, V>} u - The parameter "u" represents a node in a binary tree.
|
|
241
|
+
* @param {RedBlackTreeNode<K, V> | undefined} v - The parameter `v` is of type `RedBlackTreeNode<K, V> | undefined`, which means it can
|
|
242
|
+
* either be a `RedBlackTreeNode<K, V>` object or `undefined`.
|
|
243
|
+
*/
|
|
244
|
+
protected _transplant(u: RedBlackTreeNode<K, V>, v: RedBlackTreeNode<K, V> | undefined): void;
|
|
245
|
+
/**
|
|
246
|
+
* Time Complexity: O(log n)
|
|
247
|
+
* Space Complexity: O(1)
|
|
248
|
+
*
|
|
249
|
+
* The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
|
|
250
|
+
* @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
|
|
251
|
+
* structure. It can either be a valid node or `undefined`.
|
|
252
|
+
*/
|
|
253
|
+
protected _insertFixup(z: RedBlackTreeNode<K, V> | undefined): void;
|
|
254
|
+
/**
|
|
255
|
+
* Time Complexity: O(log n)
|
|
256
|
+
* Space Complexity: O(1)
|
|
257
|
+
*
|
|
258
|
+
* The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
|
|
259
|
+
* the colors and performing rotations.
|
|
260
|
+
* @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
|
|
261
|
+
* be either a valid node object or `undefined`.
|
|
262
|
+
* @returns The function does not return any value. It has a return type of `void`, which means it
|
|
263
|
+
* does not return anything.
|
|
264
|
+
*/
|
|
265
|
+
protected _deleteFixup(node: RedBlackTreeNode<K, V> | undefined): void;
|
|
266
|
+
/**
|
|
267
|
+
* Time Complexity: O(1)
|
|
268
|
+
* Space Complexity: O(1)
|
|
269
|
+
*
|
|
270
|
+
* The `_leftRotate` function performs a left rotation on a given node in a binary tree.
|
|
271
|
+
* @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
272
|
+
* node in a binary tree or `undefined` if there is no node.
|
|
273
|
+
* @returns void, which means it does not return any value.
|
|
274
|
+
*/
|
|
275
|
+
protected _leftRotate(x: RedBlackTreeNode<K, V> | undefined): void;
|
|
276
|
+
/**
|
|
277
|
+
* Time Complexity: O(1)
|
|
278
|
+
* Space Complexity: O(1)
|
|
279
|
+
*
|
|
280
|
+
* The `_rightRotate` function performs a right rotation on a given node in a binary tree.
|
|
281
|
+
* @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
282
|
+
* node in a binary tree or `undefined` if there is no node.
|
|
283
|
+
* @returns void, which means it does not return any value.
|
|
284
|
+
*/
|
|
285
|
+
protected _rightRotate(y: RedBlackTreeNode<K, V> | undefined): void;
|
|
286
|
+
}
|