data-structure-typed 1.52.6 → 1.52.8
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 +1 -1
- package/README.md +33 -30
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +156 -156
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/cjs/constants/index.js +9 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +668 -597
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +3 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.js +4 -2
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/cjs/data-structures/queue/deque.js +29 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/cjs/data-structures/trie/trie.js +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/constants/index.d.ts +4 -0
- package/dist/mjs/constants/index.js +5 -0
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +667 -591
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.js +1 -1
- package/dist/mjs/data-structures/heap/heap.js +3 -3
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.js +4 -2
- package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/mjs/data-structures/queue/deque.js +29 -29
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/mjs/data-structures/trie/trie.js +1 -1
- package/dist/mjs/index.d.ts +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
- package/dist/umd/data-structure-typed.js +1343 -1615
- package/dist/umd/data-structure-typed.min.js +10 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/eslint.config.mjs +69 -0
- package/package.json +30 -28
- package/src/constants/index.ts +4 -0
- package/src/data-structures/base/iterable-element-base.ts +11 -1
- package/src/data-structures/base/iterable-entry-base.ts +11 -19
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
- package/src/data-structures/binary-tree/avl-tree.ts +69 -71
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +697 -725
- package/src/data-structures/binary-tree/bst.ts +123 -129
- package/src/data-structures/binary-tree/rb-tree.ts +44 -46
- package/src/data-structures/binary-tree/segment-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +3 -3
- package/src/data-structures/heap/heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/queue/deque.ts +31 -31
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/stack/stack.ts +2 -2
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/index.ts +1 -0
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
- package/test/config.ts +1 -7
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +2 -2
- package/test/integration/bst.test.ts +17 -16
- package/test/integration/heap.test.js +6 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +51 -26
- package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/test/unit/data-structures/stack/stack.test.ts +6 -0
- package/test/unit/unrestricted-interconversion.test.ts +24 -24
- package/test/utils/big-o.ts +5 -4
- package/.eslintrc.js +0 -64
|
@@ -61,21 +61,21 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
61
61
|
export class BST extends BinaryTree {
|
|
62
62
|
/**
|
|
63
63
|
* This is the constructor function for a Binary Search Tree class in TypeScript.
|
|
64
|
-
* @param
|
|
64
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
65
65
|
* iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
|
|
66
66
|
* added to the binary search tree during the construction of the object.
|
|
67
67
|
* @param [options] - An optional object that contains additional options for the Binary Search Tree.
|
|
68
68
|
* It can include a comparator function that defines the order of the elements in the tree.
|
|
69
69
|
*/
|
|
70
|
-
constructor(
|
|
70
|
+
constructor(keysOrNodesOrEntriesOrRaws = [], options) {
|
|
71
71
|
super([], options);
|
|
72
72
|
if (options) {
|
|
73
73
|
const { comparator } = options;
|
|
74
74
|
if (comparator)
|
|
75
75
|
this._comparator = comparator;
|
|
76
76
|
}
|
|
77
|
-
if (
|
|
78
|
-
this.addMany(
|
|
77
|
+
if (keysOrNodesOrEntriesOrRaws)
|
|
78
|
+
this.addMany(keysOrNodesOrEntriesOrRaws);
|
|
79
79
|
}
|
|
80
80
|
_root = undefined;
|
|
81
81
|
/**
|
|
@@ -106,21 +106,22 @@ export class BST extends BinaryTree {
|
|
|
106
106
|
createTree(options) {
|
|
107
107
|
return new BST([], {
|
|
108
108
|
iterationType: this.iterationType,
|
|
109
|
-
comparator: this.
|
|
109
|
+
comparator: this._comparator,
|
|
110
|
+
toEntryFn: this._toEntryFn,
|
|
110
111
|
...options
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
/**
|
|
114
115
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
115
|
-
* @param {
|
|
116
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - A variable that can be of
|
|
116
117
|
* type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
117
118
|
* element.
|
|
118
119
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
119
120
|
* value associated with a key in a key-value pair.
|
|
120
121
|
* @returns either a NODE object or undefined.
|
|
121
122
|
*/
|
|
122
|
-
keyValueOrEntryOrRawElementToNode(
|
|
123
|
-
return super.keyValueOrEntryOrRawElementToNode(
|
|
123
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value) {
|
|
124
|
+
return super.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value) ?? undefined;
|
|
124
125
|
}
|
|
125
126
|
/**
|
|
126
127
|
* Time Complexity: O(log n)
|
|
@@ -128,8 +129,8 @@ export class BST extends BinaryTree {
|
|
|
128
129
|
*
|
|
129
130
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
130
131
|
* it doesn't exist.
|
|
131
|
-
* @param {
|
|
132
|
-
* `
|
|
132
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
133
|
+
* `keyOrNodeOrEntryOrRaw` can accept a value of type `R`, which represents the key, node,
|
|
133
134
|
* entry, or raw element that needs to be ensured in the tree.
|
|
134
135
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
135
136
|
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
@@ -137,19 +138,27 @@ export class BST extends BinaryTree {
|
|
|
137
138
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
138
139
|
* not be ensured.
|
|
139
140
|
*/
|
|
140
|
-
ensureNode(
|
|
141
|
-
return super.ensureNode(
|
|
141
|
+
ensureNode(keyOrNodeOrEntryOrRaw, iterationType = this.iterationType) {
|
|
142
|
+
return super.ensureNode(keyOrNodeOrEntryOrRaw, iterationType) ?? undefined;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
145
|
* The function checks if the input is an instance of the BSTNode class.
|
|
145
|
-
* @param {
|
|
146
|
-
* `
|
|
147
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
146
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
147
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
148
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
148
149
|
* an instance of the `BSTNode` class.
|
|
149
150
|
*/
|
|
150
|
-
isNode(
|
|
151
|
-
return
|
|
151
|
+
isNode(keyOrNodeOrEntryOrRaw) {
|
|
152
|
+
return keyOrNodeOrEntryOrRaw instanceof BSTNode;
|
|
152
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* The function "override isKey" checks if a key is comparable based on a given comparator.
|
|
156
|
+
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
157
|
+
* type `K`.
|
|
158
|
+
* @returns The `override isKey(key: any): key is K` function is returning a boolean value based on
|
|
159
|
+
* the result of the `isComparable` function with the condition `this.comparator !==
|
|
160
|
+
* this._DEFAULT_COMPARATOR`.
|
|
161
|
+
*/
|
|
153
162
|
isKey(key) {
|
|
154
163
|
return isComparable(key, this.comparator !== this._DEFAULT_COMPARATOR);
|
|
155
164
|
}
|
|
@@ -158,22 +167,22 @@ export class BST extends BinaryTree {
|
|
|
158
167
|
* Space Complexity: O(1)
|
|
159
168
|
*
|
|
160
169
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
161
|
-
* @param {
|
|
162
|
-
* `
|
|
170
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
171
|
+
* `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
163
172
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
164
173
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
165
174
|
* @returns a boolean value.
|
|
166
175
|
*/
|
|
167
|
-
add(
|
|
168
|
-
const newNode = this.keyValueOrEntryOrRawElementToNode(
|
|
176
|
+
add(keyOrNodeOrEntryOrRaw, value) {
|
|
177
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
|
|
169
178
|
if (newNode === undefined)
|
|
170
179
|
return false;
|
|
171
|
-
if (this.
|
|
180
|
+
if (this._root === undefined) {
|
|
172
181
|
this._setRoot(newNode);
|
|
173
182
|
this._size++;
|
|
174
183
|
return true;
|
|
175
184
|
}
|
|
176
|
-
let current = this.
|
|
185
|
+
let current = this._root;
|
|
177
186
|
while (current !== undefined) {
|
|
178
187
|
if (this.comparator(current.key, newNode.key) === 0) {
|
|
179
188
|
this._replaceNode(current, newNode);
|
|
@@ -204,7 +213,7 @@ export class BST extends BinaryTree {
|
|
|
204
213
|
*
|
|
205
214
|
* The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
|
|
206
215
|
* an array indicating whether each key or node was successfully inserted.
|
|
207
|
-
* @param
|
|
216
|
+
* @param keysOrNodesOrEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
|
|
208
217
|
* elements to be added to the data structure.
|
|
209
218
|
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
210
219
|
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
@@ -219,14 +228,14 @@ export class BST extends BinaryTree {
|
|
|
219
228
|
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
220
229
|
* successfully inserted into the data structure.
|
|
221
230
|
*/
|
|
222
|
-
addMany(
|
|
231
|
+
addMany(keysOrNodesOrEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
223
232
|
const inserted = [];
|
|
224
233
|
let valuesIterator;
|
|
225
234
|
if (values) {
|
|
226
235
|
valuesIterator = values[Symbol.iterator]();
|
|
227
236
|
}
|
|
228
237
|
if (!isBalanceAdd) {
|
|
229
|
-
for (const kve of
|
|
238
|
+
for (const kve of keysOrNodesOrEntriesOrRaws) {
|
|
230
239
|
const value = valuesIterator?.next().value;
|
|
231
240
|
const nn = this.add(kve, value);
|
|
232
241
|
inserted.push(nn);
|
|
@@ -239,8 +248,9 @@ export class BST extends BinaryTree {
|
|
|
239
248
|
return false;
|
|
240
249
|
return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));
|
|
241
250
|
};
|
|
242
|
-
for (const kve of
|
|
243
|
-
isRealBTNExemplar(kve)
|
|
251
|
+
for (const kve of keysOrNodesOrEntriesOrRaws) {
|
|
252
|
+
if (isRealBTNExemplar(kve))
|
|
253
|
+
realBTNExemplars.push(kve);
|
|
244
254
|
}
|
|
245
255
|
let sorted = [];
|
|
246
256
|
sorted = realBTNExemplars.sort((a, b) => {
|
|
@@ -249,8 +259,8 @@ export class BST extends BinaryTree {
|
|
|
249
259
|
keyA = a[0];
|
|
250
260
|
else if (this.isRealNode(a))
|
|
251
261
|
keyA = a.key;
|
|
252
|
-
else if (this.
|
|
253
|
-
keyA = this.
|
|
262
|
+
else if (this._toEntryFn) {
|
|
263
|
+
keyA = this._toEntryFn(a)[0];
|
|
254
264
|
}
|
|
255
265
|
else {
|
|
256
266
|
keyA = a;
|
|
@@ -259,8 +269,8 @@ export class BST extends BinaryTree {
|
|
|
259
269
|
keyB = b[0];
|
|
260
270
|
else if (this.isRealNode(b))
|
|
261
271
|
keyB = b.key;
|
|
262
|
-
else if (this.
|
|
263
|
-
keyB = this.
|
|
272
|
+
else if (this._toEntryFn) {
|
|
273
|
+
keyB = this._toEntryFn(b)[0];
|
|
264
274
|
}
|
|
265
275
|
else {
|
|
266
276
|
keyB = b;
|
|
@@ -308,54 +318,55 @@ export class BST extends BinaryTree {
|
|
|
308
318
|
* Time Complexity: O(log n)
|
|
309
319
|
* Space Complexity: O(k + log n)
|
|
310
320
|
*
|
|
311
|
-
* The `getNodes`
|
|
312
|
-
*
|
|
313
|
-
* @param {
|
|
314
|
-
*
|
|
315
|
-
* function
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @param {IterationType} iterationType - The `iterationType` parameter
|
|
326
|
-
* iteration to be performed
|
|
327
|
-
*
|
|
321
|
+
* The function `getNodes` in TypeScript overrides the base class method to retrieve nodes based on a
|
|
322
|
+
* given predicate and iteration type.
|
|
323
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
324
|
+
* parameter in the `getNodes` method is used to filter the nodes that will be returned. It can be a
|
|
325
|
+
* key, a node, an entry, or a custom predicate function that determines whether a node should be
|
|
326
|
+
* included in the result.
|
|
327
|
+
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` method is a boolean flag that
|
|
328
|
+
* determines whether to return only the first node that matches the predicate (`true`) or all nodes
|
|
329
|
+
* that match the predicate (`false`). If `onlyOne` is set to `true`, the method will stop iterating
|
|
330
|
+
* and
|
|
331
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
|
|
332
|
+
* `getNodes` method is used to specify the starting point for traversing the tree when searching for
|
|
333
|
+
* nodes that match a given predicate. It represents the root node of the subtree where the search
|
|
334
|
+
* should begin. If not explicitly provided, the default value for `begin
|
|
335
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `getNodes` method
|
|
336
|
+
* specifies the type of iteration to be performed when traversing the nodes of a binary tree. It can
|
|
337
|
+
* have two possible values:
|
|
338
|
+
* @returns The `getNodes` method returns an array of nodes that satisfy the given predicate.
|
|
328
339
|
*/
|
|
329
|
-
getNodes(
|
|
330
|
-
if (
|
|
340
|
+
getNodes(predicate, onlyOne = false, beginRoot = this._root, iterationType = this.iterationType) {
|
|
341
|
+
if (predicate === undefined)
|
|
331
342
|
return [];
|
|
332
|
-
if (
|
|
343
|
+
if (predicate === null)
|
|
333
344
|
return [];
|
|
334
345
|
beginRoot = this.ensureNode(beginRoot);
|
|
335
346
|
if (!beginRoot)
|
|
336
347
|
return [];
|
|
337
|
-
callback = this.
|
|
348
|
+
const callback = this._ensurePredicate(predicate);
|
|
338
349
|
const ans = [];
|
|
339
350
|
if (iterationType === 'RECURSIVE') {
|
|
340
351
|
const dfs = (cur) => {
|
|
341
|
-
|
|
342
|
-
if (callbackResult === identifier) {
|
|
352
|
+
if (callback(cur)) {
|
|
343
353
|
ans.push(cur);
|
|
344
354
|
if (onlyOne)
|
|
345
355
|
return;
|
|
346
356
|
}
|
|
347
357
|
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
348
358
|
return;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
|
|
359
|
+
if (this.isKey(predicate)) {
|
|
360
|
+
if (this.isRealNode(cur.left) && this.comparator(cur.key, predicate) > 0)
|
|
352
361
|
dfs(cur.left);
|
|
353
|
-
if (this.isRealNode(cur.right) && this.comparator(cur.key,
|
|
362
|
+
if (this.isRealNode(cur.right) && this.comparator(cur.key, predicate) < 0)
|
|
354
363
|
dfs(cur.right);
|
|
355
364
|
}
|
|
356
365
|
else {
|
|
357
|
-
this.isRealNode(cur.left)
|
|
358
|
-
|
|
366
|
+
if (this.isRealNode(cur.left))
|
|
367
|
+
dfs(cur.left);
|
|
368
|
+
if (this.isRealNode(cur.right))
|
|
369
|
+
dfs(cur.right);
|
|
359
370
|
}
|
|
360
371
|
};
|
|
361
372
|
dfs(beginRoot);
|
|
@@ -364,28 +375,22 @@ export class BST extends BinaryTree {
|
|
|
364
375
|
const stack = [beginRoot];
|
|
365
376
|
while (stack.length > 0) {
|
|
366
377
|
const cur = stack.pop();
|
|
367
|
-
|
|
368
|
-
if (callbackResult === identifier) {
|
|
378
|
+
if (callback(cur)) {
|
|
369
379
|
ans.push(cur);
|
|
370
380
|
if (onlyOne)
|
|
371
381
|
return ans;
|
|
372
382
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
|
|
383
|
+
if (this.isKey(predicate)) {
|
|
384
|
+
if (this.isRealNode(cur.right) && this.comparator(cur.key, predicate) < 0)
|
|
376
385
|
stack.push(cur.right);
|
|
377
|
-
if (this.isRealNode(cur.left) && this.comparator(cur.key,
|
|
386
|
+
if (this.isRealNode(cur.left) && this.comparator(cur.key, predicate) > 0)
|
|
378
387
|
stack.push(cur.left);
|
|
379
|
-
// if (this.isRealNode(cur.right) && this._lt(cur.key, identifier as K)) stack.push(cur.right);
|
|
380
|
-
// if (this.isRealNode(cur.left) && this._gt(cur.key, identifier as K)) stack.push(cur.left);
|
|
381
|
-
// // @ts-ignore
|
|
382
|
-
// if (this.isRealNode(cur.right) && cur.key > identifier) stack.push(cur.right);
|
|
383
|
-
// // @ts-ignore
|
|
384
|
-
// if (this.isRealNode(cur.left) && cur.key < identifier) stack.push(cur.left);
|
|
385
388
|
}
|
|
386
389
|
else {
|
|
387
|
-
this.isRealNode(cur.right)
|
|
388
|
-
|
|
390
|
+
if (this.isRealNode(cur.right))
|
|
391
|
+
stack.push(cur.right);
|
|
392
|
+
if (this.isRealNode(cur.left))
|
|
393
|
+
stack.push(cur.left);
|
|
389
394
|
}
|
|
390
395
|
}
|
|
391
396
|
}
|
|
@@ -395,25 +400,24 @@ export class BST extends BinaryTree {
|
|
|
395
400
|
* Time Complexity: O(log n)
|
|
396
401
|
* Space Complexity: O(1)
|
|
397
402
|
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* node
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* @returns The method is returning a NODE object or undefined.
|
|
403
|
+
* This function retrieves a node based on a given predicate within a binary search tree structure.
|
|
404
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
405
|
+
* parameter can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, `R`, or `BTNPredicate<NODE>`.
|
|
406
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} beginRoot - The `beginRoot` parameter in the `getNode` method
|
|
407
|
+
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
408
|
+
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
409
|
+
* node of the binary search tree.
|
|
410
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is a
|
|
411
|
+
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
412
|
+
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
413
|
+
* no value is provided when calling the method.
|
|
414
|
+
* @returns The `getNode` method is returning an optional binary search tree node (`OptBSTN<NODE>`).
|
|
415
|
+
* It is using the `getNodes` method to find the node based on the provided predicate, beginning at
|
|
416
|
+
* the specified root node (`beginRoot`) and using the specified iteration type. The method then
|
|
417
|
+
* returns the first node found or `undefined` if no node is found.
|
|
414
418
|
*/
|
|
415
|
-
getNode(
|
|
416
|
-
return this.getNodes(
|
|
419
|
+
getNode(predicate, beginRoot = this._root, iterationType = this.iterationType) {
|
|
420
|
+
return this.getNodes(predicate, true, beginRoot, iterationType)[0] ?? undefined;
|
|
417
421
|
}
|
|
418
422
|
/**
|
|
419
423
|
* Time Complexity: O(log n)
|
|
@@ -429,7 +433,7 @@ export class BST extends BinaryTree {
|
|
|
429
433
|
* @returns The method is returning a NODE object or undefined.
|
|
430
434
|
*/
|
|
431
435
|
getNodeByKey(key, iterationType = this.iterationType) {
|
|
432
|
-
return this.getNode(key, this.
|
|
436
|
+
return this.getNode(key, this._root, iterationType);
|
|
433
437
|
}
|
|
434
438
|
/**
|
|
435
439
|
* Time complexity: O(n)
|
|
@@ -439,11 +443,11 @@ export class BST extends BinaryTree {
|
|
|
439
443
|
* the callback function.
|
|
440
444
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
441
445
|
* during the depth-first search traversal. It is an optional parameter and defaults to
|
|
442
|
-
* `this.
|
|
446
|
+
* `this._DEFAULT_BTN_CALLBACK`. The type `C` represents the type of the callback function.
|
|
443
447
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
444
448
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
445
449
|
* take one of the following values:
|
|
446
|
-
* @param {
|
|
450
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
|
|
447
451
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
448
452
|
* node entry. If not specified, the default value is the root of the tree.
|
|
449
453
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -451,7 +455,7 @@ export class BST extends BinaryTree {
|
|
|
451
455
|
* following values:
|
|
452
456
|
* @returns The method is returning an array of the return type of the callback function.
|
|
453
457
|
*/
|
|
454
|
-
dfs(callback = this.
|
|
458
|
+
dfs(callback = this._DEFAULT_BTN_CALLBACK, pattern = 'IN', beginRoot = this._root, iterationType = this.iterationType) {
|
|
455
459
|
return super.dfs(callback, pattern, beginRoot, iterationType);
|
|
456
460
|
}
|
|
457
461
|
/**
|
|
@@ -463,7 +467,7 @@ export class BST extends BinaryTree {
|
|
|
463
467
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
464
468
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
465
469
|
* node being visited, and it can return a value of any type.
|
|
466
|
-
* @param {
|
|
470
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
|
|
467
471
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
468
472
|
* object. If no value is provided, the default value is the root of the tree.
|
|
469
473
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -471,7 +475,7 @@ export class BST extends BinaryTree {
|
|
|
471
475
|
* the following values:
|
|
472
476
|
* @returns an array of the return type of the callback function.
|
|
473
477
|
*/
|
|
474
|
-
bfs(callback = this.
|
|
478
|
+
bfs(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
|
|
475
479
|
return super.bfs(callback, beginRoot, iterationType, false);
|
|
476
480
|
}
|
|
477
481
|
/**
|
|
@@ -483,7 +487,7 @@ export class BST extends BinaryTree {
|
|
|
483
487
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
484
488
|
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
485
489
|
* tree during the iteration process.
|
|
486
|
-
* @param {
|
|
490
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
|
|
487
491
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
488
492
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
489
493
|
* value is provided, the root of
|
|
@@ -492,7 +496,7 @@ export class BST extends BinaryTree {
|
|
|
492
496
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
493
497
|
* function.
|
|
494
498
|
*/
|
|
495
|
-
listLevels(callback = this.
|
|
499
|
+
listLevels(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
|
|
496
500
|
return super.listLevels(callback, beginRoot, iterationType, false);
|
|
497
501
|
}
|
|
498
502
|
/**
|
|
@@ -507,7 +511,7 @@ export class BST extends BinaryTree {
|
|
|
507
511
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
508
512
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
509
513
|
* 0, or 1, where:
|
|
510
|
-
* @param {
|
|
514
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} targetNode - The `targetNode` parameter is the node in
|
|
511
515
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
512
516
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
513
517
|
* `targetNode` is provided,
|
|
@@ -516,12 +520,12 @@ export class BST extends BinaryTree {
|
|
|
516
520
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
517
521
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
518
522
|
*/
|
|
519
|
-
lesserOrGreaterTraverse(callback = this.
|
|
523
|
+
lesserOrGreaterTraverse(callback = this._DEFAULT_BTN_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
|
|
520
524
|
const targetNodeEnsured = this.ensureNode(targetNode);
|
|
521
525
|
const ans = [];
|
|
522
|
-
if (!
|
|
526
|
+
if (!this._root)
|
|
523
527
|
return ans;
|
|
524
|
-
if (!
|
|
528
|
+
if (!targetNodeEnsured)
|
|
525
529
|
return ans;
|
|
526
530
|
const targetKey = targetNodeEnsured.key;
|
|
527
531
|
if (iterationType === 'RECURSIVE') {
|
|
@@ -534,11 +538,11 @@ export class BST extends BinaryTree {
|
|
|
534
538
|
if (this.isRealNode(cur.right))
|
|
535
539
|
dfs(cur.right);
|
|
536
540
|
};
|
|
537
|
-
dfs(this.
|
|
541
|
+
dfs(this._root);
|
|
538
542
|
return ans;
|
|
539
543
|
}
|
|
540
544
|
else {
|
|
541
|
-
const queue = new Queue([this.
|
|
545
|
+
const queue = new Queue([this._root]);
|
|
542
546
|
while (queue.size > 0) {
|
|
543
547
|
const cur = queue.shift();
|
|
544
548
|
if (this.isRealNode(cur)) {
|
|
@@ -615,7 +619,7 @@ export class BST extends BinaryTree {
|
|
|
615
619
|
* @returns a boolean value.
|
|
616
620
|
*/
|
|
617
621
|
isAVLBalanced(iterationType = this.iterationType) {
|
|
618
|
-
if (!this.
|
|
622
|
+
if (!this._root)
|
|
619
623
|
return true;
|
|
620
624
|
let balanced = true;
|
|
621
625
|
if (iterationType === 'RECURSIVE') {
|
|
@@ -627,11 +631,11 @@ export class BST extends BinaryTree {
|
|
|
627
631
|
balanced = false;
|
|
628
632
|
return Math.max(leftHeight, rightHeight) + 1;
|
|
629
633
|
};
|
|
630
|
-
_height(this.
|
|
634
|
+
_height(this._root);
|
|
631
635
|
}
|
|
632
636
|
else {
|
|
633
637
|
const stack = [];
|
|
634
|
-
let node = this.
|
|
638
|
+
let node = this._root, last = undefined;
|
|
635
639
|
const depths = new Map();
|
|
636
640
|
while (stack.length > 0 || node) {
|
|
637
641
|
if (node) {
|
|
@@ -643,8 +647,8 @@ export class BST extends BinaryTree {
|
|
|
643
647
|
if (!node.right || last === node.right) {
|
|
644
648
|
node = stack.pop();
|
|
645
649
|
if (node) {
|
|
646
|
-
const left = node.left ?
|
|
647
|
-
const right = node.right ?
|
|
650
|
+
const left = node.left ? depths.get(node.left) : -1;
|
|
651
|
+
const right = node.right ? depths.get(node.right) : -1;
|
|
648
652
|
if (Math.abs(left - right) > 1)
|
|
649
653
|
return false;
|
|
650
654
|
depths.set(node, 1 + Math.max(left, right));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { BinaryTreeDeleteResult,
|
|
2
|
-
import { BTNEntry } from '../../types';
|
|
1
|
+
import type { BinaryTreeDeleteResult, BTNKeyOrNodeOrEntry, BTNPredicate, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested, BTNEntry } from '../../types';
|
|
3
2
|
import { BST, BSTNode } from './bst';
|
|
4
3
|
import { IBinaryTree } from '../../interfaces';
|
|
5
4
|
export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
@@ -30,7 +29,7 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
|
|
|
30
29
|
export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
31
30
|
/**
|
|
32
31
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
33
|
-
* @param
|
|
32
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
34
33
|
* iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
|
|
35
34
|
* initialize the RBTree with the provided elements.
|
|
36
35
|
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
@@ -38,7 +37,7 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
38
37
|
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
39
38
|
* depend on the implementation
|
|
40
39
|
*/
|
|
41
|
-
constructor(
|
|
40
|
+
constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
|
|
42
41
|
protected _root: NODE | undefined;
|
|
43
42
|
/**
|
|
44
43
|
* The function returns the root node of a tree or undefined if there is no root.
|
|
@@ -72,12 +71,12 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
72
71
|
* Space Complexity: O(1)
|
|
73
72
|
*
|
|
74
73
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
75
|
-
* @param {
|
|
76
|
-
* `
|
|
77
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
74
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
75
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
76
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
78
77
|
* an instance of the `RedBlackTreeNode` class.
|
|
79
78
|
*/
|
|
80
|
-
isNode(
|
|
79
|
+
isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
|
|
81
80
|
/**
|
|
82
81
|
* Time Complexity: O(1)
|
|
83
82
|
* Space Complexity: O(1)
|
|
@@ -92,8 +91,8 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
92
91
|
*
|
|
93
92
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
94
93
|
* added.
|
|
95
|
-
* @param {
|
|
96
|
-
* `
|
|
94
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
95
|
+
* `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
97
96
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
98
97
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
99
98
|
* structure.
|
|
@@ -101,24 +100,22 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
101
100
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
102
101
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
103
102
|
*/
|
|
104
|
-
add(
|
|
103
|
+
add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean;
|
|
105
104
|
/**
|
|
106
105
|
* Time Complexity: O(log n)
|
|
107
106
|
* Space Complexity: O(1)
|
|
108
107
|
*
|
|
109
|
-
* The function overrides the delete method
|
|
110
|
-
*
|
|
111
|
-
* @param {
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
108
|
+
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
109
|
+
* a given predicate and maintain the binary search tree properties.
|
|
110
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
111
|
+
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
112
|
+
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
113
|
+
* function that determines which node(s) should be deleted.
|
|
114
|
+
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
|
|
115
|
+
* objects. Each object in the array contains information about the deleted node and whether
|
|
116
|
+
* balancing is needed.
|
|
117
|
+
*/
|
|
118
|
+
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
|
|
122
119
|
/**
|
|
123
120
|
* Time Complexity: O(1)
|
|
124
121
|
* Space Complexity: O(1)
|