graph-typed 1.54.0 → 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 -177
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -340
- package/dist/data-structures/binary-tree/avl-tree.d.ts +102 -57
- package/dist/data-structures/binary-tree/avl-tree.js +110 -47
- 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 +240 -190
- package/dist/data-structures/binary-tree/binary-tree.js +269 -240
- package/dist/data-structures/binary-tree/bst.d.ts +145 -112
- package/dist/data-structures/binary-tree/bst.js +180 -129
- 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 +100 -82
- package/dist/data-structures/binary-tree/red-black-tree.js +115 -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 -174
- package/dist/data-structures/binary-tree/tree-multi-map.js +142 -377
- 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 +8 -8
- 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 +0 -3
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -3
- 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 -4
- 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 -4
- 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 +155 -393
- package/src/data-structures/binary-tree/avl-tree.ts +144 -93
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +433 -405
- package/src/data-structures/binary-tree/bst.ts +261 -239
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +163 -134
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +161 -429
- 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 -24
- 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 +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -5
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -6
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -6
|
@@ -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
|
-
_left?: OptNodeOrNull<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(): OptNodeOrNull<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: OptNodeOrNull<NODE>);
|
|
27
|
-
_right?: OptNodeOrNull<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(): OptNodeOrNull<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,64 +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, MK = any, MV = any, MR = object
|
|
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> {
|
|
107
97
|
/**
|
|
108
|
-
* This
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
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:
|
|
114
105
|
*/
|
|
115
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<
|
|
116
|
-
protected _root?:
|
|
117
|
-
|
|
118
|
-
* The function returns the root node of a tree structure.
|
|
119
|
-
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
120
|
-
*/
|
|
121
|
-
get root(): OptNode<NODE>;
|
|
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;
|
|
111
|
+
protected _comparator: Comparator<K>;
|
|
112
|
+
get comparator(): Comparator<K>;
|
|
113
|
+
protected _specifyComparable?: (key: K) => Comparable;
|
|
114
|
+
get specifyComparable(): ((key: K) => Comparable) | undefined;
|
|
129
115
|
/**
|
|
116
|
+
* Time Complexity: O(1)
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
*
|
|
130
119
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
131
120
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
132
121
|
* being created.
|
|
133
122
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
134
123
|
* value associated with the key in the node being created.
|
|
135
|
-
* @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.
|
|
136
125
|
*/
|
|
137
|
-
createNode(key: K, value?: V):
|
|
126
|
+
createNode(key: K, value?: V): BSTNode<K, V>;
|
|
138
127
|
/**
|
|
128
|
+
* Time Complexity: O(1)
|
|
129
|
+
* Space Complexity: O(1)
|
|
130
|
+
*
|
|
139
131
|
* The function creates a new binary search tree with the specified options.
|
|
140
132
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
141
133
|
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
142
134
|
* following properties:
|
|
143
135
|
* @returns a new instance of the BST class with the provided options.
|
|
144
136
|
*/
|
|
145
|
-
createTree(options?: BSTOptions<K, V, R>):
|
|
146
|
-
/**
|
|
147
|
-
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
148
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
|
|
149
|
-
* type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
150
|
-
* element.
|
|
151
|
-
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
152
|
-
* value associated with a key in a key-value pair.
|
|
153
|
-
* @returns either a NODE object or undefined.
|
|
154
|
-
*/
|
|
155
|
-
protected _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNode<NODE>, V | undefined];
|
|
137
|
+
createTree(options?: BSTOptions<K, V, R>): BST<K, V, R, MK, MV, MR>;
|
|
156
138
|
/**
|
|
157
139
|
* Time Complexity: O(log n)
|
|
158
140
|
* Space Complexity: O(log n)
|
|
159
141
|
*
|
|
160
142
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
161
143
|
* it doesn't exist.
|
|
162
|
-
* @param {BTNRep<K, V,
|
|
163
|
-
* `
|
|
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,
|
|
164
146
|
* entry, or raw element that needs to be ensured in the tree.
|
|
165
147
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
166
148
|
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
@@ -168,36 +150,42 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
168
150
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
169
151
|
* not be ensured.
|
|
170
152
|
*/
|
|
171
|
-
ensureNode(
|
|
153
|
+
ensureNode(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
|
|
172
154
|
/**
|
|
155
|
+
* Time Complexity: O(1)
|
|
156
|
+
* Space Complexity: O(1)
|
|
157
|
+
*
|
|
173
158
|
* The function checks if the input is an instance of the BSTNode class.
|
|
174
|
-
* @param {BTNRep<K, V,
|
|
175
|
-
* `
|
|
176
|
-
* @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
|
|
177
162
|
* an instance of the `BSTNode` class.
|
|
178
163
|
*/
|
|
179
|
-
isNode(
|
|
164
|
+
isNode(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>): keyNodeOrEntry is BSTNode<K, V>;
|
|
180
165
|
/**
|
|
181
|
-
*
|
|
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.
|
|
182
170
|
* @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
|
|
183
171
|
* type `K`.
|
|
184
|
-
* @returns The `override
|
|
172
|
+
* @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
|
|
185
173
|
* the result of the `isComparable` function with the condition `this._compare !==
|
|
186
174
|
* this._DEFAULT_COMPARATOR`.
|
|
187
175
|
*/
|
|
188
|
-
|
|
176
|
+
isValidKey(key: any): key is K;
|
|
189
177
|
/**
|
|
190
178
|
* Time Complexity: O(log n)
|
|
191
|
-
* Space Complexity: O(
|
|
179
|
+
* Space Complexity: O(log n)
|
|
192
180
|
*
|
|
193
181
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
194
|
-
* @param {BTNRep<K, V,
|
|
195
|
-
* `
|
|
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>>`.
|
|
196
184
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
197
185
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
198
186
|
* @returns a boolean value.
|
|
199
187
|
*/
|
|
200
|
-
add(
|
|
188
|
+
add(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>, value?: V): boolean;
|
|
201
189
|
/**
|
|
202
190
|
* Time Complexity: O(k log n)
|
|
203
191
|
* Space Complexity: O(k + log n)
|
|
@@ -219,24 +207,24 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
219
207
|
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
220
208
|
* successfully inserted into the data structure.
|
|
221
209
|
*/
|
|
222
|
-
addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V,
|
|
210
|
+
addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
223
211
|
/**
|
|
224
212
|
* Time Complexity: O(log n)
|
|
225
213
|
* Space Complexity: O(k + log n)
|
|
226
214
|
*
|
|
227
215
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
228
216
|
* on specified criteria.
|
|
229
|
-
* @param {BTNRep<K, V,
|
|
230
|
-
* `
|
|
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
|
|
231
219
|
* following types:
|
|
232
220
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
233
221
|
* search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
|
|
234
222
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
235
223
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
236
224
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
237
|
-
* extends `NodeCallback<
|
|
225
|
+
* extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
238
226
|
* argument and
|
|
239
|
-
* @param {BTNRep<K, V,
|
|
227
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
|
|
240
228
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
241
229
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
242
230
|
* node before proceeding with the search operation. If the `
|
|
@@ -248,19 +236,19 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
248
236
|
* structure based on the provided key, predicate, and other options. The search results are
|
|
249
237
|
* collected in an array and returned as the output of the method.
|
|
250
238
|
*/
|
|
251
|
-
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>[];
|
|
252
240
|
/**
|
|
253
241
|
* Time Complexity: O(log n)
|
|
254
|
-
* Space Complexity: O(n)
|
|
242
|
+
* Space Complexity: O(k + log n)
|
|
255
243
|
*
|
|
256
244
|
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
257
245
|
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
258
246
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
259
247
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
260
248
|
* function that is used to process each node that is found within the specified range during the
|
|
261
|
-
* 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
|
|
262
250
|
* data structure.
|
|
263
|
-
* @param {BTNRep<K, V,
|
|
251
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
|
|
264
252
|
* function represents the node from which the search for nodes within the specified range will
|
|
265
253
|
* begin. It is the starting point for the range search operation.
|
|
266
254
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -270,15 +258,15 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
270
258
|
* @returns The `rangeSearch` function is returning the result of calling the `search` method with
|
|
271
259
|
* the specified parameters.
|
|
272
260
|
*/
|
|
273
|
-
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>[];
|
|
274
262
|
/**
|
|
275
263
|
* Time Complexity: O(log n)
|
|
276
|
-
* Space Complexity: O(
|
|
264
|
+
* Space Complexity: O(log n)
|
|
277
265
|
*
|
|
278
|
-
* This function retrieves a node based on a given
|
|
279
|
-
* @param {BTNRep<K, V,
|
|
280
|
-
* parameter can be of type `BTNRep<K, V,
|
|
281
|
-
* @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
|
|
282
270
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
283
271
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
284
272
|
* node of the binary search tree.
|
|
@@ -286,12 +274,12 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
286
274
|
* parameter that specifies the type of iteration to be used. It has a default value of
|
|
287
275
|
* `this.iterationType`, which means it will use the iteration type defined in the class instance if
|
|
288
276
|
* no value is provided when calling the method.
|
|
289
|
-
* @returns The `getNode` method is returning an optional binary search tree node (`OptNode<
|
|
290
|
-
* 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
|
|
291
279
|
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
292
280
|
* returns the first node found or `undefined` if no node is found.
|
|
293
281
|
*/
|
|
294
|
-
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>>;
|
|
295
283
|
/**
|
|
296
284
|
* Time complexity: O(n)
|
|
297
285
|
* Space complexity: O(n)
|
|
@@ -304,7 +292,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
304
292
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
305
293
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
306
294
|
* take one of the following values:
|
|
307
|
-
* @param {BTNRep<K, V,
|
|
295
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
308
296
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
309
297
|
* node entry. If not specified, the default value is the root of the tree.
|
|
310
298
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -312,7 +300,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
312
300
|
* following values:
|
|
313
301
|
* @returns The method is returning an array of the return type of the callback function.
|
|
314
302
|
*/
|
|
315
|
-
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>[];
|
|
316
304
|
/**
|
|
317
305
|
* Time complexity: O(n)
|
|
318
306
|
* Space complexity: O(n)
|
|
@@ -322,7 +310,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
322
310
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
323
311
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
324
312
|
* node being visited, and it can return a value of any type.
|
|
325
|
-
* @param {BTNRep<K, V,
|
|
313
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
326
314
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
327
315
|
* object. If no value is provided, the default value is the root of the tree.
|
|
328
316
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -330,7 +318,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
330
318
|
* the following values:
|
|
331
319
|
* @returns an array of the return type of the callback function.
|
|
332
320
|
*/
|
|
333
|
-
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>[];
|
|
334
322
|
/**
|
|
335
323
|
* Time complexity: O(n)
|
|
336
324
|
* Space complexity: O(n)
|
|
@@ -338,9 +326,9 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
338
326
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
339
327
|
* containing the results of the callback function applied to each level of the tree.
|
|
340
328
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
341
|
-
* `NodeCallback<
|
|
329
|
+
* `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
|
|
342
330
|
* tree during the iteration process.
|
|
343
|
-
* @param {BTNRep<K, V,
|
|
331
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
344
332
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
345
333
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
346
334
|
* value is provided, the root of
|
|
@@ -349,7 +337,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
349
337
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
350
338
|
* function.
|
|
351
339
|
*/
|
|
352
|
-
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>[][];
|
|
353
341
|
/**
|
|
354
342
|
* Time complexity: O(n)
|
|
355
343
|
* Space complexity: O(n)
|
|
@@ -362,7 +350,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
362
350
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
363
351
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
364
352
|
* 0, or 1, where:
|
|
365
|
-
* @param {BTNRep<K, V,
|
|
353
|
+
* @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
|
|
366
354
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
367
355
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
368
356
|
* `targetNode` is provided,
|
|
@@ -371,7 +359,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
371
359
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
372
360
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
373
361
|
*/
|
|
374
|
-
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>[];
|
|
375
363
|
/**
|
|
376
364
|
* Time complexity: O(n)
|
|
377
365
|
* Space complexity: O(n)
|
|
@@ -398,25 +386,70 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
398
386
|
* @returns a boolean value.
|
|
399
387
|
*/
|
|
400
388
|
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
401
|
-
protected _comparator: Comparator<K>;
|
|
402
389
|
/**
|
|
403
|
-
*
|
|
404
|
-
*
|
|
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.
|
|
405
407
|
*/
|
|
406
|
-
|
|
407
|
-
protected _specifyComparable?: (key: K) => Comparable;
|
|
408
|
+
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR>;
|
|
408
409
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
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.
|
|
412
416
|
*/
|
|
413
|
-
|
|
417
|
+
clone(): BST<K, V, R, MK, MV, MR>;
|
|
414
418
|
/**
|
|
419
|
+
* Time Complexity: O(1)
|
|
420
|
+
* Space Complexity: O(1)
|
|
421
|
+
*
|
|
422
|
+
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
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
|
|
425
|
+
* element.
|
|
426
|
+
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
427
|
+
* value associated with a key in a key-value pair.
|
|
428
|
+
* @returns either a BSTNode<K, V> object or undefined.
|
|
429
|
+
*/
|
|
430
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: BTNRep<K, V, BSTNode<K, V>>, value?: V): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
431
|
+
/**
|
|
432
|
+
* Time Complexity: O(1)
|
|
433
|
+
* Space Complexity: O(1)
|
|
434
|
+
*
|
|
415
435
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
416
436
|
* root.
|
|
417
|
-
* @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`.
|
|
418
453
|
*/
|
|
419
|
-
protected _setRoot(v: OptNode<NODE>): void;
|
|
420
454
|
protected _compare(a: K, b: K): number;
|
|
421
|
-
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR>;
|
|
422
455
|
}
|