heap-typed 1.51.7 → 1.51.9

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.
Files changed (56) hide show
  1. package/README.md +72 -80
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  5. package/dist/data-structures/binary-tree/avl-tree.js +90 -71
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
  7. package/dist/data-structures/binary-tree/binary-tree.js +492 -392
  8. package/dist/data-structures/binary-tree/bst.d.ts +204 -251
  9. package/dist/data-structures/binary-tree/bst.js +256 -358
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
  11. package/dist/data-structures/binary-tree/rb-tree.js +111 -119
  12. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
  13. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  14. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  15. package/dist/data-structures/graph/abstract-graph.js +10 -15
  16. package/dist/data-structures/hash/hash-map.d.ts +31 -38
  17. package/dist/data-structures/hash/hash-map.js +40 -55
  18. package/dist/data-structures/heap/heap.d.ts +1 -3
  19. package/dist/data-structures/queue/deque.d.ts +2 -3
  20. package/dist/data-structures/queue/deque.js +2 -3
  21. package/dist/data-structures/trie/trie.d.ts +1 -1
  22. package/dist/data-structures/trie/trie.js +1 -1
  23. package/dist/interfaces/binary-tree.d.ts +7 -7
  24. package/dist/types/common.d.ts +2 -3
  25. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
  26. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
  27. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
  28. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  29. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
  30. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
  31. package/dist/types/utils/utils.d.ts +10 -1
  32. package/dist/utils/utils.d.ts +2 -1
  33. package/dist/utils/utils.js +27 -1
  34. package/package.json +2 -2
  35. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
  36. package/src/data-structures/binary-tree/avl-tree.ts +109 -80
  37. package/src/data-structures/binary-tree/binary-tree.ts +556 -433
  38. package/src/data-structures/binary-tree/bst.ts +286 -375
  39. package/src/data-structures/binary-tree/rb-tree.ts +132 -125
  40. package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
  41. package/src/data-structures/graph/abstract-graph.ts +10 -10
  42. package/src/data-structures/hash/hash-map.ts +42 -49
  43. package/src/data-structures/heap/heap.ts +1 -1
  44. package/src/data-structures/queue/deque.ts +2 -2
  45. package/src/data-structures/queue/queue.ts +1 -1
  46. package/src/data-structures/trie/trie.ts +2 -2
  47. package/src/interfaces/binary-tree.ts +11 -9
  48. package/src/types/common.ts +2 -3
  49. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
  50. package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
  51. package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
  52. package/src/types/data-structures/binary-tree/bst.ts +6 -5
  53. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
  54. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
  55. package/src/types/utils/utils.ts +14 -1
  56. package/src/utils/utils.ts +20 -1
@@ -5,11 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntry } from '../../types';
9
- import { BSTNKeyOrNode, BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
8
+ import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparable, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
9
+ import { BTNEntry } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
12
- export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
12
+ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
13
13
  parent?: NODE;
14
14
  constructor(key: K, value?: V);
15
15
  protected _left?: NODE;
@@ -47,28 +47,22 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
47
47
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
48
48
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
49
49
  */
50
- export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
50
+ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
51
51
  /**
52
- * This is the constructor function for a TypeScript class that initializes a binary search tree with
53
- * optional keys or nodes or entries and options.
54
- * @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
55
- * to initialize the binary search tree with the provided keys, nodes, or entries.
56
- * @param [options] - The `options` parameter is an optional object that can contain additional
57
- * configuration options for the binary search tree. It can have the following properties:
52
+ * This is the constructor function for a Binary Search Tree class in TypeScript.
53
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
54
+ * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
55
+ * added to the binary search tree during the construction of the object.
56
+ * @param [options] - An optional object that contains additional options for the Binary Search Tree.
57
+ * It can include a comparator function that defines the order of the elements in the tree.
58
58
  */
59
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K>);
59
+ constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K, V, R>);
60
60
  protected _root?: NODE;
61
61
  /**
62
62
  * The function returns the root node of a tree structure.
63
63
  * @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
64
64
  */
65
65
  get root(): NODE | undefined;
