Socket
Socket
Sign inDemoInstall

data-structure-typed

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-structure-typed - npm Package Compare versions

Comparing version 1.36.8 to 1.36.9

3

CHANGELOG.md

@@ -11,6 +11,7 @@ # Changelog

## [v1.36.8](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
## [v1.36.9](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
### Changes
- 1. No need for dfsIterative; integrate it directly into the dfs metho… [`#17`](https://github.com/zrwusa/data-structure-typed/pull/17)
- [heap] fibonacci heap implemented. [test] big O estimate. [project] n… [`#15`](https://github.com/zrwusa/data-structure-typed/pull/15)

@@ -17,0 +18,0 @@ - [rbtree] implemented, but with bugs [`#13`](https://github.com/zrwusa/data-structure-typed/pull/13)

@@ -24,4 +24,4 @@ /**

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -31,3 +31,3 @@ * be swapped to.

*/
swapLocation(srcNode: N, destNode: N): N;
protected _swap(srcNode: N, destNode: N): N;
/**

@@ -51,3 +51,3 @@ * The function creates a new AVL tree node with the given key and value.

/**
* The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
* deletion.

@@ -58,3 +58,3 @@ * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be

*/
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
/**

@@ -61,0 +61,0 @@ * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the

@@ -30,4 +30,4 @@ "use strict";

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -37,3 +37,3 @@ * be swapped to.

*/
swapLocation(srcNode, destNode) {
_swap(srcNode, destNode) {
const { key, val, height } = destNode;

@@ -78,3 +78,3 @@ const tempNode = this.createNode(key, val);

/**
* The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
* deletion.

@@ -85,4 +85,4 @@ * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be

*/
remove(key) {
const deletedResults = super.remove(key);
delete(key) {
const deletedResults = super.delete(key);
for (const { needBalanced } of deletedResults) {

@@ -89,0 +89,0 @@ if (needBalanced) {

@@ -58,2 +58,3 @@ /**

get loopType(): LoopType;
set loopType(v: LoopType);
visitedKey: BinaryTreeNodeKey[];

@@ -63,4 +64,4 @@ visitedVal: N['val'][];

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -70,3 +71,3 @@ * be swapped to.

*/
swapLocation(srcNode: N, destNode: N): N;
protected _swap(srcNode: N, destNode: N): N;
/**

@@ -117,9 +118,9 @@ * The clear() function resets the root, size, and maxKey properties to their initial values.

/**
* The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* The `delete` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* containing the deleted node and the node that needs to be balanced.
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeKey`).
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
/**

@@ -243,6 +244,6 @@ * The function calculates the depth of a node in a binary tree.

* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
* @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
* @returns a boolean value.
*/
isSubtreeBST(node: N | null): boolean;
isSubtreeBST(subTreeRoot: N | null): boolean;
/**

@@ -271,12 +272,10 @@ * The function isBST checks if the binary tree is valid binary search tree.

/**
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
* The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
* each node in the subtree should be incremented.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* @param callBack - The `callBack` parameter is a function that takes a node as a parameter and returns a number.
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
subTreeAdd(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
subTreeForeach(subTreeRoot: N | BinaryTreeNodeKey | null, callback: (node: N) => any): boolean;
/**

@@ -320,5 +319,6 @@ * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.

* @param {string} nodeOrPropertyName - The name of the property to accumulate.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns An array of values corresponding to the specified property.
*/
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key', loopType?: LoopType): BinaryTreeNodeKey[];
/**

@@ -328,5 +328,6 @@ * Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.

* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns An array of 'val' properties from each node.
*/
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val', loopType?: LoopType): N[];
/**

@@ -336,70 +337,7 @@ * Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.

* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns An array of binary tree nodes.
*/
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node', loopType?: LoopType): N[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
dfsIterative(): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @returns An array of values corresponding to the specified property.
*/
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of values corresponding to the specified property.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of 'val' properties from each node.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of binary tree nodes.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
levelIterative(): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @returns An array of binary tree node IDs.
*/
levelIterative(node: N | null): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of values corresponding to the specified property.
*/
levelIterative(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of 'val' properties from each node.
*/
levelIterative(node: N | null, nodeOrPropertyName: 'val'): N['val'][];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of binary tree nodes.
*/
levelIterative(node: N | null, nodeOrPropertyName: 'node'): N[];
/**
* Collects nodes from a binary tree by a specified property and organizes them into levels.

@@ -490,7 +428,2 @@ * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.

/**
* The function sets the loop type for a protected variable.
* @param {LoopType} value - The value parameter is of type LoopType.
*/
protected _setLoopType(value: LoopType): void;
/**
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the

@@ -497,0 +430,0 @@ * parent property of the value to undefined.

@@ -121,5 +121,8 @@ "use strict";

}
set loopType(v) {
this._loopType = v;
}
/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -129,3 +132,3 @@ * be swapped to.

*/
swapLocation(srcNode, destNode) {
_swap(srcNode, destNode) {
const { key, val } = destNode;

@@ -267,9 +270,9 @@ const tempNode = this.createNode(key, val);

/**
* The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* The `delete` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* containing the deleted node and the node that needs to be balanced.
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeKey`).
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey) {
delete(nodeOrKey) {
const bstDeletedResult = [];

@@ -303,3 +306,3 @@ if (!this.root)

const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
orgCurrent = this._swap(curr, leftSubTreeRightMost);
if (parentOfLeftSubTreeMax) {

@@ -600,8 +603,8 @@ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)

* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
* @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
* @returns a boolean value.
*/
isSubtreeBST(node) {
isSubtreeBST(subTreeRoot) {
// TODO there is a bug
if (!node)
if (!subTreeRoot)
return true;

@@ -616,7 +619,7 @@ if (this._loopType === types_1.LoopType.RECURSIVE) {

};
return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
return dfs(subTreeRoot, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
}
else {
const stack = [];
let prev = Number.MIN_SAFE_INTEGER, curr = node;
let prev = Number.MIN_SAFE_INTEGER, curr = subTreeRoot;
while (curr || stack.length > 0) {

@@ -724,12 +727,10 @@ while (curr) {

/**
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
* The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
* each node in the subtree should be incremented.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* @param callBack - The `callBack` parameter is a function that takes a node as a parameter and returns a number.
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
subTreeAdd(subTreeRoot, delta, propertyName = 'key') {
subTreeForeach(subTreeRoot, callback) {
if (typeof subTreeRoot === 'number')

@@ -739,15 +740,5 @@ subTreeRoot = this.get(subTreeRoot, 'key');

return false;
const _addByProperty = (cur) => {
switch (propertyName) {
case 'key':
cur.key += delta;
break;
default:
cur.key += delta;
break;
}
};
if (this._loopType === types_1.LoopType.RECURSIVE) {
const _traverse = (cur) => {
_addByProperty(cur);
callback(cur);
cur.left && _traverse(cur.left);

@@ -762,3 +753,3 @@ cur.right && _traverse(cur.right);

const cur = stack.pop();
_addByProperty(cur);
callback(cur);
cur.right && stack.push(cur.right);

@@ -781,2 +772,3 @@ cur.left && stack.push(cur.left);

while (queue.length !== 0) {
// TODO Array.shift is not efficient, consider using Deque
const cur = queue.shift();

@@ -798,107 +790,70 @@ if (cur) {

* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'key'`.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns an instance of the BinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.
*/
dfs(pattern = 'in', nodeOrPropertyName = 'key') {
dfs(pattern = 'in', nodeOrPropertyName = 'key', loopType = types_1.LoopType.ITERATIVE) {
this._clearResults();
const _traverse = (node) => {
switch (pattern) {
case 'in':
if (node.left)
_traverse(node.left);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.right)
_traverse(node.right);
break;
case 'pre':
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
break;
case 'post':
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
break;
}
};
this.root && _traverse(this.root);
return this._getResultByPropertyName(nodeOrPropertyName);
}
/**
* The dfsIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
* specify the traversal pattern and the property name to accumulate results by.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. By default, it is set to `'key'`.
* @returns An object of type BinaryTreeNodeProperties<N>.
*/
dfsIterative(pattern = 'in', nodeOrPropertyName = 'key') {
this._clearResults();
if (!this.root)
return this._getResultByPropertyName(nodeOrPropertyName);
// 0: visit, 1: print
const stack = [{ opt: 0, node: this.root }];
while (stack.length > 0) {
const cur = stack.pop();
if (!cur || !cur.node)
continue;
if (cur.opt === 1) {
this._accumulatedByPropertyName(cur.node, nodeOrPropertyName);
}
else {
if (loopType === types_1.LoopType.RECURSIVE) {
const _traverse = (node) => {
switch (pattern) {
case 'in':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
if (node.left)
_traverse(node.left);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.right)
_traverse(node.right);
break;
case 'pre':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
stack.push({ opt: 1, node: cur.node });
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
break;
case 'post':
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
break;
default:
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
break;
}
}
};
this.root && _traverse(this.root);
}
return this._getResultByPropertyName(nodeOrPropertyName);
}
/**
* The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
* in an array, based on a specified property name.
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
* node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
* the tree is used as the starting node.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
* can be either a `BinaryTreeNode` property name or the string `'key'`. If a property name is provided, the function
* will accumulate results based on that property. If no property name is provided, the function will default to
* accumulating results based on the 'key' property.
* @returns An object of type `BinaryTreeNodeProperties<N>`.
*/
levelIterative(node = this.root, nodeOrPropertyName = 'key') {
if (!node)
return [];
this._clearResults();
const queue = [node];
while (queue.length > 0) {
const cur = queue.shift();
if (cur) {
this._accumulatedByPropertyName(cur, nodeOrPropertyName);
if (cur.left) {
queue.push(cur.left);
else {
if (!this.root)
return this._getResultByPropertyName(nodeOrPropertyName);
// 0: visit, 1: print
const stack = [{ opt: 0, node: this.root }];
while (stack.length > 0) {
const cur = stack.pop();
if (!cur || !cur.node)
continue;
if (cur.opt === 1) {
this._accumulatedByPropertyName(cur.node, nodeOrPropertyName);
}
if (cur.right) {
queue.push(cur.right);
else {
switch (pattern) {
case 'in':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
break;
case 'pre':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
stack.push({ opt: 1, node: cur.node });
break;
case 'post':
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
break;
default:
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
break;
}
}

@@ -1109,9 +1064,2 @@ }

/**
* The function sets the loop type for a protected variable.
* @param {LoopType} value - The value parameter is of type LoopType.
*/
_setLoopType(value) {
this._loopType = value;
}
/**
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the

@@ -1118,0 +1066,0 @@ * parent property of the value to undefined.

@@ -9,3 +9,3 @@ /**

import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
import { BinaryTreeDeletedResult, DFSOrderPattern } from '../../types';
import { BinaryTreeDeletedResult, DFSOrderPattern, LoopType } from '../../types';
import { IBinaryTree } from '../../interfaces';

@@ -52,3 +52,3 @@ import { AVLTree, AVLTreeNode } from './avl-tree';

* The function swaps the location of two nodes in a tree data structure.
* @param {N} srcNode - The source node that we want to swap with the destination node.
* @param {N} srcNode - The source node that we want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -58,3 +58,3 @@ * be swapped with.

*/
swapLocation(srcNode: N, destNode: N): N;
protected _swap(srcNode: N, destNode: N): N;
/**

@@ -99,3 +99,3 @@ * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if

/**
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
* The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
* node that needs to be balanced.

@@ -106,5 +106,5 @@ * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:

* not be taken into account when removing it. If `ignoreCount` is set to `false
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
/**

@@ -154,3 +154,3 @@ * The function `getSubTreeCount` calculates the number of nodes and the sum of their counts in a subtree, using either

*/
BFSCount(): number[];
bfsCount(): number[];
/**

@@ -178,15 +178,8 @@ * The function "listLevelsCount" takes a node and returns an array of arrays, where each inner array contains the

* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
* @param loopType - The loopType parameter is a string that specifies the type of loop to use when traversing the
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
* in the dfs traversal.
*/
dfsCountIterative(pattern?: DFSOrderPattern): number[];
dfsCount(pattern?: DFSOrderPattern, loopType?: LoopType): number[];
/**
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
* traversal.
*/
dfsCount(pattern?: DFSOrderPattern): number[];
/**
* The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser

@@ -193,0 +186,0 @@ * value than a given node.

@@ -54,3 +54,3 @@ "use strict";

* The function swaps the location of two nodes in a tree data structure.
* @param {N} srcNode - The source node that we want to swap with the destination node.
* @param {N} srcNode - The source node that we want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -60,3 +60,3 @@ * be swapped with.

*/
swapLocation(srcNode, destNode) {
_swap(srcNode, destNode) {
const { key, val, count, height } = destNode;

@@ -266,3 +266,3 @@ const tempNode = this.createNode(key, val, count);

/**
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
* The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
* node that needs to be balanced.

@@ -273,5 +273,5 @@ * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:

* not be taken into account when removing it. If `ignoreCount` is set to `false
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey, ignoreCount = false) {
delete(nodeOrKey, ignoreCount = false) {
const bstDeletedResult = [];

@@ -310,3 +310,3 @@ if (!this.root)

const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
orgCurrent = this._swap(curr, leftSubTreeRightMost);
if (parentOfLeftSubTreeMax) {

@@ -487,3 +487,3 @@ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {

*/
BFSCount() {
bfsCount() {
const nodes = super.bfs('node');

@@ -520,21 +520,11 @@ return nodes.map(node => node.count);

* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
* @param loopType - The loopType parameter is a string that specifies the type of loop to use when traversing the
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
* in the dfs traversal.
*/
dfsCountIterative(pattern = 'in') {
const nodes = super.dfsIterative(pattern, 'node');
dfsCount(pattern = 'in', loopType = types_1.LoopType.ITERATIVE) {
const nodes = super.dfs(pattern, 'node', loopType);
return nodes.map(node => node.count);
}
/**
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
* traversal.
*/
dfsCount(pattern = 'in') {
const nodes = super.dfs(pattern, 'node');
return nodes.map(node => node.count);
}
/**
* The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser

@@ -541,0 +531,0 @@ * value than a given node.

@@ -51,3 +51,3 @@ import { HashFunction } from '../../types';

get(key: K): V | undefined;
remove(key: K): void;
delete(key: K): void;
entries(): IterableIterator<[K, V]>;

@@ -54,0 +54,0 @@ [Symbol.iterator](): IterableIterator<[K, V]>;

@@ -133,3 +133,3 @@ "use strict";

}
remove(key) {
delete(key) {
const index = this._hash(key);

@@ -136,0 +136,0 @@ if (!this.table[index]) {

@@ -93,9 +93,9 @@ /**

/**
* The remove function removes a key-value pair from a hash table.
* The delete function removes a key-value pair from a hash table.
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
* table.
* @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
* @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
* any value.
*/
remove(key: K): void;
delete(key: K): void;
/**

@@ -102,0 +102,0 @@ * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the

@@ -185,9 +185,9 @@ "use strict";

/**
* The remove function removes a key-value pair from a hash table.
* The delete function removes a key-value pair from a hash table.
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
* table.
* @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
* @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
* any value.
*/
remove(key) {
delete(key) {
const index = this._hash(key);

@@ -194,0 +194,0 @@ let currentNode = this._buckets[index];

@@ -55,8 +55,8 @@ /**

/**
* The `remove` function removes a node with a specific key from a Skip List data structure.
* The `delete` function removes a node with a specific key from a Skip List data structure.
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
* @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
* skip list, and `false` if the key was not found in the skip list.
*/
remove(key: K): boolean;
delete(key: K): boolean;
}

@@ -112,8 +112,8 @@ "use strict";

/**
* The `remove` function removes a node with a specific key from a Skip List data structure.
* The `delete` function removes a node with a specific key from a Skip List data structure.
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
* @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
* skip list, and `false` if the key was not found in the skip list.
*/
remove(key) {
delete(key) {
const update = new Array(this.maxLevel).fill(this.head);

@@ -120,0 +120,0 @@ let current = this.head;

@@ -153,3 +153,3 @@ /**

/**
* The remove function removes an element from an array at a specified index.
* The delete function removes an element from an array at a specified index.
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It

@@ -159,3 +159,3 @@ * is a number that represents the index of the element to be removed.

*/
remove(index: number): E[];
delete(index: number): E[];
/**

@@ -162,0 +162,0 @@ * The function checks if an array called "_nodes" is empty.

@@ -259,3 +259,3 @@ "use strict";

/**
* The remove function removes an element from an array at a specified index.
* The delete function removes an element from an array at a specified index.
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It

@@ -265,3 +265,3 @@ * is a number that represents the index of the element to be removed.

*/
remove(index) {
delete(index) {
return this._nodes.splice(index, 1);

@@ -268,0 +268,0 @@ }

@@ -97,3 +97,3 @@ "use strict";

return first;
// only remove dequeued elements when reaching half size
// only delete dequeued elements when reaching half size
// to decrease latency of shifting elements.

@@ -100,0 +100,0 @@ this.nodes = this.nodes.slice(this.offset);

@@ -48,6 +48,6 @@ /**

* Remove a word from the Trie structure.
* @param{string} word - The word to remove.
* @param{string} word - The word to delete.
* @returns {boolean} True if the word was successfully removed.
*/
remove(word: string): boolean;
delete(word: string): boolean;
getHeight(): number;

@@ -54,0 +54,0 @@ /**

@@ -103,6 +103,6 @@ "use strict";

* Remove a word from the Trie structure.
* @param{string} word - The word to remove.
* @param{string} word - The word to delete.
* @returns {boolean} True if the word was successfully removed.
*/
remove(word) {
delete(word) {
word = this._caseProcess(word);

@@ -109,0 +109,0 @@ let isDeleted = false;

@@ -6,3 +6,3 @@ import { BinaryTreeNode } from '../data-structures';

add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
}

@@ -24,4 +24,4 @@ /**

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -31,3 +31,3 @@ * be swapped to.

*/
swapLocation(srcNode: N, destNode: N): N;
protected _swap(srcNode: N, destNode: N): N;
/**

@@ -51,3 +51,3 @@ * The function creates a new AVL tree node with the given key and value.

/**
* The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
* deletion.

@@ -58,3 +58,3 @@ * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be

*/
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
/**

@@ -61,0 +61,0 @@ * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the

@@ -26,4 +26,4 @@ /**

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -33,3 +33,3 @@ * be swapped to.

*/
swapLocation(srcNode, destNode) {
_swap(srcNode, destNode) {
const { key, val, height } = destNode;

@@ -74,3 +74,3 @@ const tempNode = this.createNode(key, val);

/**
* The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
* deletion.

@@ -81,4 +81,4 @@ * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be

*/
remove(key) {
const deletedResults = super.remove(key);
delete(key) {
const deletedResults = super.delete(key);
for (const { needBalanced } of deletedResults) {

@@ -85,0 +85,0 @@ if (needBalanced) {

@@ -58,2 +58,3 @@ /**

get loopType(): LoopType;
set loopType(v: LoopType);
visitedKey: BinaryTreeNodeKey[];

@@ -63,4 +64,4 @@ visitedVal: N['val'][];

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -70,3 +71,3 @@ * be swapped to.

*/
swapLocation(srcNode: N, destNode: N): N;
protected _swap(srcNode: N, destNode: N): N;
/**

@@ -117,9 +118,9 @@ * The clear() function resets the root, size, and maxKey properties to their initial values.

/**
* The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* The `delete` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* containing the deleted node and the node that needs to be balanced.
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeKey`).
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
/**

@@ -243,6 +244,6 @@ * The function calculates the depth of a node in a binary tree.

* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
* @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
* @returns a boolean value.
*/
isSubtreeBST(node: N | null): boolean;
isSubtreeBST(subTreeRoot: N | null): boolean;
/**

@@ -271,12 +272,10 @@ * The function isBST checks if the binary tree is valid binary search tree.

/**
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
* The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
* each node in the subtree should be incremented.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* @param callBack - The `callBack` parameter is a function that takes a node as a parameter and returns a number.
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
subTreeAdd(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
subTreeForeach(subTreeRoot: N | BinaryTreeNodeKey | null, callback: (node: N) => any): boolean;
/**

@@ -320,5 +319,6 @@ * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.

* @param {string} nodeOrPropertyName - The name of the property to accumulate.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns An array of values corresponding to the specified property.
*/
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key', loopType?: LoopType): BinaryTreeNodeKey[];
/**

@@ -328,5 +328,6 @@ * Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.

* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns An array of 'val' properties from each node.
*/
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val', loopType?: LoopType): N[];
/**

@@ -336,70 +337,7 @@ * Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.

* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns An array of binary tree nodes.
*/
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node', loopType?: LoopType): N[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
dfsIterative(): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @returns An array of values corresponding to the specified property.
*/
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of values corresponding to the specified property.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of 'val' properties from each node.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of binary tree nodes.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
levelIterative(): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @returns An array of binary tree node IDs.
*/
levelIterative(node: N | null): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of values corresponding to the specified property.
*/
levelIterative(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of 'val' properties from each node.
*/
levelIterative(node: N | null, nodeOrPropertyName: 'val'): N['val'][];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of binary tree nodes.
*/
levelIterative(node: N | null, nodeOrPropertyName: 'node'): N[];
/**
* Collects nodes from a binary tree by a specified property and organizes them into levels.

@@ -490,7 +428,2 @@ * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.

/**
* The function sets the loop type for a protected variable.
* @param {LoopType} value - The value parameter is of type LoopType.
*/
protected _setLoopType(value: LoopType): void;
/**
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the

@@ -497,0 +430,0 @@ * parent property of the value to undefined.

@@ -117,5 +117,8 @@ /**

}
set loopType(v) {
this._loopType = v;
}
/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -125,3 +128,3 @@ * be swapped to.

*/
swapLocation(srcNode, destNode) {
_swap(srcNode, destNode) {
const { key, val } = destNode;

@@ -263,9 +266,9 @@ const tempNode = this.createNode(key, val);

/**
* The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* The `delete` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
* containing the deleted node and the node that needs to be balanced.
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
* node ID (`BinaryTreeNodeKey`).
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey) {
delete(nodeOrKey) {
const bstDeletedResult = [];

@@ -299,3 +302,3 @@ if (!this.root)

const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
orgCurrent = this._swap(curr, leftSubTreeRightMost);
if (parentOfLeftSubTreeMax) {

@@ -596,8 +599,8 @@ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)

* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
* @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
* @returns a boolean value.
*/
isSubtreeBST(node) {
isSubtreeBST(subTreeRoot) {
// TODO there is a bug
if (!node)
if (!subTreeRoot)
return true;

@@ -612,7 +615,7 @@ if (this._loopType === LoopType.RECURSIVE) {

};
return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
return dfs(subTreeRoot, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
}
else {
const stack = [];
let prev = Number.MIN_SAFE_INTEGER, curr = node;
let prev = Number.MIN_SAFE_INTEGER, curr = subTreeRoot;
while (curr || stack.length > 0) {

@@ -720,12 +723,10 @@ while (curr) {

/**
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
* The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
* each node in the subtree should be incremented.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* @param callBack - The `callBack` parameter is a function that takes a node as a parameter and returns a number.
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
* @returns a boolean value.
*/
subTreeAdd(subTreeRoot, delta, propertyName = 'key') {
subTreeForeach(subTreeRoot, callback) {
if (typeof subTreeRoot === 'number')

@@ -735,15 +736,5 @@ subTreeRoot = this.get(subTreeRoot, 'key');

return false;
const _addByProperty = (cur) => {
switch (propertyName) {
case 'key':
cur.key += delta;
break;
default:
cur.key += delta;
break;
}
};
if (this._loopType === LoopType.RECURSIVE) {
const _traverse = (cur) => {
_addByProperty(cur);
callback(cur);
cur.left && _traverse(cur.left);

@@ -758,3 +749,3 @@ cur.right && _traverse(cur.right);

const cur = stack.pop();
_addByProperty(cur);
callback(cur);
cur.right && stack.push(cur.right);

@@ -777,2 +768,3 @@ cur.left && stack.push(cur.left);

while (queue.length !== 0) {
// TODO Array.shift is not efficient, consider using Deque
const cur = queue.shift();

@@ -794,107 +786,70 @@ if (cur) {

* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'key'`.
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
* @returns an instance of the BinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.
*/
dfs(pattern = 'in', nodeOrPropertyName = 'key') {
dfs(pattern = 'in', nodeOrPropertyName = 'key', loopType = LoopType.ITERATIVE) {
this._clearResults();
const _traverse = (node) => {
switch (pattern) {
case 'in':
if (node.left)
_traverse(node.left);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.right)
_traverse(node.right);
break;
case 'pre':
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
break;
case 'post':
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
break;
}
};
this.root && _traverse(this.root);
return this._getResultByPropertyName(nodeOrPropertyName);
}
/**
* The dfsIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
* specify the traversal pattern and the property name to accumulate results by.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. By default, it is set to `'key'`.
* @returns An object of type BinaryTreeNodeProperties<N>.
*/
dfsIterative(pattern = 'in', nodeOrPropertyName = 'key') {
this._clearResults();
if (!this.root)
return this._getResultByPropertyName(nodeOrPropertyName);
// 0: visit, 1: print
const stack = [{ opt: 0, node: this.root }];
while (stack.length > 0) {
const cur = stack.pop();
if (!cur || !cur.node)
continue;
if (cur.opt === 1) {
this._accumulatedByPropertyName(cur.node, nodeOrPropertyName);
}
else {
if (loopType === LoopType.RECURSIVE) {
const _traverse = (node) => {
switch (pattern) {
case 'in':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
if (node.left)
_traverse(node.left);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.right)
_traverse(node.right);
break;
case 'pre':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
stack.push({ opt: 1, node: cur.node });
this._accumulatedByPropertyName(node, nodeOrPropertyName);
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
break;
case 'post':
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
if (node.left)
_traverse(node.left);
if (node.right)
_traverse(node.right);
this._accumulatedByPropertyName(node, nodeOrPropertyName);
break;
default:
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
break;
}
}
};
this.root && _traverse(this.root);
}
return this._getResultByPropertyName(nodeOrPropertyName);
}
/**
* The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
* in an array, based on a specified property name.
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
* node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
* the tree is used as the starting node.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
* can be either a `BinaryTreeNode` property name or the string `'key'`. If a property name is provided, the function
* will accumulate results based on that property. If no property name is provided, the function will default to
* accumulating results based on the 'key' property.
* @returns An object of type `BinaryTreeNodeProperties<N>`.
*/
levelIterative(node = this.root, nodeOrPropertyName = 'key') {
if (!node)
return [];
this._clearResults();
const queue = [node];
while (queue.length > 0) {
const cur = queue.shift();
if (cur) {
this._accumulatedByPropertyName(cur, nodeOrPropertyName);
if (cur.left) {
queue.push(cur.left);
else {
if (!this.root)
return this._getResultByPropertyName(nodeOrPropertyName);
// 0: visit, 1: print
const stack = [{ opt: 0, node: this.root }];
while (stack.length > 0) {
const cur = stack.pop();
if (!cur || !cur.node)
continue;
if (cur.opt === 1) {
this._accumulatedByPropertyName(cur.node, nodeOrPropertyName);
}
if (cur.right) {
queue.push(cur.right);
else {
switch (pattern) {
case 'in':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
break;
case 'pre':
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
stack.push({ opt: 1, node: cur.node });
break;
case 'post':
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 0, node: cur.node.left });
break;
default:
stack.push({ opt: 0, node: cur.node.right });
stack.push({ opt: 1, node: cur.node });
stack.push({ opt: 0, node: cur.node.left });
break;
}
}

@@ -1105,9 +1060,2 @@ }

/**
* The function sets the loop type for a protected variable.
* @param {LoopType} value - The value parameter is of type LoopType.
*/
_setLoopType(value) {
this._loopType = value;
}
/**
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the

@@ -1114,0 +1062,0 @@ * parent property of the value to undefined.

@@ -9,3 +9,3 @@ /**

import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
import { BinaryTreeDeletedResult, DFSOrderPattern } from '../../types';
import { BinaryTreeDeletedResult, DFSOrderPattern, LoopType } from '../../types';
import { IBinaryTree } from '../../interfaces';

@@ -52,3 +52,3 @@ import { AVLTree, AVLTreeNode } from './avl-tree';

* The function swaps the location of two nodes in a tree data structure.
* @param {N} srcNode - The source node that we want to swap with the destination node.
* @param {N} srcNode - The source node that we want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -58,3 +58,3 @@ * be swapped with.

*/
swapLocation(srcNode: N, destNode: N): N;
protected _swap(srcNode: N, destNode: N): N;
/**

@@ -99,3 +99,3 @@ * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if

/**
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
* The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
* node that needs to be balanced.

@@ -106,5 +106,5 @@ * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:

* not be taken into account when removing it. If `ignoreCount` is set to `false
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
/**

@@ -154,3 +154,3 @@ * The function `getSubTreeCount` calculates the number of nodes and the sum of their counts in a subtree, using either

*/
BFSCount(): number[];
bfsCount(): number[];
/**

@@ -178,15 +178,8 @@ * The function "listLevelsCount" takes a node and returns an array of arrays, where each inner array contains the

* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
* @param loopType - The loopType parameter is a string that specifies the type of loop to use when traversing the
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
* in the dfs traversal.
*/
dfsCountIterative(pattern?: DFSOrderPattern): number[];
dfsCount(pattern?: DFSOrderPattern, loopType?: LoopType): number[];
/**
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
* traversal.
*/
dfsCount(pattern?: DFSOrderPattern): number[];
/**
* The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser

@@ -193,0 +186,0 @@ * value than a given node.

@@ -50,3 +50,3 @@ import { CP, FamilyPosition, LoopType } from '../../types';

* The function swaps the location of two nodes in a tree data structure.
* @param {N} srcNode - The source node that we want to swap with the destination node.
* @param {N} srcNode - The source node that we want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -56,3 +56,3 @@ * be swapped with.

*/
swapLocation(srcNode, destNode) {
_swap(srcNode, destNode) {
const { key, val, count, height } = destNode;

@@ -262,3 +262,3 @@ const tempNode = this.createNode(key, val, count);

/**
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
* The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
* node that needs to be balanced.

@@ -269,5 +269,5 @@ * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:

* not be taken into account when removing it. If `ignoreCount` is set to `false
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
remove(nodeOrKey, ignoreCount = false) {
delete(nodeOrKey, ignoreCount = false) {
const bstDeletedResult = [];

@@ -306,3 +306,3 @@ if (!this.root)

const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
orgCurrent = this._swap(curr, leftSubTreeRightMost);
if (parentOfLeftSubTreeMax) {

@@ -483,3 +483,3 @@ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {

*/
BFSCount() {
bfsCount() {
const nodes = super.bfs('node');

@@ -516,21 +516,11 @@ return nodes.map(node => node.count);

* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
* @param loopType - The loopType parameter is a string that specifies the type of loop to use when traversing the
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
* in the dfs traversal.
*/
dfsCountIterative(pattern = 'in') {
const nodes = super.dfsIterative(pattern, 'node');
dfsCount(pattern = 'in', loopType = LoopType.ITERATIVE) {
const nodes = super.dfs(pattern, 'node', loopType);
return nodes.map(node => node.count);
}
/**
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
* traversal.
*/
dfsCount(pattern = 'in') {
const nodes = super.dfs(pattern, 'node');
return nodes.map(node => node.count);
}
/**
* The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser

@@ -537,0 +527,0 @@ * value than a given node.

@@ -51,3 +51,3 @@ import { HashFunction } from '../../types';

get(key: K): V | undefined;
remove(key: K): void;
delete(key: K): void;
entries(): IterableIterator<[K, V]>;

@@ -54,0 +54,0 @@ [Symbol.iterator](): IterableIterator<[K, V]>;

@@ -130,3 +130,3 @@ /**

}
remove(key) {
delete(key) {
const index = this._hash(key);

@@ -133,0 +133,0 @@ if (!this.table[index]) {

@@ -93,9 +93,9 @@ /**

/**
* The remove function removes a key-value pair from a hash table.
* The delete function removes a key-value pair from a hash table.
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
* table.
* @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
* @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
* any value.
*/
remove(key: K): void;
delete(key: K): void;
/**

@@ -102,0 +102,0 @@ * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the

@@ -181,9 +181,9 @@ /**

/**
* The remove function removes a key-value pair from a hash table.
* The delete function removes a key-value pair from a hash table.
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
* table.
* @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
* @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
* any value.
*/
remove(key) {
delete(key) {
const index = this._hash(key);

@@ -190,0 +190,0 @@ let currentNode = this._buckets[index];

@@ -55,8 +55,8 @@ /**

/**
* The `remove` function removes a node with a specific key from a Skip List data structure.
* The `delete` function removes a node with a specific key from a Skip List data structure.
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
* @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
* skip list, and `false` if the key was not found in the skip list.
*/
remove(key: K): boolean;
delete(key: K): boolean;
}

@@ -108,8 +108,8 @@ /**

/**
* The `remove` function removes a node with a specific key from a Skip List data structure.
* The `delete` function removes a node with a specific key from a Skip List data structure.
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
* @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
* skip list, and `false` if the key was not found in the skip list.
*/
remove(key) {
delete(key) {
const update = new Array(this.maxLevel).fill(this.head);

@@ -116,0 +116,0 @@ let current = this.head;

@@ -153,3 +153,3 @@ /**

/**
* The remove function removes an element from an array at a specified index.
* The delete function removes an element from an array at a specified index.
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It

@@ -159,3 +159,3 @@ * is a number that represents the index of the element to be removed.

*/
remove(index: number): E[];
delete(index: number): E[];
/**

@@ -162,0 +162,0 @@ * The function checks if an array called "_nodes" is empty.

@@ -254,3 +254,3 @@ /**

/**
* The remove function removes an element from an array at a specified index.
* The delete function removes an element from an array at a specified index.
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It

@@ -260,3 +260,3 @@ * is a number that represents the index of the element to be removed.

*/
remove(index) {
delete(index) {
return this._nodes.splice(index, 1);

@@ -263,0 +263,0 @@ }

@@ -93,3 +93,3 @@ /**

return first;
// only remove dequeued elements when reaching half size
// only delete dequeued elements when reaching half size
// to decrease latency of shifting elements.

@@ -96,0 +96,0 @@ this.nodes = this.nodes.slice(this.offset);

@@ -48,6 +48,6 @@ /**

* Remove a word from the Trie structure.
* @param{string} word - The word to remove.
* @param{string} word - The word to delete.
* @returns {boolean} True if the word was successfully removed.
*/
remove(word: string): boolean;
delete(word: string): boolean;
getHeight(): number;

@@ -54,0 +54,0 @@ /**

@@ -99,6 +99,6 @@ /**

* Remove a word from the Trie structure.
* @param{string} word - The word to remove.
* @param{string} word - The word to delete.
* @returns {boolean} True if the word was successfully removed.
*/
remove(word) {
delete(word) {
word = this._caseProcess(word);

@@ -105,0 +105,0 @@ let isDeleted = false;

@@ -6,3 +6,3 @@ import { BinaryTreeNode } from '../data-structures';

add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
}
{
"name": "data-structure-typed",
"version": "1.36.8",
"version": "1.36.9",
"description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",

@@ -37,3 +37,3 @@ "main": "dist/index.js",

"ci": "env && npm run lint && npm run build && npm run update:individuals && npm run test && git fetch --tags && npm run changelog",
"publish:all": "npm run ci && npm publish && sh /scripts/publish_all_subs.sh && sh /scripts/publish_docs.sh"
"publish:all": "npm run ci && npm publish && sh scripts/publish_all_subs.sh && sh scripts/publish_docs.sh"
},

@@ -60,6 +60,6 @@ "repository": {

"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.36.6",
"avl-tree-typed": "^1.36.8",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.36.6",
"bst-typed": "^1.36.6",
"binary-tree-typed": "^1.36.8",
"bst-typed": "^1.36.8",
"dependency-cruiser": "^14.1.0",

@@ -71,3 +71,3 @@ "eslint": "^8.50.0",

"eslint-plugin-import": "^2.28.1",
"heap-typed": "^1.36.6",
"heap-typed": "^1.36.8",
"istanbul-badges-readme": "^1.8.5",

@@ -74,0 +74,0 @@ "jest": "^29.7.0",

@@ -644,2 +644,10 @@ # Data Structure Typed

### Adhere to ES6 standard naming conventions for APIs.
Standardize API conventions by using 'add' and 'delete' for element manipulation methods in all data structures.
Opt for concise and clear method names, avoiding excessive length while ensuring explicit intent.
### Object-oriented programming(OOP)
By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly

@@ -646,0 +654,0 @@ inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the

@@ -36,4 +36,4 @@ /**

/**
* The `swapLocation` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to swap with the destination node.
* The `_swap` function swaps the location of two nodes in a binary tree.
* @param {N} srcNode - The source node that you want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -43,3 +43,3 @@ * be swapped to.

*/
override swapLocation(srcNode: N, destNode: N): N {
protected override _swap(srcNode: N, destNode: N): N {
const {key, val, height} = destNode;

@@ -90,3 +90,3 @@ const tempNode = this.createNode(key, val);

/**
* The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
* deletion.

@@ -97,4 +97,4 @@ * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be

*/
override remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
const deletedResults = super.remove(key);
override delete(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
const deletedResults = super.delete(key);
for (const {needBalanced} of deletedResults) {

@@ -101,0 +101,0 @@ if (needBalanced) {

@@ -167,6 +167,6 @@ import {BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types';

// if (node === this.root && !replacement) {
// // If there's only the root node and no replacement, simply remove the root node
// // If there's only the root node and no replacement, simply delete the root node
// this._setRoot(null);
// } else if (node === this.root || this._isNodeRed(node)) {
// // If the node is the root or a red node, remove it directly
// // If the node is the root or a red node, delete it directly
// if (node.parent!.left === node) {

@@ -209,3 +209,3 @@ // node.parent!.left = replacement;

//
// override remove(nodeOrKey: BinaryTreeNodeKey | N): BinaryTreeDeletedResult<N>[] {
// override delete(nodeOrKey: BinaryTreeNodeKey | N): BinaryTreeDeletedResult<N>[] {
// const node = this.get(nodeOrKey);

@@ -212,0 +212,0 @@ // const result: BinaryTreeDeletedResult<N>[] = [{deleted: undefined, needBalanced: null}];

@@ -73,3 +73,3 @@ /**

* The function swaps the location of two nodes in a tree data structure.
* @param {N} srcNode - The source node that we want to swap with the destination node.
* @param {N} srcNode - The source node that we want to _swap with the destination node.
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will

@@ -79,3 +79,3 @@ * be swapped with.

*/
override swapLocation(srcNode: N, destNode: N): N {
protected override _swap(srcNode: N, destNode: N): N {
const {key, val, count, height} = destNode;

@@ -290,3 +290,3 @@ const tempNode = this.createNode(key, val, count);

/**
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
* The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
* node that needs to be balanced.

@@ -297,5 +297,5 @@ * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:

* not be taken into account when removing it. If `ignoreCount` is set to `false
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
override remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount = false): BinaryTreeDeletedResult<N>[] {
override delete(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount = false): BinaryTreeDeletedResult<N>[] {
const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];

@@ -331,3 +331,3 @@ if (!this.root) return bstDeletedResult;

const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
orgCurrent = this._swap(curr, leftSubTreeRightMost);
if (parentOfLeftSubTreeMax) {

@@ -523,3 +523,3 @@ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {

*/
BFSCount(): number[] {
bfsCount(): number[] {
const nodes = super.bfs('node');

@@ -559,7 +559,8 @@ return nodes.map(node => node.count);

* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
* @param loopType - The loopType parameter is a string that specifies the type of loop to use when traversing the
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
* in the dfs traversal.
*/
dfsCountIterative(pattern: DFSOrderPattern = 'in'): number[] {
const nodes = super.dfsIterative(pattern, 'node');
dfsCount(pattern: DFSOrderPattern = 'in', loopType: LoopType = LoopType.ITERATIVE): number[] {
const nodes = super.dfs(pattern, 'node', loopType);
return nodes.map(node => node.count);

@@ -569,14 +570,2 @@ }

/**
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
* traversal.
*/
dfsCount(pattern: DFSOrderPattern = 'in'): number[] {
const nodes = super.dfs(pattern, 'node');
return nodes.map(node => node.count);
}
/**
* The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser

@@ -583,0 +572,0 @@ * value than a given node.

@@ -160,3 +160,3 @@ import {HashFunction} from '../../types';

remove(key: K): void {
delete(key: K): void {
const index = this._hash(key);

@@ -163,0 +163,0 @@ if (!this.table[index]) {

@@ -216,9 +216,9 @@ /**

/**
* The remove function removes a key-value pair from a hash table.
* The delete function removes a key-value pair from a hash table.
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
* table.
* @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
* @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
* any value.
*/
remove(key: K): void {
delete(key: K): void {
const index = this._hash(key);

@@ -225,0 +225,0 @@ let currentNode = this._buckets[index];

@@ -378,3 +378,3 @@ /**

*/
consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[] {
consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[] {
const nodes: FibonacciHeapNode<E>[] = [];

@@ -452,3 +452,6 @@ if (!head) return nodes;

const nodes = this.consumeLinkedList(this.root);
let x: FibonacciHeapNode<E> | undefined, y: FibonacciHeapNode<E> | undefined, d: number, t: FibonacciHeapNode<E> | undefined;
let x: FibonacciHeapNode<E> | undefined,
y: FibonacciHeapNode<E> | undefined,
d: number,
t: FibonacciHeapNode<E> | undefined;

@@ -455,0 +458,0 @@ for (const node of nodes) {

@@ -133,8 +133,8 @@ /**

/**
* The `remove` function removes a node with a specific key from a Skip List data structure.
* The `delete` function removes a node with a specific key from a Skip List data structure.
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
* @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
* skip list, and `false` if the key was not found in the skip list.
*/
remove(key: K): boolean {
delete(key: K): boolean {
const update: SkipListNode<K, V>[] = new Array(this.maxLevel).fill(this.head);

@@ -141,0 +141,0 @@ let current = this.head;

@@ -280,3 +280,3 @@ /**

/**
* The remove function removes an element from an array at a specified index.
* The delete function removes an element from an array at a specified index.
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It

@@ -286,3 +286,3 @@ * is a number that represents the index of the element to be removed.

*/
remove(index: number) {
delete(index: number) {
return this._nodes.splice(index, 1);

@@ -289,0 +289,0 @@ }

@@ -109,3 +109,3 @@ /**

// only remove dequeued elements when reaching half size
// only delete dequeued elements when reaching half size
// to decrease latency of shifting elements.

@@ -112,0 +112,0 @@ this.nodes = this.nodes.slice(this.offset);

@@ -122,6 +122,6 @@ /**

* Remove a word from the Trie structure.
* @param{string} word - The word to remove.
* @param{string} word - The word to delete.
* @returns {boolean} True if the word was successfully removed.
*/
remove(word: string) {
delete(word: string) {
word = this._caseProcess(word);

@@ -128,0 +128,0 @@ let isDeleted = false;

@@ -9,3 +9,3 @@ import {BinaryTreeNode} from '../data-structures';

remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
}

@@ -44,19 +44,19 @@ import {AVLTree} from '../../../../src';

expect(tree.remove(11)[0].deleted?.key).toBe(11);
expect(tree.delete(11)[0].deleted?.key).toBe(11);
expect(tree.isAVLBalanced()).toBe(true);
expect(node15 && tree.getHeight(node15)).toBe(2);
expect(tree.remove(1)[0].deleted?.key).toBe(1);
expect(tree.delete(1)[0].deleted?.key).toBe(1);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(4);
expect(tree.remove(4)[0].deleted?.key).toBe(4);
expect(tree.delete(4)[0].deleted?.key).toBe(4);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(4);
expect(tree.remove(10)[0].deleted?.key).toBe(10);
expect(tree.delete(10)[0].deleted?.key).toBe(10);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(15)[0].deleted?.key).toBe(15);
expect(tree.delete(15)[0].deleted?.key).toBe(15);
expect(tree.isAVLBalanced()).toBe(true);

@@ -66,31 +66,31 @@

expect(tree.remove(5)[0].deleted?.key).toBe(5);
expect(tree.delete(5)[0].deleted?.key).toBe(5);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(13)[0].deleted?.key).toBe(13);
expect(tree.delete(13)[0].deleted?.key).toBe(13);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(3)[0].deleted?.key).toBe(3);
expect(tree.delete(3)[0].deleted?.key).toBe(3);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(8)[0].deleted?.key).toBe(8);
expect(tree.delete(8)[0].deleted?.key).toBe(8);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(3);
expect(tree.remove(6)[0].deleted?.key).toBe(6);
expect(tree.remove(6).length).toBe(0);
expect(tree.delete(6)[0].deleted?.key).toBe(6);
expect(tree.delete(6).length).toBe(0);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(2);
expect(tree.remove(7)[0].deleted?.key).toBe(7);
expect(tree.delete(7)[0].deleted?.key).toBe(7);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(2);
expect(tree.remove(9)[0].deleted?.key).toBe(9);
expect(tree.delete(9)[0].deleted?.key).toBe(9);
expect(tree.isAVLBalanced()).toBe(true);
expect(tree.getHeight()).toBe(2);
expect(tree.remove(14)[0].deleted?.key).toBe(14);
expect(tree.delete(14)[0].deleted?.key).toBe(14);
expect(tree.isAVLBalanced()).toBe(true);

@@ -97,0 +97,0 @@ expect(tree.getHeight()).toBe(1);

@@ -86,3 +86,3 @@ import {BinaryTree, BinaryTreeNode} from '../../../../src';

test('should remove a node', () => {
test('should delete a node', () => {
const node = binaryTree.add(1);

@@ -92,3 +92,3 @@ expect(binaryTree.size).toBe(1);

if (node) {
const result = binaryTree.remove(node);
const result = binaryTree.delete(node);
expect(result).toHaveLength(1);

@@ -95,0 +95,0 @@ expect(binaryTree.size).toBe(0);

@@ -58,3 +58,3 @@ import {BST, BSTNode} from '../../../../src';

const removed11 = bst.remove(11);
const removed11 = bst.delete(11);
expect(removed11).toBeInstanceOf(Array);

@@ -70,3 +70,3 @@ expect(removed11[0]).toBeDefined();

const removed1 = bst.remove(1);
const removed1 = bst.delete(1);
expect(removed1).toBeInstanceOf(Array);

@@ -81,3 +81,3 @@ expect(removed1[0]).toBeDefined();

const removed4 = bst.remove(4);
const removed4 = bst.delete(4);
expect(removed4).toBeInstanceOf(Array);

@@ -90,3 +90,3 @@ expect(removed4[0]).toBeDefined();

const removed10 = bst.remove(10);
const removed10 = bst.delete(10);
expect(removed10).toBeInstanceOf(Array);

@@ -99,3 +99,3 @@ expect(removed10[0]).toBeDefined();

const removed15 = bst.remove(15);
const removed15 = bst.delete(15);
expect(removed15).toBeInstanceOf(Array);

@@ -109,3 +109,3 @@ expect(removed15[0]).toBeDefined();

const removed5 = bst.remove(5);
const removed5 = bst.delete(5);
expect(removed5).toBeInstanceOf(Array);

@@ -119,3 +119,3 @@ expect(removed5[0]).toBeDefined();

const removed13 = bst.remove(13);
const removed13 = bst.delete(13);
expect(removed13).toBeInstanceOf(Array);

@@ -128,3 +128,3 @@ expect(removed13[0]).toBeDefined();

const removed3 = bst.remove(3);
const removed3 = bst.delete(3);
expect(removed3).toBeInstanceOf(Array);

@@ -137,3 +137,3 @@ expect(removed3[0]).toBeDefined();

const removed8 = bst.remove(8);
const removed8 = bst.delete(8);
expect(removed8).toBeInstanceOf(Array);

@@ -146,3 +146,3 @@ expect(removed8[0]).toBeDefined();

const removed6 = bst.remove(6);
const removed6 = bst.delete(6);
expect(removed6).toBeInstanceOf(Array);

@@ -152,7 +152,7 @@ expect(removed6[0]).toBeDefined();

if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
expect(bst.remove(6).length).toBe(0);
expect(bst.delete(6).length).toBe(0);
expect(bst.isAVLBalanced()).toBe(false);
expect(bst.getHeight()).toBe(3);
const removed7 = bst.remove(7);
const removed7 = bst.delete(7);
expect(removed7).toBeInstanceOf(Array);

@@ -165,3 +165,3 @@ expect(removed7[0]).toBeDefined();

const removed9 = bst.remove(9);
const removed9 = bst.delete(9);
expect(removed9).toBeInstanceOf(Array);

@@ -174,3 +174,3 @@ expect(removed9[0]).toBeDefined();

const removed14 = bst.remove(14);
const removed14 = bst.delete(14);
expect(removed14).toBeInstanceOf(Array);

@@ -269,3 +269,3 @@ expect(removed14[0]).toBeDefined();

const removed11 = objBST.remove(11);
const removed11 = objBST.delete(11);
expect(removed11).toBeInstanceOf(Array);

@@ -281,3 +281,3 @@ expect(removed11[0]).toBeDefined();

const removed1 = objBST.remove(1);
const removed1 = objBST.delete(1);
expect(removed1).toBeInstanceOf(Array);

@@ -292,3 +292,3 @@ expect(removed1[0]).toBeDefined();

const removed4 = objBST.remove(4);
const removed4 = objBST.delete(4);
expect(removed4).toBeInstanceOf(Array);

@@ -301,3 +301,3 @@ expect(removed4[0]).toBeDefined();

const removed10 = objBST.remove(10);
const removed10 = objBST.delete(10);
expect(removed10).toBeInstanceOf(Array);

@@ -310,3 +310,3 @@ expect(removed10[0]).toBeDefined();

const removed15 = objBST.remove(15);
const removed15 = objBST.delete(15);
expect(removed15).toBeInstanceOf(Array);

@@ -320,3 +320,3 @@ expect(removed15[0]).toBeDefined();

const removed5 = objBST.remove(5);
const removed5 = objBST.delete(5);
expect(removed5).toBeInstanceOf(Array);

@@ -330,3 +330,3 @@ expect(removed5[0]).toBeDefined();

const removed13 = objBST.remove(13);
const removed13 = objBST.delete(13);
expect(removed13).toBeInstanceOf(Array);

@@ -339,3 +339,3 @@ expect(removed13[0]).toBeDefined();

const removed3 = objBST.remove(3);
const removed3 = objBST.delete(3);
expect(removed3).toBeInstanceOf(Array);

@@ -348,3 +348,3 @@ expect(removed3[0]).toBeDefined();

const removed8 = objBST.remove(8);
const removed8 = objBST.delete(8);
expect(removed8).toBeInstanceOf(Array);

@@ -357,3 +357,3 @@ expect(removed8[0]).toBeDefined();

const removed6 = objBST.remove(6);
const removed6 = objBST.delete(6);
expect(removed6).toBeInstanceOf(Array);

@@ -363,7 +363,7 @@ expect(removed6[0]).toBeDefined();

if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
expect(objBST.remove(6).length).toBe(0);
expect(objBST.delete(6).length).toBe(0);
expect(objBST.isAVLBalanced()).toBe(false);
expect(objBST.getHeight()).toBe(3);
const removed7 = objBST.remove(7);
const removed7 = objBST.delete(7);
expect(removed7).toBeInstanceOf(Array);

@@ -376,3 +376,3 @@ expect(removed7[0]).toBeDefined();

const removed9 = objBST.remove(9);
const removed9 = objBST.delete(9);
expect(removed9).toBeInstanceOf(Array);

@@ -385,3 +385,3 @@ expect(removed9[0]).toBeDefined();

const removed14 = objBST.remove(14);
const removed14 = objBST.delete(14);
expect(removed14).toBeInstanceOf(Array);

@@ -388,0 +388,0 @@ expect(removed14[0]).toBeDefined();

@@ -22,3 +22,3 @@ import {AVLTree, BST, BSTNode} from '../../../../src';

expect(leftMost?.key).toBe(1);
bst.remove(6);
bst.delete(6);
bst.get(6); // null

@@ -56,3 +56,3 @@ expect(bst.get(6)).toBeNull();

objBST.remove(11);
objBST.delete(11);

@@ -63,3 +63,3 @@ const avlTree = new AVLTree();

expect(avlTree.isAVLBalanced()).toBe(true); // true
avlTree.remove(10);
avlTree.delete(10);
avlTree.isAVLBalanced(); // true

@@ -66,0 +66,0 @@ expect(avlTree.isAVLBalanced()).toBe(true); // true

@@ -34,3 +34,3 @@ // import {RBTree, RBTreeNode} from '../../../../src';

// // Delete a node (e.g., 3) and check if it's gone
// tree.remove(3);
// tree.delete(3);
// expect(tree.has(3)).toBe(false);

@@ -37,0 +37,0 @@ //

@@ -73,3 +73,3 @@ import {TreeMultiset, TreeMultisetNode} from '../../../../src';

const removed11 = treeMultiset.remove(11, true);
const removed11 = treeMultiset.delete(11, true);
expect(removed11 instanceof Array);

@@ -85,3 +85,3 @@ expect(removed11[0]);

const removed1 = treeMultiset.remove(1, true);
const removed1 = treeMultiset.delete(1, true);
expect(removed1 instanceof Array);

@@ -96,3 +96,3 @@ expect(removed1[0]);

const removed4 = treeMultiset.remove(4, true);
const removed4 = treeMultiset.delete(4, true);
expect(removed4 instanceof Array);

@@ -106,3 +106,3 @@ expect(removed4[0]);

const removed10 = treeMultiset.remove(10, true);
const removed10 = treeMultiset.delete(10, true);
expect(removed10 instanceof Array);

@@ -116,3 +116,3 @@ expect(removed10[0]);

const removed15 = treeMultiset.remove(15, true);
const removed15 = treeMultiset.delete(15, true);
expect(removed15 instanceof Array);

@@ -126,3 +126,3 @@ expect(removed15[0]);

const removed5 = treeMultiset.remove(5, true);
const removed5 = treeMultiset.delete(5, true);
expect(removed5 instanceof Array);

@@ -136,3 +136,3 @@ expect(removed5[0]);

const removed13 = treeMultiset.remove(13, true);
const removed13 = treeMultiset.delete(13, true);
expect(removed13 instanceof Array);

@@ -145,3 +145,3 @@ expect(removed13[0]);

const removed3 = treeMultiset.remove(3, true);
const removed3 = treeMultiset.delete(3, true);
expect(removed3 instanceof Array);

@@ -154,3 +154,3 @@ expect(removed3[0]);

const removed8 = treeMultiset.remove(8, true);
const removed8 = treeMultiset.delete(8, true);
expect(removed8 instanceof Array);

@@ -163,3 +163,3 @@ expect(removed8[0]);

const removed6 = treeMultiset.remove(6, true);
const removed6 = treeMultiset.delete(6, true);
expect(removed6 instanceof Array);

@@ -169,3 +169,3 @@ expect(removed6[0]);

if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
expect(treeMultiset.remove(6, true).length).toBe(0);
expect(treeMultiset.delete(6, true).length).toBe(0);
expect(treeMultiset.isAVLBalanced()).toBe(true);

@@ -175,3 +175,3 @@

const removed7 = treeMultiset.remove(7, true);
const removed7 = treeMultiset.delete(7, true);
expect(removed7 instanceof Array);

@@ -184,3 +184,3 @@ expect(removed7[0]);

const removed9 = treeMultiset.remove(9, true);
const removed9 = treeMultiset.delete(9, true);
expect(removed9 instanceof Array);

@@ -193,3 +193,3 @@ expect(removed9[0]);

const removed14 = treeMultiset.remove(14, true);
const removed14 = treeMultiset.delete(14, true);
expect(removed14 instanceof Array);

@@ -305,3 +305,3 @@ expect(removed14[0]);

//
// const removed11 = objTreeMultiset.remove(11, true);
// const removed11 = objTreeMultiset.delete(11, true);
// expect(removed11).toBeInstanceOf(Array);

@@ -317,3 +317,3 @@ // expect(removed11[0]).toBeDefined();

//
// const removed1 = objTreeMultiset.remove(1, true);
// const removed1 = objTreeMultiset.delete(1, true);
// expect(removed1).toBeInstanceOf(Array);

@@ -328,3 +328,3 @@ // expect(removed1[0]).toBeDefined();

//
// const removed4 = objTreeMultiset.remove(4, true);
// const removed4 = objTreeMultiset.delete(4, true);
// expect(removed4).toBeInstanceOf(Array);

@@ -337,3 +337,3 @@ // expect(removed4[0]).toBeDefined();

//
// const removed10 = objTreeMultiset.remove(10, true);
// const removed10 = objTreeMultiset.delete(10, true);
// expect(removed10).toBeInstanceOf(Array);

@@ -346,3 +346,3 @@ // expect(removed10[0]).toBeDefined();

//
// const removed15 = objTreeMultiset.remove(15, true);
// const removed15 = objTreeMultiset.delete(15, true);
// expect(removed15).toBeInstanceOf(Array);

@@ -356,3 +356,3 @@ // expect(removed15[0]).toBeDefined();

//
// const removed5 = objTreeMultiset.remove(5, true);
// const removed5 = objTreeMultiset.delete(5, true);
// expect(removed5).toBeInstanceOf(Array);

@@ -366,3 +366,3 @@ // expect(removed5[0]).toBeDefined();

//
// const removed13 = objTreeMultiset.remove(13, true);
// const removed13 = objTreeMultiset.delete(13, true);
// expect(removed13).toBeInstanceOf(Array);

@@ -375,3 +375,3 @@ // expect(removed13[0]).toBeDefined();

//
// const removed3 = objTreeMultiset.remove(3, true);
// const removed3 = objTreeMultiset.delete(3, true);
// expect(removed3).toBeInstanceOf(Array);

@@ -384,3 +384,3 @@ // expect(removed3[0]).toBeDefined();

//
// const removed8 = objTreeMultiset.remove(8, true);
// const removed8 = objTreeMultiset.delete(8, true);
// expect(removed8).toBeInstanceOf(Array);

@@ -393,3 +393,3 @@ // expect(removed8[0]).toBeDefined();

//
// const removed6 = objTreeMultiset.remove(6, true);
// const removed6 = objTreeMultiset.delete(6, true);
// expect(removed6).toBeInstanceOf(Array);

@@ -399,7 +399,7 @@ // expect(removed6[0]).toBeDefined();

// if (removed6[0].deleted) expect(removed6[0].deleted.key).toBe(6);
// expect(objTreeMultiset.remove(6, true).length).toBe(0);
// expect(objTreeMultiset.delete(6, true).length).toBe(0);
// expect(objTreeMultiset.isAVLBalanced()).toBe(false);
// expect(objTreeMultiset.getHeight()).toBe(3);
//
// const removed7 = objTreeMultiset.remove(7, true);
// const removed7 = objTreeMultiset.delete(7, true);
// expect(removed7).toBeInstanceOf(Array);

@@ -412,3 +412,3 @@ // expect(removed7[0]).toBeDefined();

//
// const removed9 = objTreeMultiset.remove(9, true);
// const removed9 = objTreeMultiset.delete(9, true);
// expect(removed9).toBeInstanceOf(Array);

@@ -421,3 +421,3 @@ // expect(removed9[0]).toBeDefined();

//
// const removed14 = objTreeMultiset.remove(14, true);
// const removed14 = objTreeMultiset.delete(14, true);
// expect(removed14).toBeInstanceOf(Array);

@@ -424,0 +424,0 @@ // expect(removed14[0]).toBeDefined();

@@ -34,3 +34,3 @@ import {DirectedEdge, DirectedGraph, DirectedVertex, VertexKey} from '../../../../src';

it('should remove edges', () => {
it('should delete edges', () => {
const vertex1 = new DirectedVertex('A');

@@ -37,0 +37,0 @@ const vertex2 = new DirectedVertex('B');

@@ -34,3 +34,3 @@ import {UndirectedEdge, UndirectedGraph, UndirectedVertex} from '../../../../src';

it('should remove edges', () => {
it('should delete edges', () => {
const vertex1 = new UndirectedVertex('A');

@@ -37,0 +37,0 @@ const vertex2 = new UndirectedVertex('B');

@@ -39,7 +39,7 @@ import {HashMap} from '../../../../src';

it('should remove values', () => {
it('should delete values', () => {
hashMap.set('one', 1);
hashMap.set('two', 2);
hashMap.remove('one');
hashMap.delete('one');
expect(hashMap.get('one')).toBeUndefined();

@@ -46,0 +46,0 @@ expect(hashMap.size).toBe(1);

@@ -84,3 +84,3 @@ import {HashTableNode, HashTable} from '../../../../src';

it('should remove key-value pair correctly', () => {
it('should delete key-value pair correctly', () => {
const hashTable = new HashTable<string, string>();

@@ -91,3 +91,3 @@ const key = 'testKey';

hashTable.set(key, value);
hashTable.remove(key);
hashTable.delete(key);

@@ -133,6 +133,6 @@ const retrievedValue = hashTable.get(key);

it('should remove values correctly', () => {
it('should delete values correctly', () => {
hashTable.set('one', 1);
hashTable.set('two', 2);
hashTable.remove('one');
hashTable.delete('one');

@@ -145,3 +145,3 @@ expect(hashTable.get('one')).toBeUndefined();

expect(hashTable.get('non-existent')).toBeUndefined();
hashTable.remove('non-existent'); // Removing a non-existent key should not cause errors
hashTable.delete('non-existent'); // Removing a non-existent key should not cause errors
});

@@ -148,0 +148,0 @@

import {FibonacciHeap, MaxHeap, MinHeap} from '../../../../src';
import {logBigOMetricsWrap} from "../../../utils";
import {logBigOMetricsWrap} from '../../../utils';

@@ -204,6 +204,4 @@ describe('Heap Operation Test', () => {

describe('FibonacciHeap Stress Test', () => {
it('should handle a large number of elements efficiently', () => {
const testByMagnitude = (magnitude: number) => {

@@ -233,3 +231,3 @@ const heap = new FibonacciHeap<number>();

expect(heap.size).toBe(0);
}
};

@@ -243,11 +241,16 @@ testByMagnitude(1000);

[
10, 100, 1000, 5000, 10000, 20000, 50000, 75000, 100000,
150000, 200000, 250000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000
].forEach(m => logBigOMetricsWrap((c: number) => {
const result: number[] = [];
for (let i = 0; i < c; i++) result.push(i);
return result;
} , [m], 'loopPush'));
10, 100, 1000, 5000, 10000, 20000, 50000, 75000, 100000, 150000, 200000, 250000, 300000, 400000, 500000, 600000,
700000, 800000, 900000, 1000000
].forEach(m =>
logBigOMetricsWrap(
(c: number) => {
const result: number[] = [];
for (let i = 0; i < c; i++) result.push(i);
return result;
},
[m],
'loopPush'
)
);
});
});

@@ -21,3 +21,3 @@ import {SinglyLinkedList} from '../../../../src';

describe('pop', () => {
it('should remove and return the last element of the list', () => {
it('should delete and return the last element of the list', () => {
list.push(1);

@@ -37,3 +37,3 @@ list.push(2);

describe('shift', () => {
it('should remove and return the first element of the list', () => {
it('should delete and return the first element of the list', () => {
list.push(1);

@@ -114,3 +114,3 @@ list.push(2);

describe('removeValue', () => {
it('should remove the first occurrence of a value from the list', () => {
it('should delete the first occurrence of a value from the list', () => {
list.push(1);

@@ -246,4 +246,4 @@ list.push(2);

describe('remove', () => {
it('should remove and return the element at the specified index', () => {
describe('delete', () => {
it('should delete and return the element at the specified index', () => {
list.push(1);

@@ -263,3 +263,3 @@ list.push(2);

it('should remove and return the first element', () => {
it('should delete and return the first element', () => {
list.push(1);

@@ -272,3 +272,3 @@ list.push(2);

it('should remove and return the last element', () => {
it('should delete and return the last element', () => {
list.push(1);

@@ -275,0 +275,0 @@ list.push(2);

@@ -28,3 +28,3 @@ import {SkipList} from '../../../../src';

it('should remove elements correctly', () => {
it('should delete elements correctly', () => {
skipList.add(1, 'One');

@@ -34,3 +34,3 @@ skipList.add(2, 'Two');

skipList.remove(2);
skipList.delete(2);

@@ -37,0 +37,0 @@ expect(skipList.get(2)).toBeUndefined(); // 修改这里的断言

@@ -30,3 +30,3 @@ import {MaxPriorityQueue} from '../../../../src';

it('should return and remove the smallest element', () => {
it('should return and delete the smallest element', () => {
const priorityQueue = new MaxPriorityQueue<number>();

@@ -33,0 +33,0 @@ priorityQueue.add(5);

@@ -19,3 +19,3 @@ import {Deque, ArrayDeque, ObjectDeque} from '../../../../src';

it('should remove elements from the beginning and end', () => {
it('should delete elements from the beginning and end', () => {
deque.addFirst(1);

@@ -73,3 +73,3 @@ deque.addLast(2);

it('should remove elements from the beginning and end', () => {
it('should delete elements from the beginning and end', () => {
objectDeque.addFirst('one');

@@ -111,3 +111,3 @@ objectDeque.addLast('two');

it('should remove elements from the beginning and end', () => {
it('should delete elements from the beginning and end', () => {
arrayDeque.addFirst(1);

@@ -114,0 +114,0 @@ arrayDeque.addLast(2);

@@ -84,3 +84,3 @@ import {Trie, TrieNode} from '../../../../src';

it('should remove words from Trie', () => {
it('should delete words from Trie', () => {
const trie = new Trie();

@@ -90,6 +90,6 @@ trie.add('apple');

expect(trie.has('apple')).toBe(true);
trie.remove('apple');
trie.delete('apple');
expect(trie.has('apple')).toBe(false);
expect(trie.has('app')).toBe(true);
trie.remove('app');
trie.delete('app');
expect(trie.has('app')).toBe(false);

@@ -777,5 +777,5 @@ });

trie.add('banana');
expect(trie.remove('apple')).toBe(true);
expect(trie.delete('apple')).toBe(true);
expect(trie.has('apple')).toBe(false);
expect(trie.remove('cherry')).toBe(false);
expect(trie.delete('cherry')).toBe(false);
});

@@ -782,0 +782,0 @@

@@ -1,2 +0,2 @@

import {AnyFunction} from "../types";
import {AnyFunction} from '../types';

@@ -27,3 +27,3 @@ const orderReducedBy = 2; // reduction of bigO's order compared to the baseline bigO

let longestArray: any[] = [];
let mostProperties: { [key: string]: any } = {};
let mostProperties: {[key: string]: any} = {};

@@ -40,3 +40,3 @@ function recurse(obj: any) {

}
keys.forEach((key) => {
keys.forEach(key => {
recurse(obj[key]);

@@ -48,3 +48,3 @@ });

if (Array.isArray(input)) {
input.forEach((item) => {
input.forEach(item => {
recurse(item);

@@ -72,10 +72,10 @@ });

const yHat = x.map((val) => slope * val + intercept);
const yHat = x.map(val => slope * val + intercept);
const totalVariation = y.map((val, i) => (val - yHat[i]) ** 2).reduce((acc, val) => acc + val, 0);
const explainedVariation = y.map((val) => (val - (sumY / n)) ** 2).reduce((acc, val) => acc + val, 0);
const explainedVariation = y.map(val => (val - sumY / n) ** 2).reduce((acc, val) => acc + val, 0);
const rSquared = 1 - totalVariation / explainedVariation;
return { slope, intercept, rSquared };
return {slope, intercept, rSquared};
}

@@ -86,3 +86,3 @@

if (runtimes.length !== dataSizes.length) {
return "输入数组的长度不匹配";
return 'Lengths of input arrays do not match';
}

@@ -95,28 +95,28 @@

const complexitiesToCheck: string[] = [
"O(1)", // constant time complexity
"O(log n)", // Logarithmic time complexity
"O(n)", // linear time complexity
"O(n log n)", // linear logarithmic time complexity
"O(n^2)", // squared time complexity
'O(1)', // constant time complexity
'O(log n)', // Logarithmic time complexity
'O(n)', // linear time complexity
'O(n log n)', // linear logarithmic time complexity
'O(n^2)' // squared time complexity
];
for (const complexity of complexitiesToCheck) {
// Calculate data points for fitting
const fittedData: number[] = dataSizes.map((size) => {
if (complexity === "O(1)") {
// Calculate data points for fitting
const fittedData: number[] = dataSizes.map(size => {
if (complexity === 'O(1)') {
return 1; // constant time complexity
} else if (complexity === "O(log n)") {
} else if (complexity === 'O(log n)') {
return Math.log(size);
} else if (complexity === "O(n)") {
} else if (complexity === 'O(n)') {
return size;
} else if (complexity === "O(n log n)") {
} else if (complexity === 'O(n log n)') {
return size * Math.log(size);
} else if (complexity === "O(n^2)") {
} else if (complexity === 'O(n^2)') {
return size ** 2;
} else {
return size ** 10
return size ** 10;
}
});
// Fit the data points using linear regression analysis
// Fit the data points using linear regression analysis
const regressionResult = linearRegression(fittedData, runtimes);

@@ -132,10 +132,40 @@

if (complexities.length === 0) {
return "Unable to estimate";
return 'Unable to estimate';
} else {
return complexities.join(" or ");
return complexities.join(' or ');
}
}
const methodLogs: Map<string, [number, number][] > = new Map();
const methodLogs: Map<string, [number, number][]> = new Map();
export function logBigOMetricsWrap<F extends AnyFunction>(fn: F, args: Parameters<F>, fnName: string) {
const startTime = performance.now();
const result = fn(args);
const endTime = performance.now();
const runTime = endTime - startTime;
const methodName = `${fnName}`;
if (!methodLogs.has(methodName)) {
methodLogs.set(methodName, []);
}
const methodLog = methodLogs.get(methodName);
const maxDataSize = args.length === 1 && typeof args[0] === 'number' ? args[0] : findPotentialN(args);
if (methodLog) {
methodLog.push([runTime, maxDataSize]);
if (methodLog.length >= 20) {
console.log('triggered', methodName, methodLog);
const bigO = estimateBigO(
methodLog.map(([runTime]) => runTime),
methodLog.map(([runTime]) => runTime)
);
console.log(`Estimated Big O: ${bigO}`);
methodLogs.delete(methodName);
}
}
return result;
}
export function logBigOMetrics(target: any, propertyKey: string, descriptor: PropertyDescriptor) {

@@ -157,3 +187,3 @@ const originalMethod = descriptor.value;

const maxDataSize = args.length === 1 && typeof args[0] === "number" ? args[0] : findPotentialN(args);
const maxDataSize = args.length === 1 && typeof args[0] === 'number' ? args[0] : findPotentialN(args);
if (methodLog) {

@@ -164,5 +194,8 @@ methodLog.push([runTime, maxDataSize]);

console.log('triggered', methodName, methodLog);
const bigO = estimateBigO(methodLog.map(([runTime,]) => runTime), methodLog.map(([runTime,]) => runTime));
const bigO = estimateBigO(
methodLog.map(([runTime]) => runTime),
methodLog.map(([runTime]) => runTime)
);
console.log(`Estimated Big O: ${bigO}`);
methodLogs.delete(methodName)
methodLogs.delete(methodName);
}

@@ -176,28 +209,1 @@ }

}
export function logBigOMetricsWrap<F extends AnyFunction>(fn: F, args: Parameters<F>, fnName: string) {
const startTime = performance.now();
const result = fn(args);
const endTime = performance.now();
const runTime = endTime - startTime;
const methodName = `${fnName}`;
if (!methodLogs.has(methodName)) {
methodLogs.set(methodName, []);
}
const methodLog = methodLogs.get(methodName);
const maxDataSize = args.length === 1 && typeof args[0] === "number" ? args[0] : findPotentialN(args);
if (methodLog) {
methodLog.push([runTime, maxDataSize]);
if (methodLog.length >= 20) {
console.log('triggered', methodName, methodLog);
const bigO = estimateBigO(methodLog.map(([runTime,]) => runTime), methodLog.map(([runTime,]) => runTime));
console.log(`Estimated Big O: ${bigO}`);
methodLogs.delete(methodName)
}
}
return result;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc