data-structure-typed 1.37.3 → 1.37.4

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 (28) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +42 -34
  3. package/dist/data-structures/binary-tree/avl-tree.js +42 -34
  4. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +265 -168
  6. package/dist/data-structures/binary-tree/binary-tree.js +257 -170
  7. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/bst.d.ts +104 -59
  9. package/dist/data-structures/binary-tree/bst.js +105 -60
  10. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  12. package/dist/data-structures/binary-tree/tree-multiset.js +47 -39
  13. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  14. package/lib/data-structures/binary-tree/avl-tree.d.ts +42 -34
  15. package/lib/data-structures/binary-tree/avl-tree.js +42 -34
  16. package/lib/data-structures/binary-tree/binary-tree.d.ts +265 -168
  17. package/lib/data-structures/binary-tree/binary-tree.js +257 -170
  18. package/lib/data-structures/binary-tree/bst.d.ts +104 -59
  19. package/lib/data-structures/binary-tree/bst.js +105 -60
  20. package/lib/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  21. package/lib/data-structures/binary-tree/tree-multiset.js +47 -39
  22. package/package.json +5 -5
  23. package/src/data-structures/binary-tree/avl-tree.ts +42 -34
  24. package/src/data-structures/binary-tree/binary-tree.ts +270 -174
  25. package/src/data-structures/binary-tree/bst.ts +108 -66
  26. package/src/data-structures/binary-tree/tree-multiset.ts +47 -39
  27. package/umd/bundle.min.js +1 -1
  28. package/umd/bundle.min.js.map +1 -1
@@ -14,79 +14,119 @@ export declare class BSTNode<V = any, FAMILY extends BSTNode<V, FAMILY> = BSTNod
14
14
  }
15
15
  export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N> implements IBinaryTree<N> {
16
16
  /**
17
- * The constructor function initializes a binary search tree object with an optional comparator function.
18
- * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
17
+ * The constructor function initializes a binary search tree object with an optional comparator
18
+ * function.
19
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the
20
+ * binary search tree.
19
21
  */
20
22
  constructor(options?: BSTOptions);
21
23
  /**
22
24
  * The function creates a new binary search tree node with the given key and value.
23
- * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
24
- * identify each node in the binary tree.
25
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
26
- * that will be stored in the node.
25
+ * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
26
+ * the new node. It is used to determine the position of the node in the binary search tree.
27
+ * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It
28
+ * represents the value associated with the node in a binary search tree.
27
29
  * @returns a new instance of the BSTNode class with the specified key and value.
28
30
  */
29
31
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
30
32
  /**
31
- * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
32
- * node with the same ID.
33
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
34
- * (which represents a binary tree node) or `null`.
35
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
36
- * being added to the binary search tree.
37
- * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
33
+ * The `add` function in a binary search tree class inserts a new node with a given key and value
34
+ * into the tree.
35
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
36
+ * `BinaryTreeNodeKey` (which can be a number or a string), a `BSTNode` object, or `null`.
37
+ * @param [val] - The `val` parameter is the value to be assigned to the new node being added to the
38
+ * binary search tree.
39
+ * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
40
+ * was not added or if the parameters were invalid, it returns null or undefined.
38
41
  */
39
42
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
40
43
  /**
41
- * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
42
- * manner.
43
- * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
44
- * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
45
- * to the binary search tree.
44
+ * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
45
+ * maintaining balance.
46
+ * @param {[BinaryTreeNodeKey | N, N['val']][]} arr - The `arr` parameter in the `addMany` function
47
+ * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
48
+ * array of `BinaryTreeNodeKey` or `N` (which represents the node type in the binary search tree) or
49
+ * `null
46
50
  * @param {N['val'][]} data - The values of tree nodes
47
51
  * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
48
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a
49
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
52
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used.
53
+ * It can have two possible values:
54
+ * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values.
50
55
  */
51
56
  addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd?: boolean, iterationType?: IterationType): (N | null | undefined)[];