66
- protected _variant: BSTVariant;
67
- /**
68
- * The function returns the value of the _variant property.
69
- * @returns The value of the `_variant` property.
70
- */
71
- get variant(): BSTVariant;
72
66
  /**
73
67
  * The function creates a new BSTNode with the given key and value and returns it.
74
68
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
@@ -81,115 +75,106 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
81
75
  /**
82
76
  * The function creates a new binary search tree with the specified options.
83
77
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
84
- * behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
85
- * partial object of type `BSTOptions<K>`.
86
- * @returns a new instance of the BST class, with the provided options merged with the default
87
- * options. The returned value is casted as TREE.
88
- */
89
- createTree(options?: Partial<BSTOptions<K>>): TREE;
90
- /**
91
- * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
92
- * otherwise it returns undefined.
93
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
94
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
95
- * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
96
- * @returns a node of type NODE or undefined.
78
+ * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
79
+ * following properties:
80
+ * @returns a new instance of the BST class with the provided options.
97
81
  */
98
- keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
82
+ createTree(options?: Partial<BSTOptions<K, V, R>>): TREE;
99
83
  /**
100
- * Time Complexity: O(log n)
101
- * Space Complexity: O(log n)
84
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
85
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
86
+ * type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
87
+ * element.
88
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
89
+ * value associated with a key in a key-value pair.
90
+ * @returns either a NODE object or undefined.
102
91
  */
92
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
103
93
  /**
104
94
  * Time Complexity: O(log n)
105
95
  * Space Complexity: O(log n)
106
96
  *
107
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
108
- * otherwise it returns the key itself.
109
- * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
110
- * `undefined`.
111
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
112
- * type of iteration to be performed. It has a default value of `'ITERATIVE'`.
113
- * @returns either a node object (NODE) or undefined.
114
- */
115
- ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
116
- /**
117
- * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
118
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
119
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
120
- */
121
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
122
- /**
123
- * Time Complexity: O(log n)
124
- * Space Complexity: O(1)
125
- */
97
+ * The function ensures the existence of a node in a data structure and returns it, or undefined if
98
+ * it doesn't exist.
99
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
100
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
101
+ * entry, or raw element that needs to be ensured in the tree.
102
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
103
+ * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
104
+ * value of `'ITERATIVE'`.
105
+ * @returns The method is returning either the node that was ensured or `undefined` if the node could
106
+ * not be ensured.
107
+ */
108
+ ensureNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
109
+ /**
110
+ * The function checks if the input is an instance of the BSTNode class.
111
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
112
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
113
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
114
+ * an instance of the `BSTNode` class.
115
+ */
116
+ isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
126
117
  /**
127
118
  * Time Complexity: O(log n)
128
119
  * Space Complexity: O(1)
129
120
  *
130
- * The `add` function adds a new node to a binary tree, updating the value if the key already exists
131
- * or inserting a new node if the key is unique.
132
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
133
- * @param {V} [value] - The `value` parameter represents the value associated with the key that is
134
- * being added to the binary tree.
135
- * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
136
- * node was not added.
121
+ * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
122
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
123
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
124
+ * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
125
+ * key in the binary search tree. If provided, it will be stored in the node along with the key.
126
+ * @returns a boolean value.
137
127
  */
138
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
128
+ add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
139
129
  /**
140
- * Time Complexity: O(k log n)
141
- * Space Complexity: O(k + log n)
130
+ * Time Complexity: O(log n)
131
+ * Space Complexity: O(log n)
142
132
  */
