diff --git a/src/data-structures/binary-tree/abstract-binary-tree.ts b/src/data-structures/binary-tree/abstract-binary-tree.ts index 3b7a771..a947efb 100644 --- a/src/data-structures/binary-tree/abstract-binary-tree.ts +++ b/src/data-structures/binary-tree/abstract-binary-tree.ts @@ -248,19 +248,19 @@ export abstract class AbstractBinaryTree} [data] - The `data` parameter is an optional array of values that will be assigned to - * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `idsOrNodes` + * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes` * array. Each value in the `data` array will be assigned to the * @returns The method is returning a boolean value. */ - fill(idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array): boolean { + refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array): boolean { this.clear(); - return idsOrNodes.length === this.addMany(idsOrNodes, data).length; + return keysOrNodes.length === this.addMany(keysOrNodes, data).length; } /** diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 4f30d77..5ac85cd 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -130,7 +130,7 @@ export class BST = BSTNode> extends BinaryTree /** * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced * manner. - * @param {[BinaryTreeNodeKey | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of + * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added * to the binary search tree. * @param {N['val'][]} data - The values of tree nodes @@ -138,18 +138,18 @@ export class BST = BSTNode> extends BinaryTree * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values. */ override addMany( - idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], + keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd = false ): (N | null | undefined)[] { function hasNoNull(arr: (BinaryTreeNodeKey | null)[] | (N | null)[]): arr is BinaryTreeNodeKey[] | N[] { return arr.indexOf(null) === -1; } - if (!isBalanceAdd || !hasNoNull(idsOrNodes)) { - return super.addMany(idsOrNodes, data); + if (!isBalanceAdd || !hasNoNull(keysOrNodes)) { + return super.addMany(keysOrNodes, data); } const inserted: (N | null | undefined)[] = []; - const combinedArr: [BinaryTreeNodeKey | N, N['val']][] = idsOrNodes.map((value, index) => [value, data?.[index]]); + const combinedArr: [BinaryTreeNodeKey | N, N['val']][] = keysOrNodes.map((value, index) => [value, data?.[index]]); let sorted = []; function isNodeOrNullTuple(arr: [BinaryTreeNodeKey | N, N['val']][]): arr is [N, N['val']][] { for (const [keyOrNode] of arr) if (keyOrNode instanceof BSTNode) return true; @@ -169,7 +169,7 @@ export class BST = BSTNode> extends BinaryTree } else if (isBinaryTreeKeyOrNullTuple(combinedArr)) { sorted = combinedArr.sort((a, b) => a[0] - b[0]); } else { - throw new Error('Invalid input idsOrNodes'); + throw new Error('Invalid input keysOrNodes'); } sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode); sortedData = sorted.map(([, val]) => val); diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts index 2eabdd6..9510db1 100644 --- a/src/data-structures/binary-tree/tree-multiset.ts +++ b/src/data-structures/binary-tree/tree-multiset.ts @@ -211,7 +211,7 @@ export class TreeMultiset = TreeMultiset /** * The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of * the inserted nodes. - * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode + * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode * objects, or null values. * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()` @@ -219,13 +219,13 @@ export class TreeMultiset = TreeMultiset * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values. */ override addMany( - idsOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], + keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][] ): (N | null | undefined)[] { const inserted: (N | null | undefined)[] = []; - for (let i = 0; i < idsOrNodes.length; i++) { - const keyOrNode = idsOrNodes[i]; + for (let i = 0; i < keysOrNodes.length; i++) { + const keyOrNode = keysOrNodes[i]; if (keyOrNode instanceof TreeMultisetNode) { inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count)); diff --git a/src/interfaces/abstract-binary-tree.ts b/src/interfaces/abstract-binary-tree.ts index df0941d..a8288ee 100644 --- a/src/interfaces/abstract-binary-tree.ts +++ b/src/interfaces/abstract-binary-tree.ts @@ -52,9 +52,9 @@ export interface IAbstractBinaryTree): boolean; + refill(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array): boolean; remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult[];