52
57
  /**
53
- * The function returns the first node in a binary tree that matches the given property name and value.
54
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
55
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
56
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
57
- * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
58
- * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
58
+ * The function returns the first node in the binary tree that matches the given node property and
59
+ * callback.
60
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is used to specify the
61
+ * property of the binary tree node that you want to search for. It can be either a specific key
62
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
63
+ * whether a node matches the desired property.
64
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
65
+ * matches the desired property. It takes a node as input and returns a boolean value indicating
66
+ * whether the node matches the property or not. If no callback function is provided, the default
67
+ * callback function `_defaultCallbackByKey` is used
68
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
69
+ * the root node from which the search should begin.
70
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
71
+ * be performed when searching for nodes in the binary tree. It can have one of the following values:
72
+ * @returns either the first node that matches the given nodeProperty and callback, or null if no
73
+ * matching node is found.
59
74
  */
60
- get(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>): N | null;
75
+ get(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>, beginRoot?: N | null, iterationType?: IterationType): N | null;
61
76
  /**
62
- * lastKey returns the last key in a binary tree. If the binary tree is empty, it returns 0.
63
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to begin
64
- * the search for the last key.
65
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a recursive or iterative approach to search for the last key.
77
+ * The function `lastKey` returns the key of the rightmost node if the comparison result is less
78
+ * than, the key of the leftmost node if the comparison result is greater than, and the key of the
79
+ * rightmost node otherwise.
80
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting point for finding the last
81
+ * key in a binary tree. It represents the root node of the subtree from which the search for the
82
+ * last key should begin. If no specific `beginRoot` is provided, the search will start from the root
83
+ * of the entire binary
84
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
85
+ * be performed when finding the last key. It determines whether the iteration should be performed in
86
+ * pre-order, in-order, or post-order.
87
+ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
88
+ * the key of the leftmost node if the comparison result is greater than, and the key of the
89
+ * rightmost node otherwise. If no node is found, it returns 0.
66
90
  */
67
91
  lastKey(beginRoot?: N | null, iterationType?: IterationType): BinaryTreeNodeKey;
68
92
  /**
69
- * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
70
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
71
- * `N` type. It represents the property of the binary tree node that you want to compare with.
72
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
73
- * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
74
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
75
- * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
76
- * is set to `true`, the function will return an array with only one node (if
77
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to
78
- * @param iterationType
79
- * @returns an array of nodes (type N).
93
+ * The function `getNodes` retrieves nodes from a binary tree based on a given node property or key,
94
+ * using either recursive or iterative traversal.
95
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter represents the property
96
+ * of the binary tree node that you want to search for. It can be either a `BinaryTreeNodeKey` or a
97
+ * generic type `N`.
98
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
99
+ * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
100
+ * included in the result. The default value for `callback` is `this._defaultCallbackByKey`, which is
101
+ * a
102
+ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
103
+ * the first node that matches the nodeProperty. If set to true, the function will return an array
104
+ * containing only that node. If set to false (default), the function will continue the traversal and
105
+ * return an array containing all nodes that match the node
106
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the traversal. It
107
+ * specifies the root node of the binary tree from which the traversal should begin. If `beginRoot`
108
+ * is `null`, an empty array will be returned.
109
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
110
+ * traverse the binary tree. It can have one of the following values:
111
+ * @returns an array of nodes (N[]).
80
112
  */