143
133
  /**
144
134
  * Time Complexity: O(k log n)
145
135
  * Space Complexity: O(k + log n)
146
136
  *
147
- * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
148
- * balancing the tree after each addition.
149
- * @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
150
- * the binary tree.
137
+ * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
138
+ * an array indicating whether each key or node was successfully inserted.
139
+ * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
140
+ * elements to be added to the data structure.
151
141
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
152
142
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
153
143
  * order. If not provided, undefined will be assigned as the value for each key or node.
154
- * @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
155
- * balanced or not. If set to true, the add operation will be balanced using a binary search tree
156
- * algorithm. If set to false, the add operation will not be balanced and the nodes will be added
157
- * in the order they appear in the input.
158
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
159
- * type of iteration to use when adding multiple keys or nodes. It has a default value of
160
- * `this.iterationType`, which suggests that it is a property of the current object.
161
- * @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
162
- */
163
- addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
144
+ * @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
145
+ * adding the elements. If set to true, the tree will be balanced using a binary search tree
146
+ * algorithm. If set to false, the elements will be added without balancing the tree. The default
147
+ * value is true.
148
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
149
+ * specifies the type of iteration to use when adding multiple keys or nodes to the binary search
150
+ * tree. It can have two possible values:
151
+ * @returns The function `addMany` returns an array of booleans indicating whether each element was
152
+ * successfully inserted into the data structure.
153
+ */
154
+ addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
164
155
  /**
165
- * Time Complexity: O(log n)
166
- * Space Complexity: O(k + log n)
167
- * /
168
-
169
- /**
170
156
  * Time Complexity: O(log n)
171
157
  * Space Complexity: O(k + log n)
172
158
  *
173
- * The function `getNodes` returns an array of nodes that match a given identifier, using either a
174
- * recursive or iterative approach.
159
+ * The `getNodes` function in TypeScript retrieves nodes from a binary tree based on a given
160
+ * identifier and callback function.
175
161
  * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
176
- * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
177
- * callback function `C`.
178
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
179
- * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
180
- * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
181
- * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
182
- * first node that matches the identifier. If set to true, the function will return an array
183
- * containing only the first matching node. If set to false (default), the function will continue
184
- * searching for all nodes that match the identifier and return an array containing
185
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
186
- * for the traversal. It can be either a key value or a node object. If it is undefined, the
187
- * traversal will start from the root of the tree.
188
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be
189
- * performed on the binary tree. It can have two possible values:
190
- * @returns The method returns an array of nodes (`NODE[]`).
191
- */
192
- getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
162
+ * want to search for in the binary tree. It can be of any type that is returned by the callback
163
+ * function.
164
+ * @param {C} callback - The `callback` parameter is a function that takes a node as input and
165
+ * returns a value. This value is used to identify the nodes that match the given identifier. The
166
+ * `callback` function is optional and defaults to `this._DEFAULT_CALLBACK`.
167
+ * @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
168
+ * or all matching nodes. If set to true, only the first matching node will be returned. If set to
169
+ * false, all matching nodes will be returned. The default value is false.
170
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
171
+ * point for the search in the binary tree. It can be either a node object, a key-value pair, or an
172
+ * entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
173
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
174
+ * iteration to be performed. It can have two possible values:
175
+ * @returns The method `getNodes` returns an array of `NODE` objects.
176
+ */
177
+ getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
193
178
  /**
194
179
  * Time Complexity: O(log n)
195
180
  * Space Complexity: O(1)
@@ -198,46 +183,45 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
198
183
  * Time Complexity: O(log n)
199
184
  * Space Complexity: O(1)
200
185
  *
201
- * The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
202
- * callback function.
203
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
204
- * that you want to search for in the binary search tree. It can be of any type that is compatible
205
- * with the type of nodes in the tree.
206
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
207
- * the tree. It is used to determine whether a node matches the given identifier. The `callback`
208
- * function should take a node as its parameter and return a value that can be compared to the
209
- * `identifier` parameter.
186
+ * The function `getNode` returns the first node that matches the given identifier and callback
187
+ * function in a binary search tree.
188
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
189
+ * want to search for in the binary search tree. It can be of any type that is compatible with the
190
+ * type returned by the callback function.
191
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
192
+ * node matches the desired criteria. It should be a function that takes a node as an argument and
193
+ * returns a boolean value indicating whether the node matches the criteria or not. If no callback is
194
+ * provided, the default callback will be
210
195
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
211
- * search tree. It can be either a key or a node. If it is a key, it will be converted to a node
212
- * using the `ensureNode` method. If it is not provided, the `root`
213
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
214
- * be performed when searching for nodes in the binary search tree. It is an optional parameter and
215
- * its default value is taken from the `iterationType` property of the class.
216
- * @returns The method is returning a value of type `NODE | null | undefined`.
196
+ * search tree. It can be either a key or a node. If it is a key, the search will start from the node
197
+ * with that key. If it is a node, the search will start from that node.
198
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
199
+ * of iteration to be performed when searching for nodes in the binary search tree. It can have one
200
+ * of the following values:
201
+ * @returns The method is returning a NODE object or undefined.
217
202
  */
