doubly-linked-list-typed 1.53.9 → 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/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 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -357
- package/dist/data-structures/binary-tree/avl-tree.d.ts +108 -78
- package/dist/data-structures/binary-tree/avl-tree.js +126 -79
- 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 +243 -190
- package/dist/data-structures/binary-tree/binary-tree.js +273 -229
- package/dist/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/data-structures/binary-tree/bst.js +170 -134
- package/dist/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/data-structures/binary-tree/index.js +2 -0
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/data-structures/binary-tree/red-black-tree.js +101 -79
- 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 -186
- package/dist/data-structures/binary-tree/tree-multi-map.js +140 -388
- 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/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +3 -0
- 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/trie/trie.d.ts +0 -4
- package/dist/data-structures/trie/trie.js +0 -4
- package/dist/interfaces/binary-tree.d.ts +7 -6
- 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 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -2
- 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 +1 -3
- 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 +1 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +148 -394
- package/src/data-structures/binary-tree/avl-tree.ts +152 -112
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +446 -379
- package/src/data-structures/binary-tree/bst.ts +224 -201
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +138 -114
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +156 -428
- 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/linked-list/singly-linked-list.ts +3 -0
- 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/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -11
- 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 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -3
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -4
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -4
|
@@ -5,38 +5,28 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import type { BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode, OptNodeOrNull } from '../../types';
|
|
9
9
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { Range } from '../../common';
|
|
12
|
-
export declare class BSTNode<K = any, V = any
|
|
13
|
-
parent?: NODE;
|
|
14
|
-
constructor(key: K, value?: V);
|
|
15
|
-
protected _left?: NODE;
|
|
16
|
-
/**
|
|
17
|
-
* The function returns the value of the `_left` property.
|
|
18
|
-
* @returns The `_left` property of the current object is being returned.
|
|
19
|
-
*/
|
|
20
|
-
get left(): OptNode<NODE>;
|
|
21
|
-
/**
|
|
22
|
-
* The function sets the left child of a node and updates the parent reference of the child.
|
|
23
|
-
* @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be an
|
|
24
|
-
* instance of the `NODE` class or `undefined`.
|
|
25
|
-
*/
|
|
26
|
-
set left(v: OptNode<NODE>);
|
|
27
|
-
protected _right?: NODE;
|
|
28
|
-
/**
|
|
29
|
-
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
30
|
-
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
31
|
-
* `undefined`.
|
|
32
|
-
*/
|
|
33
|
-
get right(): OptNode<NODE>;
|
|
12
|
+
export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
34
13
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {
|
|
37
|
-
*
|
|
14
|
+
* This TypeScript constructor function initializes an instance with a key and an optional value.
|
|
15
|
+
* @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
|
|
16
|
+
* within a data structure. It serves as a reference or identifier for accessing or manipulating the
|
|
17
|
+
* associated value.
|
|
18
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
19
|
+
* have to be provided when creating an instance of the class. If a value is not provided, it will
|
|
20
|
+
* default to `undefined`.
|
|
38
21
|
*/
|
|
39
|
-
|
|
22
|
+
constructor(key: K, value?: V);
|
|
23
|
+
parent?: BSTNode<K, V>;
|
|
24
|
+
_left?: OptNodeOrNull<BSTNode<K, V>>;
|
|
25
|
+
get left(): OptNodeOrNull<BSTNode<K, V>>;
|
|
26
|
+
set left(v: OptNodeOrNull<BSTNode<K, V>>);
|
|
27
|
+
_right?: OptNodeOrNull<BSTNode<K, V>>;
|
|
28
|
+
get right(): OptNodeOrNull<BSTNode<K, V>>;
|
|
29
|
+
set right(v: OptNodeOrNull<BSTNode<K, V>>);
|
|
40
30
|
}
|
|
41
31
|
/**
|
|
42
32
|
* 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
|
|
@@ -103,71 +93,56 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
|
|
|
103
93
|
* console.log(findLCA(5, 35)); // 15
|
|
104
94
|
* console.log(findLCA(20, 30)); // 25
|
|
105
95
|
*/
|
|
106
|
-
export declare class BST<K = any, V = any, R = object,
|
|
107
|
-
/**
|
|
108
|
-
* This is the constructor function for a Binary Search Tree class in TypeScript.
|
|
109
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
110
|
-
* iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
|
|
111
|
-
* added to the binary search tree during the construction of the object.
|
|
112
|
-
* @param [options] - An optional object that contains additional options for the Binary Search Tree.
|
|
113
|
-
* It can include a comparator function that defines the order of the elements in the tree.
|
|
114
|
-
*/
|
|
115
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<R | BTNRep<K, V, NODE>>, options?: BSTOptions<K, V, R>);
|
|
116
|
-
protected _root?: NODE;
|
|
96
|
+
export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends BinaryTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
|
|
117
97
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
98
|
+
* This TypeScript constructor initializes a binary search tree with optional options and adds
|
|
99
|
+
* elements if provided.
|
|
100
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
101
|
+
* iterable that can contain elements of type `BTNRep<K, V, BSTNode<K, V>>` or `R`. It is used to
|
|
102
|
+
* initialize the binary search tree with keys, nodes, entries, or raw data.
|
|
103
|
+
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
104
|
+
* properties:
|
|
120
105
|
*/
|
|
121
|
-
|
|
106
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, BSTNode<K, V>> | R>, options?: BSTOptions<K, V, R>);
|
|
107
|
+
protected _root?: BSTNode<K, V>;
|
|
108
|
+
get root(): OptNode<BSTNode<K, V>>;
|
|
122
109
|
protected _isReverse: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* The above function is a getter method in TypeScript that returns the value of the private property
|
|
125
|
-
* `_isReverse`.
|
|
126
|
-
* @returns The `isReverse` property of the object, which is a boolean value.
|
|
127
|
-
*/
|
|
128
110
|
get isReverse(): boolean;
|
|
129
111
|
protected _comparator: Comparator<K>;
|
|
130
|
-
/**
|
|
131
|
-
* The function returns the value of the _comparator property.
|
|
132
|
-
* @returns The `_comparator` property is being returned.
|
|
133
|
-
*/
|
|
134
112
|
get comparator(): Comparator<K>;
|
|
135
113
|
protected _specifyComparable?: (key: K) => Comparable;
|
|
136
|
-
/**
|
|
137
|
-
* This function returns the value of the `_specifyComparable` property.
|
|
138
|
-
* @returns The method `specifyComparable()` is being returned, which is a getter method for the
|
|
139
|
-
* `_specifyComparable` property.
|
|
140
|
-
*/
|
|
141
114
|
get specifyComparable(): ((key: K) => Comparable) | undefined;
|
|
142
115
|
/**
|
|
116
|
+
* Time Complexity: O(1)
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
*
|
|
143
119
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
144
120
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
145
121
|
* being created.
|
|
146
122
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
147
123
|
* value associated with the key in the node being created.
|
|
148
|
-
* @returns The method is returning a new instance of the BSTNode class, casted as the
|
|
124
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
|
|
149
125
|
*/
|
|
150
|
-
createNode(key: K, value?: V):
|
|
126
|
+
createNode(key: K, value?: V): BSTNode<K, V>;
|
|
151
127
|
/**
|
|
152
128
|
* Time Complexity: O(1)
|
|
153
129
|
* Space Complexity: O(1)
|
|
154
130
|
*
|
|
155
|
-
* The
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @returns
|
|
160
|
-
* and properties inherited from the current instance.
|
|
131
|
+
* The function creates a new binary search tree with the specified options.
|
|
132
|
+
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
133
|
+
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
134
|
+
* following properties:
|
|
135
|
+
* @returns a new instance of the BST class with the provided options.
|
|
161
136
|
*/
|
|
162
|
-
createTree(options?: BSTOptions<K, V, R>): BST<K, V, R,
|
|
137
|
+
createTree(options?: BSTOptions<K, V, R>): BST<K, V, R, MK, MV, MR>;
|
|
163
138
|
/**
|
|
164
139
|
* Time Complexity: O(log n)
|
|
165
140
|
* Space Complexity: O(log n)
|
|
166
141
|
*
|
|
167
142
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
168
143
|
* it doesn't exist.
|
|
169
|
-
* @param {BTNRep<K, V,
|
|
170
|
-
* `
|
|
144
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
145
|
+
* `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
|
|
171
146
|
* entry, or raw element that needs to be ensured in the tree.
|
|
172
147
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
173
148
|
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
@@ -175,36 +150,42 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
175
150
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
176
151
|
* not be ensured.
|
|
177
152
|
*/
|
|
178
|
-
ensureNode(
|
|
153
|
+
ensureNode(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
|
|
179
154
|
/**
|
|
155
|
+
* Time Complexity: O(1)
|
|
156
|
+
* Space Complexity: O(1)
|
|
157
|
+
*
|
|
180
158
|
* The function checks if the input is an instance of the BSTNode class.
|
|
181
|
-
* @param {BTNRep<K, V,
|
|
182
|
-
* `
|
|
183
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
159
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
160
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
|
|
161
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
184
162
|
* an instance of the `BSTNode` class.
|
|
185
163
|
*/
|
|
186
|
-
isNode(
|
|
164
|
+
isNode(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>): keyNodeOrEntry is BSTNode<K, V>;
|
|
187
165
|
/**
|
|
188
|
-
*
|
|
166
|
+
* Time Complexity: O(1)
|
|
167
|
+
* Space Complexity: O(1)
|
|
168
|
+
*
|
|
169
|
+
* The function "override isValidKey" checks if a key is comparable based on a given comparator.
|
|
189
170
|
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
190
171
|
* type `K`.
|
|
191
|
-
* @returns The `override
|
|
172
|
+
* @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
|
|
192
173
|
* the result of the `isComparable` function with the condition `this._compare !==
|
|
193
174
|
* this._DEFAULT_COMPARATOR`.
|
|
194
175
|
*/
|
|
195
|
-
|
|
176
|
+
isValidKey(key: any): key is K;
|
|
196
177
|
/**
|
|
197
178
|
* Time Complexity: O(log n)
|
|
198
|
-
* Space Complexity: O(
|
|
179
|
+
* Space Complexity: O(log n)
|
|
199
180
|
*
|
|
200
181
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
201
|
-
* @param {BTNRep<K, V,
|
|
202
|
-
* `
|
|
182
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
|
|
183
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
|
|
203
184
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
204
185
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
205
186
|
* @returns a boolean value.
|
|
206
187
|
*/
|
|
207
|
-
add(
|
|
188
|
+
add(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>, value?: V): boolean;
|
|
208
189
|
/**
|
|
209
190
|
* Time Complexity: O(k log n)
|
|
210
191
|
* Space Complexity: O(k + log n)
|
|
@@ -226,34 +207,24 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
226
207
|
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
227
208
|
* successfully inserted into the data structure.
|
|
228
209
|
*/
|
|
229
|
-
addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V,
|
|
230
|
-
/**
|
|
231
|
-
* Time Complexity: O(n)
|
|
232
|
-
* Space Complexity: O(1)
|
|
233
|
-
*
|
|
234
|
-
* The `merge` function overrides the base class method by adding elements from another
|
|
235
|
-
* binary search tree.
|
|
236
|
-
* @param anotherTree - `anotherTree` is an instance of a Binary Search Tree (BST) with key type `K`,
|
|
237
|
-
* value type `V`, return type `R`, node type `NODE`, and tree type `TREE`.
|
|
238
|
-
*/
|
|
239
|
-
merge(anotherTree: this): void;
|
|
210
|
+
addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
240
211
|
/**
|
|
241
212
|
* Time Complexity: O(log n)
|
|
242
213
|
* Space Complexity: O(k + log n)
|
|
243
214
|
*
|
|
244
215
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
245
216
|
* on specified criteria.
|
|
246
|
-
* @param {BTNRep<K, V,
|
|
247
|
-
* `
|
|
217
|
+
* @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
218
|
+
* `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
|
|
248
219
|
* following types:
|
|
249
220
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
250
221
|
* search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
|
|
251
222
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
252
223
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
253
224
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
254
|
-
* extends `NodeCallback<
|
|
225
|
+
* extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
255
226
|
* argument and
|
|
256
|
-
* @param {BTNRep<K, V,
|
|
227
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
|
|
257
228
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
258
229
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
259
230
|
* node before proceeding with the search operation. If the `
|
|
@@ -265,19 +236,19 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
265
236
|
* structure based on the provided key, predicate, and other options. The search results are
|
|
266
237
|
* collected in an array and returned as the output of the method.
|
|
267
238
|
*/
|
|
268
|
-
search<C extends NodeCallback<
|
|
239
|
+
search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, callback?: C, startNode?: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
269
240
|
/**
|
|
270
241
|
* Time Complexity: O(log n)
|
|
271
|
-
* Space Complexity: O(n)
|
|
242
|
+
* Space Complexity: O(k + log n)
|
|
272
243
|
*
|
|
273
244
|
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
274
245
|
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
275
246
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
276
247
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
277
248
|
* function that is used to process each node that is found within the specified range during the
|
|
278
|
-
* search operation. It is of type `NodeCallback<
|
|
249
|
+
* search operation. It is of type `NodeCallback<BSTNode<K, V>>`, where `BSTNode<K, V>` is the type of nodes in the
|
|
279
250
|
* data structure.
|
|
280
|
-
* @param {BTNRep<K, V,
|
|
251
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
|
|
281
252
|
* function represents the node from which the search for nodes within the specified range will
|
|
282
253
|
* begin. It is the starting point for the range search operation.
|
|
283
254
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -287,15 +258,15 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
287
258
|
* @returns The `rangeSearch` function is returning the result of calling the `search` method with
|
|
288
259
|
* the specified parameters.
|
|
289
260
|
*/
|
|
290
|
-
rangeSearch<C extends NodeCallback<
|
|
261
|
+
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback?: C, startNode?: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
291
262
|
/**
|
|
292
263
|
* Time Complexity: O(log n)
|
|
293
|
-
* Space Complexity: O(
|
|
264
|
+
* Space Complexity: O(log n)
|
|
294
265
|
*
|
|
295
|
-
* This function retrieves a node based on a given
|
|
296
|
-
* @param {BTNRep<K, V,
|
|
297
|
-
* parameter can be of type `BTNRep<K, V,
|
|
298
|
-
* @param {
|
|
266
|
+
* This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
|
|
267
|
+
* @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
|
|
268
|
+
* parameter can be of type `BTNRep<K, V, BSTNode<K, V>>`, `R`, or `NodePredicate<BSTNode<K, V>>`.
|
|
269
|
+
* @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
|
|
299
270
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
300
271
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
301
272
|
* node of the binary search tree.
|
|
@@ -303,12 +274,12 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
303
274
|
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
304
275
|
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
305
276
|
* no value is provided when calling the method.
|
|
306
|
-
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<
|
|
307
|
-
* It is using the `getNodes` method to find the node based on the provided
|
|
277
|
+
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
|
|
278
|
+
* It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
|
|
308
279
|
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
309
280
|
* returns the first node found or `undefined` if no node is found.
|
|
310
281
|
*/
|
|
311
|
-
getNode(
|
|
282
|
+
getNode(keyNodeEntryOrPredicate: BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>, startNode?: BSTNOptKeyOrNode<K, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
|
|
312
283
|
/**
|
|
313
284
|
* Time complexity: O(n)
|
|
314
285
|
* Space complexity: O(n)
|
|
@@ -321,7 +292,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
321
292
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
322
293
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
323
294
|
* take one of the following values:
|
|
324
|
-
* @param {BTNRep<K, V,
|
|
295
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
325
296
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
326
297
|
* node entry. If not specified, the default value is the root of the tree.
|
|
327
298
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -329,7 +300,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
329
300
|
* following values:
|
|
330
301
|
* @returns The method is returning an array of the return type of the callback function.
|
|
331
302
|
*/
|
|
332
|
-
dfs<C extends NodeCallback<
|
|
303
|
+
dfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
333
304
|
/**
|
|
334
305
|
* Time complexity: O(n)
|
|
335
306
|
* Space complexity: O(n)
|
|
@@ -339,7 +310,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
339
310
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
340
311
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
341
312
|
* node being visited, and it can return a value of any type.
|
|
342
|
-
* @param {BTNRep<K, V,
|
|
313
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
343
314
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
344
315
|
* object. If no value is provided, the default value is the root of the tree.
|
|
345
316
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -347,7 +318,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
347
318
|
* the following values:
|
|
348
319
|
* @returns an array of the return type of the callback function.
|
|
349
320
|
*/
|
|
350
|
-
bfs<C extends NodeCallback<
|
|
321
|
+
bfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
351
322
|
/**
|
|
352
323
|
* Time complexity: O(n)
|
|
353
324
|
* Space complexity: O(n)
|
|
@@ -355,9 +326,9 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
355
326
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
356
327
|
* containing the results of the callback function applied to each level of the tree.
|
|
357
328
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
358
|
-
* `NodeCallback<
|
|
329
|
+
* `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
|
|
359
330
|
* tree during the iteration process.
|
|
360
|
-
* @param {BTNRep<K, V,
|
|
331
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
361
332
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
362
333
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
363
334
|
* value is provided, the root of
|
|
@@ -366,7 +337,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
366
337
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
367
338
|
* function.
|
|
368
339
|
*/
|
|
369
|
-
listLevels<C extends NodeCallback<
|
|
340
|
+
listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): ReturnType<C>[][];
|
|
370
341
|
/**
|
|
371
342
|
* Time complexity: O(n)
|
|
372
343
|
* Space complexity: O(n)
|
|
@@ -379,7 +350,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
379
350
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
380
351
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
381
352
|
* 0, or 1, where:
|
|
382
|
-
* @param {BTNRep<K, V,
|
|
353
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
|
|
383
354
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
384
355
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
385
356
|
* `targetNode` is provided,
|
|
@@ -388,7 +359,7 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
388
359
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
389
360
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
390
361
|
*/
|
|
391
|
-
lesserOrGreaterTraverse<C extends NodeCallback<
|
|
362
|
+
lesserOrGreaterTraverse<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, lesserOrGreater?: CP, targetNode?: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
392
363
|
/**
|
|
393
364
|
* Time complexity: O(n)
|
|
394
365
|
* Space complexity: O(n)
|
|
@@ -415,22 +386,70 @@ export declare class BST<K = any, V = any, R = object, NODE extends BSTNode<K, V
|
|
|
415
386
|
* @returns a boolean value.
|
|
416
387
|
*/
|
|
417
388
|
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
418
|
-
map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR, BSTNode<MK, MV, BSTNodeNested<MK, MV>>>;
|
|
419
389
|
/**
|
|
390
|
+
* Time complexity: O(n)
|
|
391
|
+
* Space complexity: O(n)
|
|
392
|
+
*
|
|
393
|
+
* The `map` function in TypeScript overrides the default map behavior for a binary search tree by
|
|
394
|
+
* applying a callback function to each entry and creating a new tree with the results.
|
|
395
|
+
* @param callback - A function that will be called for each entry in the BST. It takes four
|
|
396
|
+
* arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
|
|
397
|
+
* the BST itself.
|
|
398
|
+
* @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
|
|
399
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
|
|
400
|
+
* Search Tree (BST) being created in the `map` method. These options could include configuration
|
|
401
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
|
|
402
|
+
* the value of `this` that should be used when executing the `callback` function. It allows you to
|
|
403
|
+
* set the context or scope in which the callback function will be called. This can be useful when
|
|
404
|
+
* you want
|
|
405
|
+
* @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
|
|
406
|
+
* transformed by the provided callback function.
|
|
407
|
+
*/
|
|
408
|
+
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR>;
|
|
409
|
+
/**
|
|
410
|
+
* Time complexity: O(n)
|
|
411
|
+
* Space complexity: O(n)
|
|
412
|
+
*
|
|
413
|
+
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
414
|
+
* structure.
|
|
415
|
+
* @returns The `cloned` object is being returned.
|
|
416
|
+
*/
|
|
417
|
+
clone(): BST<K, V, R, MK, MV, MR>;
|
|
418
|
+
/**
|
|
419
|
+
* Time Complexity: O(1)
|
|
420
|
+
* Space Complexity: O(1)
|
|
421
|
+
*
|
|
420
422
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
421
|
-
* @param {BTNRep<K, V,
|
|
422
|
-
* type R or BTNRep<K, V,
|
|
423
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - A variable that can be of
|
|
424
|
+
* type R or BTNRep<K, V, BSTNode<K, V>>. It represents either a key, a node, an entry, or a raw
|
|
423
425
|
* element.
|
|
424
426
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
425
427
|
* value associated with a key in a key-value pair.
|
|
426
|
-
* @returns either a
|
|
428
|
+
* @returns either a BSTNode<K, V> object or undefined.
|
|
427
429
|
*/
|
|
428
|
-
protected
|
|
430
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>, value?: V): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
429
431
|
/**
|
|
432
|
+
* Time Complexity: O(1)
|
|
433
|
+
* Space Complexity: O(1)
|
|
434
|
+
*
|
|
430
435
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
431
436
|
* root.
|
|
432
|
-
* @param {OptNode<
|
|
437
|
+
* @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
|
|
438
|
+
*/
|
|
439
|
+
protected _setRoot(v: OptNode<BSTNode<K, V>>): void;
|
|
440
|
+
/**
|
|
441
|
+
* Time Complexity: O(1)
|
|
442
|
+
* Space Complexity: O(1)
|
|
443
|
+
*
|
|
444
|
+
* The _compare function compares two values using a specified comparator function and optionally
|
|
445
|
+
* reverses the result.
|
|
446
|
+
* @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
|
|
447
|
+
* `_compare` method.
|
|
448
|
+
* @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
|
|
449
|
+
* @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
|
|
450
|
+
* is true, it returns the negation of the result of calling the `_comparator` function with
|
|
451
|
+
* arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
|
|
452
|
+
* `_comparator` function with arguments `a` and `b`.
|
|
433
453
|
*/
|
|
434
|
-
protected _setRoot(v: OptNode<NODE>): void;
|
|
435
454
|
protected _compare(a: K, b: K): number;
|
|
436
455
|
}
|