81
113
  getNodes(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
82
114
  /**
83
- * The `lesserOrGreaterTraverse` function adds a delta value to the specified property of all nodes in a binary tree that
84
- * have a greater value than a given node.
85
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
86
- * represents the node in the binary tree to which the delta value will be added.
87
- * @param lesserOrGreater - The `lesserOrGreater` parameter is an optional parameter that specifies whether the delta
88
- * @param targetNode - The `targetNode` parameter is an optional parameter that specifies the node in the binary tree
89
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a
115
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
116
+ * nodes that have a key value lesser or greater than a target key value.
117
+ * @param callback - The `callback` parameter is a function that will be called for each node that
118
+ * meets the condition specified by the `lesserOrGreater` parameter. It takes a node as an argument
119
+ * and returns a value.
120
+ * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
121
+ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It can take one
122
+ * of the following values:
123
+ * @param {N | BinaryTreeNodeKey | null} targetNode - The `targetNode` parameter in the
124
+ * `lesserOrGreaterTraverse` function is used to specify the node from which the traversal should
125
+ * start. It can be either a reference to a specific node (`N`), the key of a node
126
+ * (`BinaryTreeNodeKey`), or `null` to
127
+ * @param iterationType - The `iterationType` parameter determines whether the traversal should be
128
+ * done recursively or iteratively. It can have two possible values:
129
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
90
130
  */
91
131
  lesserOrGreaterTraverse(callback?: MapCallback<N>, lesserOrGreater?: CP, targetNode?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): MapCallbackReturn<N>;
92
132
  /**
@@ -99,24 +139,29 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends Binar
99
139
  * 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).
100
140
  */
101
141
  /**
102
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
103
- * constructs a balanced binary search tree using either a recursive or iterative approach.
104
- * @returns The function `perfectlyBalance()` returns a boolean value.
142
+ * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
143
+ * ensures the tree is perfectly balanced.
144
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
145
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
146
+ * values:
147
+ * @returns The function `perfectlyBalance` returns a boolean value.
105
148
  */
106
149
  perfectlyBalance(iterationType?: IterationType): boolean;
107
150
  /**
108
- * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
151
+ * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
152
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
153
+ * to check if the AVL tree is balanced. It can have two possible values:
109
154
  * @returns a boolean value.
110
155
  */
111
156
  isAVLBalanced(iterationType?: IterationType): boolean;
112
157
  protected _comparator: BSTComparator;
113
158
  /**
114
- * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
115
- * greater than, less than, or equal to the second ID.
116
- * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
117
- * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
118
- * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
119
- * than), or CP.eq (equal).
159
+ * The function compares two values using a comparator function and returns whether the first value
160
+ * is greater than, less than, or equal to the second value.
161
+ * @param {BinaryTreeNodeKey} a - The parameter "a" is of type BinaryTreeNodeKey.
162
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code represents a BinaryTreeNodeKey.
163
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
164
+ * than), CP.lt (less than), or CP.eq (equal).
120
165
  */
121
166
  protected _compare(a: BinaryTreeNodeKey, b: BinaryTreeNodeKey): CP;
122
167
  }
@@ -8,8 +8,10 @@ export class BSTNode extends BinaryTreeNode {
8
8
  }