218
- getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
203
+ getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: R | BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
219
204
  /**
220
- * Time Complexity: O(log n)
221
- * Space Complexity: O(1)
205
+ * Time Complexity: O(k log n)
206
+ * Space Complexity: O(k + log n)
222
207
  */
223
208
  /**
224
209
  * Time Complexity: O(log n)
225
210
  * Space Complexity: O(1)
226
211
  *
227
- * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
228
- * either recursive or iterative methods.
229
- * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
230
- * It is used to identify the node that we want to retrieve.
231
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
232
- * type of iteration to use when searching for a node in the binary tree. It can have two possible
233
- * values:
234
- * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
235
- * found in the binary tree. If no node is found, it returns `undefined`.
212
+ * The function `getNodeByKey` returns a node with a specific key from a tree data structure.
213
+ * @param {K} key - The key parameter is the value used to search for a specific node in the tree. It
214
+ * is typically a unique identifier or a value that can be used to determine the position of the node
215
+ * in the tree structure.
216
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
217
+ * parameter that specifies the type of iteration to be used when searching for a node in the tree.
218
+ * It has a default value of `'ITERATIVE'`.
219
+ * @returns The method is returning a NODE object or undefined.
236
220
  */
237
221
  getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
238
222
  /**
239
- * Time complexity: O(n)
240
- * Space complexity: O(n)
223
+ * Time Complexity: O(log n)
224
+ * Space Complexity: O(k + log n)
241
225
  */
242
226
  /**
243
227
  * Time complexity: O(n)
@@ -246,22 +230,23 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
246
230
  * The function overrides the depth-first search method and returns an array of the return types of
247
231
  * the callback function.
248
232
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
249
- * during the depth-first search traversal. It is an optional parameter and if not provided, a
250
- * default callback function will be used.
251
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
252
- * nodes are visited during the depth-first search. It can have one of the following values:
253
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
254
- * Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
255
- * value is provided, the DFS traversal will start from the root of the tree.
256
- * @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
257
- * iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
233
+ * during the depth-first search traversal. It is an optional parameter and defaults to
234
+ * `this._DEFAULT_CALLBACK`. The type `C` represents the type of the callback function.
235
+ * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
236
+ * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
237
+ * take one of the following values:
238
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
239
+ * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
240
+ * node entry. If not specified, the default value is the root of the tree.
241
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
242
+ * type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
258
243
  * following values:
259
244
  * @returns The method is returning an array of the return type of the callback function.
260
245
  */
261
- dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
246
+ dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
262
247
  /**
263
- * Time complexity: O(n)
264
- * Space complexity: O(n)
248
+ * Time Complexity: O(log n)
249
+ * Space Complexity: O(1)
265
250
  */
266
251
  /**
267
252
  * Time complexity: O(n)
@@ -270,155 +255,123 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
270
255
  * The function overrides the breadth-first search method and returns an array of the return types of
271
256
  * the callback function.
272
257
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
273
- * visited during the breadth-first search traversal. It is an optional parameter and if not
274
- * provided, a default callback function will be used.
275
- * @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
276
- * traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
277
- * the tree is used as the starting point.
278
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
279
- * be performed during the breadth-first search (BFS) traversal. It determines the order in which the
280
- * nodes are visited.
281
- * @returns The method is returning an array of the return type of the callback function.
282
- */
283
- bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
258
+ * visited during the breadth-first search. It should take a single argument, which is the current
259
+ * node being visited, and it can return a value of any type.
260
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
261
+ * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
262
+ * object. If no value is provided, the default value is the root of the tree.
263
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
264
+ * of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
265
+ * the following values:
266
+ * @returns an array of the return type of the callback function.
267
+ */
268
+ bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
284
269
  /**
285
- * Time complexity: O(n)
286
- * Space complexity: O(n)
270
+ * Time Complexity: O(log n)
271
+ * Space Complexity: O(1)
287
272
  */
288
273
  /**
289
274
  * Time complexity: O(n)
290
275
  * Space complexity: O(n)
291
276
  *
292
- * The function overrides the listLevels method and returns an array of arrays containing the return
293
- * type of the callback function for each level of the tree.
277
+ * The function overrides the listLevels method from the superclass and returns an array of arrays
278
+ * containing the results of the callback function applied to each level of the tree.
294
279
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
295
- * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
296
- * during the level listing process.
297
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
298
- * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
299
- * provided, the root of the binary tree is used as the starting point.
300
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
301
- * be performed on the tree. It determines the order in which the nodes are visited during the
302
- * iteration.
280
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
281
+ * tree during the iteration process.
282
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
283
+ * point for listing the levels of the binary tree. It can be either a root node of the tree, a
284
+ * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
285
+ * value is provided, the root of
286
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
287
+ * of iteration to be performed on the tree. It can have one of the following values:
303
288
  * @returns The method is returning a two-dimensional array of the return type of the callback
304
289
  * function.
305
290
  */
306
- listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
307
- /**
308
- * Time Complexity: O(log n)
309
- * Space Complexity: O(1)
310
- */
291
+ listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
311
292
  /**
312
- * Time Complexity: O(log n)
313
- * Space Complexity: O(1)
314
- *
315
- * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
316
- * leftmost node if the comparison result is greater than.
317
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
318
- * type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
319
- * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
320
- * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
321
- * the key of the leftmost node if the comparison result is greater than, and the key of the
322
- * rightmost node otherwise. If no node is found, it returns 0.
323
- */
324
- lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): K | undefined;
325
- /**
326
- * Time Complexity: O(log n)
327
- * Space Complexity: O(log n)
293
+ * Time complexity: O(n)
294
+ * Space complexity: O(n)
328
295
  */
329
296
  /**
330
- * Time Complexity: O(log n)
331
- * Space Complexity: O(log n)
297
+ * Time complexity: O(n)
298
+ * Space complexity: O(n)
332
299
  *
333
- * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
334
- * are either lesser or greater than a target node, depending on the specified comparison type.
300
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
301
+ * each node that meets a certain condition based on a target node and a comparison value.
335
302
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
336
- * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
337
- * parameter of type `NODE` (the node type) and returns a value of any type.
303
+ * that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
304
+ * which is the current node being traversed, and returns a value of any type.
338
305
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
339
- * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
340
- * `CP`, which is a custom type representing the comparison operator. The possible values for
341
- * `lesserOrGreater` are
342
- * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
343
- * binary tree that you want to traverse from. It can be specified either by its key, by the node
344
- * object itself, or it can be left undefined to start the traversal from the root of the tree.
345
- * @param iterationType - The `iterationType` parameter determines the type of traversal to be
346
- * performed on the binary tree. It can have two possible values:
306
+ * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
307
+ * 0, or 1, where:
308
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
309
+ * the binary tree that you want to start traversing from. It can be specified either by providing
310
+ * the key of the node, the node itself, or an entry containing the key and value of the node. If no
311
+ * `targetNode` is provided,
312
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
313
+ * traversal to be performed on the binary tree. It can have two possible values:
347
314
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
348
315
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
349
316
  */
350
- lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
317
+ lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
351
318
  /**
352
- * Time Complexity: O(log n)
353
- * Space Complexity: O(log n)
319
+ * Time complexity: O(n)
320
+ * Space complexity: O(n)
354
321
  */
355
322
  /**
356
- * Time Complexity: O(log n)
357
- * Space Complexity: O(log n)
323
+ * Time complexity: O(n)
324
+ * Space complexity: O(n)
358
325
  *
359
- * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
360
- * ensures the tree is perfectly balanced.
361
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
362
- * type of iteration to use when building a balanced binary search tree. It can have two possible
363
- * values:
326
+ * The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
327
+ * the binary search tree is perfectly balanced, otherwise it returns `false`.
328
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
329
+ * specifies the type of iteration to use when building a balanced binary search tree. It has a
330
+ * default value of `this.iterationType`, which means it will use the iteration type specified in the
331
+ * current instance of the class.
364
332
  * @returns The function `perfectlyBalance` returns a boolean value.
365
333
  */
366
334
  perfectlyBalance(iterationType?: IterationType): boolean;
367
335
  /**
368
- * Balancing Adjustment:
369
- * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
370
- * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
371
- *
372
- * Use Cases and Efficiency:
373
- * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
374
- * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
375
- */
376
- /**
377
- * Time Complexity: O(n)
378
- * Space Complexity: O(log n)
336
+ * Time complexity: O(n)
337
+ * Space complexity: O(n)
379
338
  */
380
339
  /**
381
340
  * Time Complexity: O(n)
382
341
  * Space Complexity: O(log n)
383
342
  *
384
- * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
385
- * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
386
- * to check if the AVL tree is balanced. It can have two possible values:
343
+ * The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
344
+ * iterative approach.
345
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
346
+ * specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
347
+ * value of `this.iterationType`, which means it will use the iteration type specified in the current
348
+ * instance of the AVL tree.
387
349
  * @returns a boolean value.
388
350
  */
389
351
  isAVLBalanced(iterationType?: IterationType): boolean;
390
352
  /**
391
- * The function sets the root property of an object and updates the parent property of the new root.
392
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
393
- * can either be an object of type `NODE` or it can be `undefined`.
353
+ * Time complexity: O(n)
354
+ * Space complexity: O(n)
394
355
  */
395
- protected _setRoot(v: NODE | undefined): void;
356
+ protected _DEFAULT_COMPARATOR: (a: K, b: K) => number;
396
357
  /**
397
- * The function compares two values using a comparator function and returns whether the first value
398
- * is greater than, less than, or equal to the second value.
399
- * @param {K} a - The parameter "a" is of type K.
400
- * @param {K} b - The parameter "b" in the above code represents a K.
401
- * @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
402
- * than), 'LT' (less than), or 'EQ' (equal).
403
- */
404
- protected _compare(a: K, b: K): CP;
405
- /**
406
- * The function `_lt` compares two values `a` and `b` using an extractor function and returns true if
407
- * `a` is less than `b` based on the specified variant.
408
- * @param {K} a - The parameter "a" is of type "K", which means it can be any type. It represents the
409
- * first value to be compared in the function.
410
- * @param {K} b - The parameter `b` is of type `K`, which means it can be any type. It is used as one
411
- * of the arguments for the comparison in the `_lt` function.
412
- * @returns a boolean value.
358
+ * Time complexity: O(n)
359
+ * Space complexity: O(n)
413
360
  */
414
- protected _lt(a: K, b: K): boolean;
361
+ protected _comparator: Comparator<K>;
415
362
  /**
416
- * The function compares two values using a custom extractor function and returns true if the first
417
- * value is greater than the second value.
418
- * @param {K} a - The parameter "a" is of type K, which means it can be any type.
419
- * @param {K} b - The parameter "b" is of type K, which means it can be any type. It is used as one
420
- * of the arguments for the comparison in the function.
421
- * @returns a boolean value.
363
+ * Time Complexity: O(n)
364
+ * Space Complexity: O(log n)
422
365
  */
423
- protected _gt(a: K, b: K): boolean;
366
+ /**
367
+ * The function returns the value of the _comparator property.
368
+ * @returns The `_comparator` property is being returned.
369
+ */
370
+ get comparator(): Comparator<K>;
371
+ /**
372
+ * The function sets the root of a tree-like structure and updates the parent property of the new
373
+ * root.
374
+ * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
375
+ */
376
+ protected _setRoot(v: NODE | undefined): void;
424
377
  }