undirected-graph-typed
Advanced tools
Comparing version
@@ -53,3 +53,3 @@ /** | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)` | ||
* `this.defaultOneParamCallback` | ||
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects. | ||
@@ -56,0 +56,0 @@ */ |
@@ -65,6 +65,6 @@ "use strict"; | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)` | ||
* `this.defaultOneParamCallback` | ||
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects. | ||
*/ | ||
delete(identifier, callback = ((node) => node.key)) { | ||
delete(identifier, callback = this.defaultOneParamCallback) { | ||
if (identifier instanceof AVLTreeNode) | ||
@@ -71,0 +71,0 @@ callback = (node => node); |
@@ -82,2 +82,3 @@ /** | ||
get size(): number; | ||
protected defaultOneParamCallback: (node: N) => number; | ||
/** | ||
@@ -261,3 +262,3 @@ * Creates a new instance of BinaryTreeNode with the given key and value. | ||
* the depth-first search traversal. It takes a node as input and returns a value. The default value | ||
* is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code. | ||
* is `this.defaultOneParamCallback`, which is a callback function defined elsewhere in the code. | ||
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the | ||
@@ -278,3 +279,3 @@ * nodes are visited during the depth-first search. There are three possible values for `pattern`: | ||
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type | ||
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key) | ||
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this.defaultOneParamCallback | ||
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first | ||
@@ -323,3 +324,3 @@ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search | ||
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The | ||
* default value for this parameter is `((node: N) => node.key)`. | ||
* default value for this parameter is `this.defaultOneParamCallback`. | ||
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function | ||
@@ -326,0 +327,0 @@ * determines the order in which the nodes of a binary tree are traversed. It can have one of the |
@@ -93,2 +93,3 @@ "use strict"; | ||
this._size = 0; | ||
this.defaultOneParamCallback = (node) => node.key; | ||
if (options !== undefined) { | ||
@@ -246,5 +247,5 @@ const { iterationType = types_1.IterationType.ITERATIVE } = options; | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)`, which | ||
* `this.defaultOneParamCallback`, which | ||
*/ | ||
delete(identifier, callback = ((node) => node.key)) { | ||
delete(identifier, callback = this.defaultOneParamCallback) { | ||
const bstDeletedResult = []; | ||
@@ -440,3 +441,3 @@ if (!this.root) | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)`, which | ||
* `this.defaultOneParamCallback`, which | ||
* @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the | ||
@@ -453,3 +454,3 @@ * first node that matches the identifier. If set to true, the function will return an array with | ||
*/ | ||
getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) { | ||
getNodes(identifier, callback = this.defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (!beginRoot) | ||
@@ -499,3 +500,3 @@ return []; | ||
* whether the node matches the criteria or not. The default callback function | ||
* `((node: N) => node.key)` is used if no callback function is | ||
* `this.defaultOneParamCallback` is used if no callback function is | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
@@ -509,3 +510,3 @@ * the node from which the search should begin. By default, it is set to `this.root`, which means the | ||
*/ | ||
has(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
has(identifier, callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (identifier instanceof BinaryTreeNode) | ||
@@ -523,3 +524,3 @@ callback = (node => node); | ||
* whether the node matches the criteria or not. The default callback function | ||
* (`((node: N) => node.key)`) is used if no callback function is | ||
* (`this.defaultOneParamCallback`) is used if no callback function is | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
@@ -531,3 +532,3 @@ * the root node from which the search should begin. | ||
*/ | ||
getNode(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
getNode(identifier, callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) { | ||
var _a; | ||
@@ -546,3 +547,3 @@ if (identifier instanceof BinaryTreeNode) | ||
* whether the node matches the criteria or not. The default callback function | ||
* (`((node: N) => node.key)`) is used if no callback function is | ||
* (`this.defaultOneParamCallback`) is used if no callback function is | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
@@ -554,3 +555,3 @@ * the root node from which the search should begin. | ||
*/ | ||
get(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
get(identifier, callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) { | ||
var _a, _b; | ||
@@ -717,3 +718,3 @@ if (identifier instanceof BinaryTreeNode) | ||
*/ | ||
subTreeTraverse(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
subTreeTraverse(callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (typeof beginRoot === 'number') | ||
@@ -748,3 +749,3 @@ beginRoot = this.getNode(beginRoot); | ||
* the depth-first search traversal. It takes a node as input and returns a value. The default value | ||
* is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code. | ||
* is `this.defaultOneParamCallback`, which is a callback function defined elsewhere in the code. | ||
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the | ||
@@ -759,3 +760,3 @@ * nodes are visited during the depth-first search. There are three possible values for `pattern`: | ||
*/ | ||
dfs(callback = ((node) => node.key), pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) { | ||
dfs(callback = this.defaultOneParamCallback, pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) { | ||
if (!beginRoot) | ||
@@ -835,3 +836,3 @@ return []; | ||
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type | ||
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key) | ||
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this.defaultOneParamCallback | ||
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first | ||
@@ -844,3 +845,3 @@ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search | ||
*/ | ||
bfs(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
bfs(callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (!beginRoot) | ||
@@ -895,3 +896,3 @@ return []; | ||
*/ | ||
listLevels(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
listLevels(callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (!beginRoot) | ||
@@ -971,3 +972,3 @@ return []; | ||
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The | ||
* default value for this parameter is `((node: N) => node.key)`. | ||
* default value for this parameter is `this.defaultOneParamCallback`. | ||
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function | ||
@@ -981,3 +982,3 @@ * determines the order in which the nodes of a binary tree are traversed. It can have one of the | ||
*/ | ||
morris(callback = ((node) => node.key), pattern = 'in', beginRoot = this.root) { | ||
morris(callback = this.defaultOneParamCallback, pattern = 'in', beginRoot = this.root) { | ||
if (beginRoot === null) | ||
@@ -984,0 +985,0 @@ return []; |
@@ -58,21 +58,2 @@ /** | ||
/** | ||
* The function returns the first node in the binary tree that matches the given node property and | ||
* callback. | ||
* @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the | ||
* property of the binary tree node that you want to search for. It can be either a specific key | ||
* value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines | ||
* whether a node matches the desired property. | ||
* @param callback - The `callback` parameter is a function that is used to determine whether a node | ||
* matches the desired property. It takes a node as input and returns a boolean value indicating | ||
* whether the node matches the property or not. If no callback function is provided, the default | ||
* callback function `_defaultCallbackByKey` is used | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
* the root node from which the search should begin. | ||
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to | ||
* be performed when searching for nodes in the binary tree. It can have one of the following values: | ||
* @returns either the first node that matches the given nodeProperty and callback, or null if no | ||
* matching node is found. | ||
*/ | ||
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null; | ||
/** | ||
* The function `lastKey` returns the key of the rightmost node if the comparison result is less | ||
@@ -101,3 +82,3 @@ * than, the key of the leftmost node if the comparison result is greater than, and the key of the | ||
* value. This value is compared with the `nodeProperty` parameter to determine if the node should be | ||
* included in the result. The default value for `callback` is `((node: N) => node.key)`, which is | ||
* included in the result. The default value for `callback` is `this.defaultOneParamCallback`, which is | ||
* a | ||
@@ -104,0 +85,0 @@ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding |
@@ -209,24 +209,2 @@ "use strict"; | ||
/** | ||
* The function returns the first node in the binary tree that matches the given node property and | ||
* callback. | ||
* @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the | ||
* property of the binary tree node that you want to search for. It can be either a specific key | ||
* value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines | ||
* whether a node matches the desired property. | ||
* @param callback - The `callback` parameter is a function that is used to determine whether a node | ||
* matches the desired property. It takes a node as input and returns a boolean value indicating | ||
* whether the node matches the property or not. If no callback function is provided, the default | ||
* callback function `_defaultCallbackByKey` is used | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
* the root node from which the search should begin. | ||
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to | ||
* be performed when searching for nodes in the binary tree. It can have one of the following values: | ||
* @returns either the first node that matches the given nodeProperty and callback, or null if no | ||
* matching node is found. | ||
*/ | ||
getNode(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) { | ||
var _a; | ||
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : null; | ||
} | ||
/** | ||
* The function `lastKey` returns the key of the rightmost node if the comparison result is less | ||
@@ -263,3 +241,3 @@ * than, the key of the leftmost node if the comparison result is greater than, and the key of the | ||
* value. This value is compared with the `nodeProperty` parameter to determine if the node should be | ||
* included in the result. The default value for `callback` is `((node: N) => node.key)`, which is | ||
* included in the result. The default value for `callback` is `this.defaultOneParamCallback`, which is | ||
* a | ||
@@ -277,3 +255,3 @@ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding | ||
*/ | ||
getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) { | ||
getNodes(identifier, callback = this.defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (!beginRoot) | ||
@@ -293,3 +271,3 @@ return []; | ||
// TODO potential bug | ||
if (callback === ((node) => node.key)) { | ||
if (callback === this.defaultOneParamCallback) { | ||
if (this._compare(cur.key, identifier) === types_1.CP.gt) | ||
@@ -319,3 +297,3 @@ cur.left && _traverse(cur.left); | ||
// TODO potential bug | ||
if (callback === ((node) => node.key)) { | ||
if (callback === this.defaultOneParamCallback) { | ||
if (this._compare(cur.key, identifier) === types_1.CP.gt) | ||
@@ -353,3 +331,3 @@ cur.left && queue.push(cur.left); | ||
*/ | ||
lesserOrGreaterTraverse(callback = ((node) => node.key), lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) { | ||
lesserOrGreaterTraverse(callback = this.defaultOneParamCallback, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) { | ||
if (typeof targetNode === 'number') | ||
@@ -356,0 +334,0 @@ targetNode = this.getNode(targetNode); |
@@ -101,3 +101,3 @@ /** | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)` | ||
* `this.defaultOneParamCallback` | ||
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node | ||
@@ -104,0 +104,0 @@ * being deleted. If set to true, the count of the node will not be considered and the node will be |
@@ -254,3 +254,3 @@ "use strict"; | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)` | ||
* `this.defaultOneParamCallback` | ||
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node | ||
@@ -262,3 +262,3 @@ * being deleted. If set to true, the count of the node will not be considered and the node will be | ||
*/ | ||
delete(identifier, callback = ((node) => node.key), ignoreCount = false) { | ||
delete(identifier, callback = this.defaultOneParamCallback, ignoreCount = false) { | ||
const bstDeletedResult = []; | ||
@@ -265,0 +265,0 @@ if (!this.root) |
{ | ||
"name": "undirected-graph-typed", | ||
"version": "1.41.5", | ||
"version": "1.41.6", | ||
"description": "Undirected Graph. Javascript & Typescript Data Structure.", | ||
@@ -148,4 +148,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.41.5" | ||
"data-structure-typed": "^1.41.6" | ||
} | ||
} |
@@ -73,3 +73,3 @@ /** | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)` | ||
* `this.defaultOneParamCallback` | ||
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects. | ||
@@ -79,3 +79,3 @@ */ | ||
identifier: ReturnType<C>, | ||
callback: C = ((node: N) => node.key) as C | ||
callback: C = this.defaultOneParamCallback as C | ||
): BinaryTreeDeletedResult<N>[] { | ||
@@ -82,0 +82,0 @@ if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C; |
@@ -144,2 +144,4 @@ /** | ||
protected defaultOneParamCallback = (node: N) => node.key; | ||
/** | ||
@@ -288,7 +290,7 @@ * Creates a new instance of BinaryTreeNode with the given key and value. | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)`, which | ||
* `this.defaultOneParamCallback`, which | ||
*/ | ||
delete<C extends BTNCallback<N>>( | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C | ||
callback: C = this.defaultOneParamCallback as C | ||
): BinaryTreeDeletedResult<N>[] { | ||
@@ -511,3 +513,3 @@ const bstDeletedResult: BinaryTreeDeletedResult<N>[] = []; | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)`, which | ||
* `this.defaultOneParamCallback`, which | ||
* @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the | ||
@@ -526,3 +528,3 @@ * first node that matches the identifier. If set to true, the function will return an array with | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
onlyOne = false, | ||
@@ -595,3 +597,3 @@ beginRoot: N | null = this.root, | ||
* whether the node matches the criteria or not. The default callback function | ||
* `((node: N) => node.key)` is used if no callback function is | ||
* `this.defaultOneParamCallback` is used if no callback function is | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
@@ -607,3 +609,3 @@ * the node from which the search should begin. By default, it is set to `this.root`, which means the | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
beginRoot = this.root, | ||
@@ -646,3 +648,3 @@ iterationType = this.iterationType | ||
* whether the node matches the criteria or not. The default callback function | ||
* (`((node: N) => node.key)`) is used if no callback function is | ||
* (`this.defaultOneParamCallback`) is used if no callback function is | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
@@ -656,3 +658,3 @@ * the root node from which the search should begin. | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
beginRoot = this.root, | ||
@@ -695,3 +697,3 @@ iterationType = this.iterationType | ||
* whether the node matches the criteria or not. The default callback function | ||
* (`((node: N) => node.key)`) is used if no callback function is | ||
* (`this.defaultOneParamCallback`) is used if no callback function is | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
@@ -705,3 +707,3 @@ * the root node from which the search should begin. | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
beginRoot = this.root, | ||
@@ -872,3 +874,3 @@ iterationType = this.iterationType | ||
subTreeTraverse<C extends BTNCallback<N>>( | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
beginRoot: BTNKey | N | null = this.root, | ||
@@ -909,3 +911,3 @@ iterationType = this.iterationType | ||
* the depth-first search traversal. It takes a node as input and returns a value. The default value | ||
* is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code. | ||
* is `this.defaultOneParamCallback`, which is a callback function defined elsewhere in the code. | ||
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the | ||
@@ -921,3 +923,3 @@ * nodes are visited during the depth-first search. There are three possible values for `pattern`: | ||
dfs<C extends BTNCallback<N>>( | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
pattern: DFSOrderPattern = 'in', | ||
@@ -997,3 +999,3 @@ beginRoot: N | null = this.root, | ||
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type | ||
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key) | ||
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this.defaultOneParamCallback | ||
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first | ||
@@ -1007,3 +1009,3 @@ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search | ||
bfs<C extends BTNCallback<N>>( | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
beginRoot: N | null = this.root, | ||
@@ -1065,3 +1067,3 @@ iterationType = this.iterationType | ||
listLevels<C extends BTNCallback<N>>( | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
beginRoot: N | null = this.root, | ||
@@ -1145,3 +1147,3 @@ iterationType = this.iterationType | ||
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The | ||
* default value for this parameter is `((node: N) => node.key)`. | ||
* default value for this parameter is `this.defaultOneParamCallback`. | ||
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function | ||
@@ -1156,3 +1158,3 @@ * determines the order in which the nodes of a binary tree are traversed. It can have one of the | ||
morris<C extends BTNCallback<N>>( | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
pattern: DFSOrderPattern = 'in', | ||
@@ -1159,0 +1161,0 @@ beginRoot: N | null = this.root |
@@ -39,3 +39,3 @@ /** | ||
} | ||
/** | ||
@@ -221,29 +221,2 @@ * The function creates a new binary search tree node with the given key and value. | ||
/** | ||
* The function returns the first node in the binary tree that matches the given node property and | ||
* callback. | ||
* @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the | ||
* property of the binary tree node that you want to search for. It can be either a specific key | ||
* value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines | ||
* whether a node matches the desired property. | ||
* @param callback - The `callback` parameter is a function that is used to determine whether a node | ||
* matches the desired property. It takes a node as input and returns a boolean value indicating | ||
* whether the node matches the property or not. If no callback function is provided, the default | ||
* callback function `_defaultCallbackByKey` is used | ||
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies | ||
* the root node from which the search should begin. | ||
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to | ||
* be performed when searching for nodes in the binary tree. It can have one of the following values: | ||
* @returns either the first node that matches the given nodeProperty and callback, or null if no | ||
* matching node is found. | ||
*/ | ||
override getNode<C extends BTNCallback<N>>( | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C, | ||
beginRoot = this.root, | ||
iterationType = this.iterationType | ||
): N | null { | ||
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null; | ||
} | ||
/** | ||
* The function `lastKey` returns the key of the rightmost node if the comparison result is less | ||
@@ -277,3 +250,3 @@ * than, the key of the leftmost node if the comparison result is greater than, and the key of the | ||
* value. This value is compared with the `nodeProperty` parameter to determine if the node should be | ||
* included in the result. The default value for `callback` is `((node: N) => node.key)`, which is | ||
* included in the result. The default value for `callback` is `this.defaultOneParamCallback`, which is | ||
* a | ||
@@ -293,3 +266,3 @@ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding | ||
identifier: ReturnType<C> | null, | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
onlyOne = false, | ||
@@ -312,3 +285,3 @@ beginRoot: N | null = this.root, | ||
// TODO potential bug | ||
if (callback === ((node: N) => node.key)) { | ||
if (callback === this.defaultOneParamCallback) { | ||
if (this._compare(cur.key, identifier as number) === CP.gt) cur.left && _traverse(cur.left); | ||
@@ -334,3 +307,3 @@ if (this._compare(cur.key, identifier as number) === CP.lt) cur.right && _traverse(cur.right); | ||
// TODO potential bug | ||
if (callback === ((node: N) => node.key)) { | ||
if (callback === this.defaultOneParamCallback) { | ||
if (this._compare(cur.key, identifier as number) === CP.gt) cur.left && queue.push(cur.left); | ||
@@ -369,3 +342,3 @@ if (this._compare(cur.key, identifier as number) === CP.lt) cur.right && queue.push(cur.right); | ||
lesserOrGreaterTraverse<C extends BTNCallback<N>>( | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
lesserOrGreater: CP = CP.lt, | ||
@@ -372,0 +345,0 @@ targetNode: BTNKey | N | null = this.root, |
@@ -271,3 +271,3 @@ /** | ||
* included in the result. The `callback` parameter has a default value of | ||
* `((node: N) => node.key)` | ||
* `this.defaultOneParamCallback` | ||
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node | ||
@@ -281,3 +281,3 @@ * being deleted. If set to true, the count of the node will not be considered and the node will be | ||
identifier: ReturnType<C>, | ||
callback: C = ((node: N) => node.key) as C, | ||
callback: C = this.defaultOneParamCallback as C, | ||
ignoreCount = false | ||
@@ -284,0 +284,0 @@ ): BinaryTreeDeletedResult<N>[] { |
1434200
-0.29%25477
-0.25%Updated