9
9
  export class BST extends BinaryTree {
10
10
  /**
11
- * The constructor function initializes a binary search tree object with an optional comparator function.
12
- * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
11
+ * The constructor function initializes a binary search tree object with an optional comparator
12
+ * function.
13
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the
14
+ * binary search tree.
13
15
  */
14
16
  constructor(options) {
15
17
  super(options);
@@ -23,23 +25,24 @@ export class BST extends BinaryTree {
23
25
  }
24
26
  /**
25
27
  * The function creates a new binary search tree node with the given key and value.
26
- * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
27
- * identify each node in the binary tree.
28
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
29
- * that will be stored in the node.
28
+ * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
29
+ * the new node. It is used to determine the position of the node in the binary search tree.
30
+ * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It
31
+ * represents the value associated with the node in a binary search tree.
30
32
  * @returns a new instance of the BSTNode class with the specified key and value.
31
33
  */
32
34
  createNode(key, val) {
33
35
  return new BSTNode(key, val);
34
36
  }
35
37
  /**
36
- * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
37
- * node with the same ID.
38
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
39
- * (which represents a binary tree node) or `null`.
40
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
41
- * being added to the binary search tree.
42
- * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
38
+ * The `add` function in a binary search tree class inserts a new node with a given key and value
39
+ * into the tree.
40
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
41
+ * `BinaryTreeNodeKey` (which can be a number or a string), a `BSTNode` object, or `null`.
42
+ * @param [val] - The `val` parameter is the value to be assigned to the new node being added to the
43
+ * binary search tree.
44
+ * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
45
+ * was not added or if the parameters were invalid, it returns null or undefined.
43
46
  */
44
47
  add(keyOrNode, val) {
45
48
  // TODO support node as a parameter
@@ -117,15 +120,17 @@ export class BST extends BinaryTree {
117
120
  return inserted;
118
121
  }
119
122
  /**
120
- * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
121
- * manner.
122
- * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
123
- * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
124
- * to the binary search tree.
123
+ * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
124
+ * maintaining balance.
125
+ * @param {[BinaryTreeNodeKey | N, N['val']][]} arr - The `arr` parameter in the `addMany` function
126
+ * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
127
+ * array of `BinaryTreeNodeKey` or `N` (which represents the node type in the binary search tree) or
128
+ * `null
125
129
  * @param {N['val'][]} data - The values of tree nodes
126
130
  * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
127
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a
128
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
131
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used.
132
+ * It can have two possible values:
133
+ * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values.
129
134
  */
130
135
  addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.iterationType) {
131
136
  // TODO this addMany function is inefficient, it should be optimized
@@ -197,22 +202,41 @@ export class BST extends BinaryTree {
197
202
  return inserted;
198
203
  }
199
204
  /**
200
- * The function returns the first node in a binary tree that matches the given property name and value.
201
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
202
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
203
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
204
- * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
205
- * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
205
+ * The function returns the first node in the binary tree that matches the given node property and
206
+ * callback.
207
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is used to specify the
208
+ * property of the binary tree node that you want to search for. It can be either a specific key
209
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
210
+ * whether a node matches the desired property.
211
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
212
+ * matches the desired property. It takes a node as input and returns a boolean value indicating
213
+ * whether the node matches the property or not. If no callback function is provided, the default
214
+ * callback function `_defaultCallbackByKey` is used
215
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
216
+ * the root node from which the search should begin.
217
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
218
+ * be performed when searching for nodes in the binary tree. It can have one of the following values:
219
+ * @returns either the first node that matches the given nodeProperty and callback, or null if no
220
+ * matching node is found.
206
221
  */
207
- get(nodeProperty, callback = this._defaultCallbackByKey) {
222
+ get(nodeProperty, callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
208
223
  var _a;
209
- return (_a = this.getNodes(nodeProperty, callback, true)[0]) !== null && _a !== void 0 ? _a : null;
224
+ return (_a = this.getNodes(nodeProperty, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : null;
210
225
  }
211
226
  /**
212
- * lastKey returns the last key in a binary tree. If the binary tree is empty, it returns 0.
213
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to begin
214
- * the search for the last key.
215
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a recursive or iterative approach to search for the last key.
227
+ * The function `lastKey` returns the key of the rightmost node if the comparison result is less
228
+ * than, the key of the leftmost node if the comparison result is greater than, and the key of the
229
+ * rightmost node otherwise.
230
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting point for finding the last
231
+ * key in a binary tree. It represents the root node of the subtree from which the search for the
232
+ * last key should begin. If no specific `beginRoot` is provided, the search will start from the root
233
+ * of the entire binary
234
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
235
+ * be performed when finding the last key. It determines whether the iteration should be performed in
236
+ * pre-order, in-order, or post-order.
237
+ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
238
+ * the key of the leftmost node if the comparison result is greater than, and the key of the
239
+ * rightmost node otherwise. If no node is found, it returns 0.
216
240
  */
217
241
  lastKey(beginRoot = this.root, iterationType = this.iterationType) {
218
242
  var _a, _b, _c, _d, _e, _f;
@@ -224,17 +248,25 @@ export class BST extends BinaryTree {
224
248
  return (_f = (_e = this.getRightMost(beginRoot, iterationType)) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
225
249
  }
226
250
  /**
227
- * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
228
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
229
- * `N` type. It represents the property of the binary tree node that you want to compare with.
230
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
231
- * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
232
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
233
- * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
234
- * is set to `true`, the function will return an array with only one node (if
235
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to
236
- * @param iterationType
237
- * @returns an array of nodes (type N).
251
+ * The function `getNodes` retrieves nodes from a binary tree based on a given node property or key,
252
+ * using either recursive or iterative traversal.
253
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter represents the property
254
+ * of the binary tree node that you want to search for. It can be either a `BinaryTreeNodeKey` or a
255
+ * generic type `N`.
256
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
257
+ * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
258
+ * included in the result. The default value for `callback` is `this._defaultCallbackByKey`, which is
259
+ * a
260
+ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
261
+ * the first node that matches the nodeProperty. If set to true, the function will return an array
262
+ * containing only that node. If set to false (default), the function will continue the traversal and
263
+ * return an array containing all nodes that match the node
264
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the traversal. It
265
+ * specifies the root node of the binary tree from which the traversal should begin. If `beginRoot`
266
+ * is `null`, an empty array will be returned.
267
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
268
+ * traverse the binary tree. It can have one of the following values:
269
+ * @returns an array of nodes (N[]).
238
270
  */
239
271
  getNodes(nodeProperty, callback = this._defaultCallbackByKey, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
240
272
  if (!beginRoot)
@@ -293,13 +325,21 @@ export class BST extends BinaryTree {
293
325
  }
294
326
  // --- start additional functions
295
327
  /**
296
- * The `lesserOrGreaterTraverse` function adds a delta value to the specified property of all nodes in a binary tree that
297
- * have a greater value than a given node.
298
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
299
- * represents the node in the binary tree to which the delta value will be added.
300
- * @param lesserOrGreater - The `lesserOrGreater` parameter is an optional parameter that specifies whether the delta
301
- * @param targetNode - The `targetNode` parameter is an optional parameter that specifies the node in the binary tree
302
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a
328
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
329
+ * nodes that have a key value lesser or greater than a target key value.
330
+ * @param callback - The `callback` parameter is a function that will be called for each node that
331
+ * meets the condition specified by the `lesserOrGreater` parameter. It takes a node as an argument
332
+ * and returns a value.
333
+ * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
334
+ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It can take one
335
+ * of the following values:
336
+ * @param {N | BinaryTreeNodeKey | null} targetNode - The `targetNode` parameter in the
337
+ * `lesserOrGreaterTraverse` function is used to specify the node from which the traversal should
338
+ * start. It can be either a reference to a specific node (`N`), the key of a node
339
+ * (`BinaryTreeNodeKey`), or `null` to
340
+ * @param iterationType - The `iterationType` parameter determines whether the traversal should be
341
+ * done recursively or iteratively. It can have two possible values:
342
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
303
343
  */
304
344
  lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = CP.lt, targetNode = this.root, iterationType = this.iterationType) {
305
345
  if (typeof targetNode === 'number')
@@ -352,9 +392,12 @@ export class BST extends BinaryTree {
352
392
  * 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).
353
393
  */
354
394
  /**
355
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
356
- * constructs a balanced binary search tree using either a recursive or iterative approach.
357
- * @returns The function `perfectlyBalance()` returns a boolean value.
395
+ * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
396
+ * ensures the tree is perfectly balanced.
397
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
398
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
399
+ * values:
400
+ * @returns The function `perfectlyBalance` returns a boolean value.
358
401
  */
359
402
  perfectlyBalance(iterationType = this.iterationType) {
360
403
  const sorted = this.dfs(node => node, 'in'), n = sorted.length;
@@ -393,7 +436,9 @@ export class BST extends BinaryTree {
393
436
  }
394
437
  }
395
438
  /**
396
- * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
439
+ * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
440
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
441
+ * to check if the AVL tree is balanced. It can have two possible values:
397
442
  * @returns a boolean value.
398
443
  */
399
444
  isAVLBalanced(iterationType = this.iterationType) {
@@ -443,12 +488,12 @@ export class BST extends BinaryTree {
443
488
  return balanced;
444
489
  }
445
490
  /**
446
- * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
447
- * greater than, less than, or equal to the second ID.
448
- * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
449
- * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
450
- * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
451
- * than), or CP.eq (equal).
491
+ * The function compares two values using a comparator function and returns whether the first value
492
+ * is greater than, less than, or equal to the second value.
493
+ * @param {BinaryTreeNodeKey} a - The parameter "a" is of type BinaryTreeNodeKey.
494
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code represents a BinaryTreeNodeKey.
495
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
496
+ * than), CP.lt (less than), or CP.eq (equal).
452
497
  */
453
498
  _compare(a, b) {
454
499
  const compared = this._comparator(a, b);
@@ -47,67 +47,75 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
47
47
  */
48
48
  createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
49
49
  /**
50
- * The function swaps the location of two nodes in a tree data structure.
51
- * @param {N} srcNode - The source node that we want to _swap with the destination node.
52
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
53
- * be swapped with.
54
- * @returns the `destNode` after swapping its values with the `srcNode`.
50
+ * The function swaps the values of two nodes in a binary tree.
51
+ * @param {N} srcNode - The source node that needs to be swapped with the destination node.
52
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
53
+ * from `srcNode` will be swapped into.
54
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
55
55
  */
56
56
  protected _swap(srcNode: N, destNode: N): N;
57
57
  /**
58
- * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if
59
- * necessary.
60
- * @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which
61
- * represents a `BinaryTreeNode`).
62
- * @param [val] - The `val` parameter represents the value to be added to the binary tree node.
63
- * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
64
- * value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
65
- * @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
58
+ * The `add` function adds a new node to a binary search tree, updating the count if the key already
59
+ * exists, and balancing the tree if necessary.
60
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
61
+ * `BinaryTreeNodeKey` (which represents the key of the node to be added), a `N` (which represents a
62
+ * node to be added), or `null` (which represents a null node).
63
+ * @param [val] - The `val` parameter represents the value associated with the key that is being
64
+ * added to the binary tree.
65
+ * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
66
+ * pair that will be added to the binary tree. It has a default value of 1, which means that if no
67
+ * count is specified, the default count will be 1.
68
+ * @returns The function `add` returns a value of type `N | null | undefined`.
66
69
  */
67
70
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count?: number): N | null | undefined;
68
71
  /**
69
- * The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent
70
- * node.
71
- * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
72
- * be either a node object (`N`) or `null`.
73
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
74
- * child.
75
- * @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
72
+ * The function adds a new node to a binary tree if there is an available slot in the parent node.
73
+ * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
74
+ * the tree. It can be either a node object (`N`) or `null`.
75
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
76
+ * be added as a child.
77
+ * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
76
78
  */
77
79
  _addTo(newNode: N | null, parent: N): N | null | undefined;
78
80
  /**
79
- * The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
80
- * the inserted nodes.
81
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
82
- * objects, or null values.
83
- * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
84
- * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
85
- * method. If provided, the `data` array should
81
+ * The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
82
+ * inserted nodes.
83
+ * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
84
+ * added to the multiset. Each element can be either a BinaryTreeNodeKey or a TreeMultisetNode.
85
+ * @param {N['val'][]} [data] - The `data` parameter is an optional array of values that correspond
86
+ * to the keys or nodes being added to the multiset. It is used to associate additional data with
87
+ * each key or node.
86
88
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
87
89
  */
88
90
  addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
89
91
  /**
90
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
91
- * constructs a balanced binary search tree using either a recursive or iterative approach.
92
- * @returns The function `perfectlyBalance()` returns a boolean value.
92
+ * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
93
+ * binary search tree using either a recursive or iterative approach.
94
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
95
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
96
+ * values:
97
+ * @returns a boolean value.
93
98
  */
94
99
  perfectlyBalance(iterationType?: IterationType): boolean;
95
100
  /**
96
- * The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
97
- * node that needs to be balanced.
98
- * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
99
- * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
100
- * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
101
- * not be taken into account when removing it. If `ignoreCount` is set to `false
102
- * @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
101
+ * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
102
+ * node along with the parent node that needs to be balanced.
103
+ * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
104
+ * (`N`) or a key value (`BinaryTreeNodeKey`). It represents the node or key that needs to be deleted
105
+ * from the binary tree.
106
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
107
+ * being deleted. If set to true, the count of the node will not be considered and the node will be
108
+ * deleted regardless of its count. If set to false (default), the count of the node will be
109
+ * decremented by 1 and
110
+ * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
103
111
  */
104
112
  delete(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
105
113
  /**
106
- * The clear() function clears the data and sets the count to 0.
114
+ * The clear() function clears the contents of a data structure and sets the count to zero.
107
115
  */
108
116
  clear(): void;
109
117
  /**
110
- * The function "_setCount" is used to set the value of the "_count" property.
118
+ * The function sets the value of the "_count" property.
111
119
  * @param {number} v - number
112
120
  */
113
121
  protected _setCount(v: number): void;