queue-typed
Advanced tools
Comparing version 1.52.8 to 1.52.9
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, BTNEntry } from '../../types'; | ||
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, IterationType, BTNEntry } from '../../types'; | ||
import { IBinaryTree } from '../../interfaces'; | ||
@@ -131,5 +131,5 @@ import { AVLTree, AVLTreeNode } from './avl-tree'; | ||
* nodes and maintaining balance in the tree. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate` | ||
* parameter in the `delete` method is used to specify the condition for deleting a node from the | ||
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which | ||
* binary tree. It can be a key, node, or entry that determines which | ||
* node(s) should be deleted. | ||
@@ -145,3 +145,3 @@ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a | ||
*/ | ||
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[]; | ||
delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[]; | ||
/** | ||
@@ -148,0 +148,0 @@ * Time Complexity: O(1) |
@@ -178,5 +178,5 @@ "use strict"; | ||
* nodes and maintaining balance in the tree. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate` | ||
* parameter in the `delete` method is used to specify the condition for deleting a node from the | ||
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which | ||
* binary tree. It can be a key, node, or entry that determines which | ||
* node(s) should be deleted. | ||
@@ -192,3 +192,3 @@ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a | ||
*/ | ||
delete(predicate, ignoreCount = false) { | ||
delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) { | ||
var _a; | ||
@@ -198,3 +198,3 @@ const deletedResult = []; | ||
return deletedResult; | ||
const curr = (_a = this.getNode(predicate)) !== null && _a !== void 0 ? _a : undefined; | ||
const curr = (_a = this.getNode(keyOrNodeOrEntryOrRaw)) !== null && _a !== void 0 ? _a : undefined; | ||
if (!curr) | ||
@@ -201,0 +201,0 @@ return deletedResult; |
@@ -9,3 +9,3 @@ /** | ||
import { BST, BSTNode } from './bst'; | ||
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, BTNEntry } from '../../types'; | ||
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNEntry } from '../../types'; | ||
import { IBinaryTree } from '../../interfaces'; | ||
@@ -103,3 +103,3 @@ export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> { | ||
* balances the tree if necessary. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw` | ||
* parameter in the `override delete` method can be one of the following types: | ||
@@ -111,3 +111,3 @@ * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete` | ||
*/ | ||
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[]; | ||
delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[]; | ||
/** | ||
@@ -114,0 +114,0 @@ * Time Complexity: O(1) |
@@ -127,3 +127,3 @@ "use strict"; | ||
* balances the tree if necessary. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw` | ||
* parameter in the `override delete` method can be one of the following types: | ||
@@ -135,4 +135,4 @@ * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete` | ||
*/ | ||
delete(predicate) { | ||
const deletedResults = super.delete(predicate); | ||
delete(keyOrNodeOrEntryOrRaw) { | ||
const deletedResults = super.delete(keyOrNodeOrEntryOrRaw); | ||
for (const { needBalanced } of deletedResults) { | ||
@@ -139,0 +139,0 @@ if (needBalanced) { |
@@ -238,5 +238,5 @@ /** | ||
* the deleted node along with information for tree balancing. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw | ||
* - The `delete` method you provided is used to delete a node from a binary tree based on the key, | ||
* node, entry, raw data, or a custom predicate. The method returns an array of | ||
* node, entry or raw data. The method returns an array of | ||
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether | ||
@@ -248,3 +248,3 @@ * balancing is needed. | ||
*/ | ||
delete(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[]; | ||
delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[]; | ||
/** | ||
@@ -662,5 +662,62 @@ * Time Complexity: O(n) | ||
toVisual(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, options?: BinaryTreePrintOptions): string; | ||
protected _dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[]; | ||
protected _dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[]; | ||
/** | ||
* Time Complexity: O(n) | ||
* Space Complexity: O(n) | ||
* | ||
* The function `print` in TypeScript overrides the default print behavior to log a visual | ||
* representation of the binary tree to the console. | ||
* @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the | ||
* printing options for the binary tree. It is an optional parameter that allows you to customize how | ||
* the binary tree is printed, such as choosing between different traversal orders or formatting | ||
* options. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the | ||
* `override print` method is used to specify the starting point for printing the binary tree. It can | ||
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is | ||
* provided, the default value is set to | ||
*/ | ||
print(options?: BinaryTreePrintOptions, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R): void; | ||
/** | ||
* Time complexity: O(n) | ||
* Space complexity: O(n) | ||
* | ||
* The `_dfs` function performs a depth-first search traversal on a binary tree structure based on | ||
* the specified order pattern and callback function. | ||
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be | ||
* called on each node visited during the depth-first search traversal. It is of type `C`, which | ||
* extends `BTNCallback<OptBTNOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT | ||
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the | ||
* order in which the nodes are visited during the Depth-First Search traversal. It can have one of | ||
* the following values: | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `_dfs` | ||
* method is used to specify the starting point for the depth-first search traversal in a binary | ||
* tree. It can be provided as either a `BTNKeyOrNodeOrEntry` object or a reference to the root node | ||
* of the tree. If no specific | ||
* @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method | ||
* specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a | ||
* binary tree. It can have two possible values: | ||
* @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method is a boolean flag | ||
* that determines whether null nodes should be included in the depth-first search traversal. If | ||
* `includeNull` is set to `true`, null nodes will be considered during the traversal process. If it | ||
* is set to `false`, | ||
* @param shouldVisitLeft - The `shouldVisitLeft` parameter is a function that takes a node as input | ||
* and returns a boolean value. It is used to determine whether the left child of a node should be | ||
* visited during the depth-first search traversal. By default, it checks if the node is truthy (not | ||
* null or undefined | ||
* @param shouldVisitRight - The `shouldVisitRight` parameter is a function that takes a node as an | ||
* argument and returns a boolean value. It is used to determine whether the right child of a node | ||
* should be visited during the depth-first search traversal. The default implementation checks if | ||
* the node is truthy before visiting the right child | ||
* @param shouldVisitRoot - The `shouldVisitRoot` parameter is a function that takes a node as an | ||
* argument and returns a boolean value. It is used to determine whether the root node should be | ||
* visited during the depth-first search traversal based on certain conditions. The default | ||
* implementation checks if the node is a real node or null based | ||
* @param shouldProcessRoot - The `shouldProcessRoot` parameter is a function that takes a node as an | ||
* argument and returns a boolean value indicating whether the node should be processed during the | ||
* depth-first search traversal. The default implementation checks if the node is a real node or null | ||
* based on the `includeNull` flag. If ` | ||
* @returns The function `_dfs` returns an array of the return type of the callback function provided | ||
* as input. | ||
*/ | ||
protected _dfs<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: OptBTNOrNull<NODE>) => boolean, shouldVisitRight?: (node: OptBTNOrNull<NODE>) => boolean, shouldVisitRoot?: (node: OptBTNOrNull<NODE>) => boolean, shouldProcessRoot?: (node: OptBTNOrNull<NODE>) => boolean): ReturnType<C>[]; | ||
/** | ||
* Time Complexity: O(1) | ||
@@ -667,0 +724,0 @@ * Space Complexity: O(1) |
@@ -249,4 +249,3 @@ "use strict"; | ||
const value = valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value; | ||
const nn = this.add(kve, value); | ||
inserted.push(nn); | ||
inserted.push(this.add(kve, value)); | ||
} | ||
@@ -256,13 +255,9 @@ return inserted; | ||
const realBTNExemplars = []; | ||
const isRealBTNExemplar = (kve) => { | ||
if (kve === undefined || kve === null) | ||
return false; | ||
return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null)); | ||
}; | ||
let i = 0; | ||
for (const kve of keysOrNodesOrEntriesOrRaws) { | ||
if (isRealBTNExemplar(kve)) | ||
realBTNExemplars.push(kve); | ||
realBTNExemplars.push({ key: kve, value: valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value, orgIndex: i }); | ||
i++; | ||
} | ||
let sorted = []; | ||
sorted = realBTNExemplars.sort((a, b) => { | ||
sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => { | ||
let keyA, keyB; | ||
@@ -298,4 +293,4 @@ if (this.isEntry(a)) | ||
const mid = Math.floor((arr.length - 1) / 2); | ||
const newNode = this.add(arr[mid]); | ||
inserted.push(newNode); | ||
const { key, value, orgIndex } = arr[mid]; | ||
inserted[orgIndex] = this.add(key, value); | ||
_dfs(arr.slice(0, mid)); | ||
@@ -313,4 +308,4 @@ _dfs(arr.slice(mid + 1)); | ||
const m = l + Math.floor((r - l) / 2); | ||
const newNode = this.add(sorted[m]); | ||
inserted.push(newNode); | ||
const { key, value, orgIndex } = sorted[m]; | ||
inserted[orgIndex] = this.add(key, value); | ||
stack.push([m + 1, r]); | ||
@@ -317,0 +312,0 @@ stack.push([l, m - 1]); |
@@ -1,2 +0,2 @@ | ||
import type { BinaryTreeDeleteResult, BTNKeyOrNodeOrEntry, BTNPredicate, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested, BTNEntry } from '../../types'; | ||
import type { BinaryTreeDeleteResult, BTNKeyOrNodeOrEntry, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested, BTNEntry } from '../../types'; | ||
import { BST, BSTNode } from './bst'; | ||
@@ -110,3 +110,3 @@ import { IBinaryTree } from '../../interfaces'; | ||
* a given predicate and maintain the binary search tree properties. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw` | ||
* parameter in the `override delete` method is used to specify the condition or key based on which a | ||
@@ -119,3 +119,3 @@ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate | ||
*/ | ||
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[]; | ||
delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[]; | ||
/** | ||
@@ -122,0 +122,0 @@ * Time Complexity: O(1) |
@@ -187,3 +187,3 @@ "use strict"; | ||
* a given predicate and maintain the binary search tree properties. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw` | ||
* parameter in the `override delete` method is used to specify the condition or key based on which a | ||
@@ -196,11 +196,13 @@ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate | ||
*/ | ||
delete(predicate) { | ||
if (predicate === null) | ||
delete(keyOrNodeOrEntryOrRaw) { | ||
if (keyOrNodeOrEntryOrRaw === null) | ||
return []; | ||
const results = []; | ||
let nodeToDelete; | ||
if (this._isPredicated(predicate)) | ||
nodeToDelete = this.getNode(predicate); | ||
if (this._isPredicated(keyOrNodeOrEntryOrRaw)) | ||
nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw); | ||
else | ||
nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate); | ||
nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw) | ||
? keyOrNodeOrEntryOrRaw | ||
: this.getNode(keyOrNodeOrEntryOrRaw); | ||
if (!nodeToDelete) { | ||
@@ -207,0 +209,0 @@ return results; |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types'; | ||
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types'; | ||
import { IBinaryTree } from '../../interfaces'; | ||
@@ -132,6 +132,5 @@ import { RedBlackTree, RedBlackTreeNode } from './rb-tree'; | ||
* structure, handling cases where nodes have children and maintaining balance in the tree. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate` | ||
* parameter in the `delete` method is used to specify the condition or key based on which a node | ||
* should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate | ||
* function. | ||
* should be deleted from the binary tree. It can be a key, a node, or an entry. | ||
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a | ||
@@ -143,3 +142,3 @@ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If | ||
*/ | ||
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[]; | ||
delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[]; | ||
/** | ||
@@ -146,0 +145,0 @@ * Time Complexity: O(1) |
@@ -181,6 +181,5 @@ "use strict"; | ||
* structure, handling cases where nodes have children and maintaining balance in the tree. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate` | ||
* parameter in the `delete` method is used to specify the condition or key based on which a node | ||
* should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate | ||
* function. | ||
* should be deleted from the binary tree. It can be a key, a node, or an entry. | ||
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a | ||
@@ -192,11 +191,13 @@ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If | ||
*/ | ||
delete(predicate, ignoreCount = false) { | ||
if (predicate === null) | ||
delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) { | ||
if (keyOrNodeOrEntryOrRaw === null) | ||
return []; | ||
const results = []; | ||
let nodeToDelete; | ||
if (this._isPredicated(predicate)) | ||
nodeToDelete = this.getNode(predicate); | ||
if (this._isPredicated(keyOrNodeOrEntryOrRaw)) | ||
nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw); | ||
else | ||
nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate); | ||
nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw) | ||
? keyOrNodeOrEntryOrRaw | ||
: this.getNode(keyOrNodeOrEntryOrRaw); | ||
if (!nodeToDelete) { | ||
@@ -203,0 +204,0 @@ return results; |
{ | ||
"name": "queue-typed", | ||
"version": "1.52.8", | ||
"version": "1.52.9", | ||
"description": "Queue, ArrayQueue. Javascript & Typescript Data Structure.", | ||
@@ -118,4 +118,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.52.8" | ||
"data-structure-typed": "^1.52.9" | ||
} | ||
} |
@@ -15,3 +15,2 @@ /** | ||
BTNKeyOrNodeOrEntry, | ||
BTNPredicate, | ||
IterationType, | ||
@@ -236,5 +235,5 @@ BTNEntry | ||
* nodes and maintaining balance in the tree. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate` | ||
* parameter in the `delete` method is used to specify the condition for deleting a node from the | ||
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which | ||
* binary tree. It can be a key, node, or entry that determines which | ||
* node(s) should be deleted. | ||
@@ -251,3 +250,3 @@ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a | ||
override delete( | ||
predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, | ||
keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, | ||
ignoreCount = false | ||
@@ -258,3 +257,3 @@ ): BinaryTreeDeleteResult<NODE>[] { | ||
const curr: NODE | undefined = this.getNode(predicate) ?? undefined; | ||
const curr: NODE | undefined = this.getNode(keyOrNodeOrEntryOrRaw) ?? undefined; | ||
if (!curr) return deletedResult; | ||
@@ -261,0 +260,0 @@ |
@@ -16,3 +16,2 @@ /** | ||
BTNKeyOrNodeOrEntry, | ||
BTNPredicate, | ||
BTNEntry | ||
@@ -164,3 +163,3 @@ } from '../../types'; | ||
* balances the tree if necessary. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw` | ||
* parameter in the `override delete` method can be one of the following types: | ||
@@ -172,4 +171,4 @@ * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete` | ||
*/ | ||
override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] { | ||
const deletedResults = super.delete(predicate); | ||
override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] { | ||
const deletedResults = super.delete(keyOrNodeOrEntryOrRaw); | ||
for (const { needBalanced } of deletedResults) { | ||
@@ -176,0 +175,0 @@ if (needBalanced) { |
@@ -17,3 +17,2 @@ /** | ||
BTNPredicate, | ||
BTNPureKeyOrNodeOrEntry, | ||
Comparator, | ||
@@ -314,4 +313,3 @@ CP, | ||
const value = valuesIterator?.next().value; | ||
const nn = this.add(kve, value); | ||
inserted.push(nn); | ||
inserted.push(this.add(kve, value)); | ||
} | ||
@@ -321,18 +319,17 @@ return inserted; | ||
const realBTNExemplars: (R | BTNPureKeyOrNodeOrEntry<K, V, NODE>)[] = []; | ||
const realBTNExemplars: { | ||
key: R | BTNKeyOrNodeOrEntry<K, V, NODE>; | ||
value: V | undefined; | ||
orgIndex: number; | ||
}[] = []; | ||
const isRealBTNExemplar = ( | ||
kve: BTNKeyOrNodeOrEntry<K, V, NODE> | R | ||
): kve is BTNPureKeyOrNodeOrEntry<K, V, NODE> => { | ||
if (kve === undefined || kve === null) return false; | ||
return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null)); | ||
}; | ||
let i = 0; | ||
for (const kve of keysOrNodesOrEntriesOrRaws) { | ||
if (isRealBTNExemplar(kve)) realBTNExemplars.push(kve); | ||
realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i }); | ||
i++; | ||
} | ||
let sorted: (R | BTNPureKeyOrNodeOrEntry<K, V, NODE>)[] = []; | ||
let sorted: { key: R | BTNKeyOrNodeOrEntry<K, V, NODE>; value: V | undefined; orgIndex: number }[] = []; | ||
sorted = realBTNExemplars.sort((a, b) => { | ||
sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => { | ||
let keyA: K | undefined | null, keyB: K | undefined | null; | ||
@@ -361,8 +358,8 @@ if (this.isEntry(a)) keyA = a[0]; | ||
const _dfs = (arr: (R | BTNPureKeyOrNodeOrEntry<K, V, NODE>)[]) => { | ||
const _dfs = (arr: { key: R | BTNKeyOrNodeOrEntry<K, V, NODE>; value: V | undefined; orgIndex: number }[]) => { | ||
if (arr.length === 0) return; | ||
const mid = Math.floor((arr.length - 1) / 2); | ||
const newNode = this.add(arr[mid]); | ||
inserted.push(newNode); | ||
const { key, value, orgIndex } = arr[mid]; | ||
inserted[orgIndex] = this.add(key, value); | ||
_dfs(arr.slice(0, mid)); | ||
@@ -381,4 +378,4 @@ _dfs(arr.slice(mid + 1)); | ||
const m = l + Math.floor((r - l) / 2); | ||
const newNode = this.add(sorted[m]); | ||
inserted.push(newNode); | ||
const { key, value, orgIndex } = sorted[m]; | ||
inserted[orgIndex] = this.add(key, value); | ||
stack.push([m + 1, r]); | ||
@@ -385,0 +382,0 @@ stack.push([l, m - 1]); |
import type { | ||
BinaryTreeDeleteResult, | ||
BTNKeyOrNodeOrEntry, | ||
BTNPredicate, | ||
CRUD, | ||
@@ -233,3 +232,3 @@ OptBSTN, | ||
* a given predicate and maintain the binary search tree properties. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw` | ||
* parameter in the `override delete` method is used to specify the condition or key based on which a | ||
@@ -242,9 +241,12 @@ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate | ||
*/ | ||
override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] { | ||
if (predicate === null) return []; | ||
override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] { | ||
if (keyOrNodeOrEntryOrRaw === null) return []; | ||
const results: BinaryTreeDeleteResult<NODE>[] = []; | ||
let nodeToDelete: OptBSTN<NODE>; | ||
if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate); | ||
else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate); | ||
if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw); | ||
else | ||
nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw) | ||
? keyOrNodeOrEntryOrRaw | ||
: this.getNode(keyOrNodeOrEntryOrRaw); | ||
@@ -251,0 +253,0 @@ if (!nodeToDelete) { |
@@ -12,3 +12,2 @@ /** | ||
BTNKeyOrNodeOrEntry, | ||
BTNPredicate, | ||
IterationType, | ||
@@ -236,6 +235,5 @@ OptBSTN, | ||
* structure, handling cases where nodes have children and maintaining balance in the tree. | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate` | ||
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate` | ||
* parameter in the `delete` method is used to specify the condition or key based on which a node | ||
* should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate | ||
* function. | ||
* should be deleted from the binary tree. It can be a key, a node, or an entry. | ||
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a | ||
@@ -248,6 +246,6 @@ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If | ||
override delete( | ||
predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, | ||
keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, | ||
ignoreCount = false | ||
): BinaryTreeDeleteResult<NODE>[] { | ||
if (predicate === null) return []; | ||
if (keyOrNodeOrEntryOrRaw === null) return []; | ||
@@ -257,4 +255,7 @@ const results: BinaryTreeDeleteResult<NODE>[] = []; | ||
let nodeToDelete: OptBSTN<NODE>; | ||
if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate); | ||
else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate); | ||
if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw); | ||
else | ||
nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw) | ||
? keyOrNodeOrEntryOrRaw | ||
: this.getNode(keyOrNodeOrEntryOrRaw); | ||
@@ -261,0 +262,0 @@ if (!nodeToDelete) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2027095
39080
Updateddata-structure-typed@^1.52.9