Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heap-typed

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heap-typed - npm Package Compare versions

Comparing version 1.50.1 to 1.50.2

123

dist/data-structures/base/iterable-base.d.ts

@@ -116,2 +116,68 @@ import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';

*
* The `find` function iterates over the entries of a collection and returns the first value for
* which the callback function returns true.
* @param callbackfn - The callback function that will be called for each entry in the collection. It
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
* the collection. It should return a boolean value indicating whether the current entry matches the
* desired condition.
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
* be passed as the `this` value to the `callbackfn` function. If `thisArg
* @returns The method `find` returns the value of the first element in the iterable that satisfies
* the provided callback function. If no element satisfies the callback function, `undefined` is
* returned.
*/
find(callbackfn: EntryCallback<K, V, [K, V]>, thisArg?: any): [K, V] | undefined;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given key exists in a collection.
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
* the key that we want to check for existence in the data structure.
* @returns a boolean value. It returns true if the key is found in the collection, and false
* otherwise.
*/
has(key: K): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given value exists in a collection.
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
* collection.
* @returns a boolean value, either true or false.
*/
hasValue(value: V): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `get` function retrieves the value associated with a given key from a collection.
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
* searched for in the collection.
* @returns The `get` method returns the value associated with the specified key if it exists in the
* collection, otherwise it returns `undefined`.
*/
get(key: K): V | undefined;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `reduce` function iterates over key-value pairs and applies a callback function to each pair,

@@ -130,3 +196,2 @@ * accumulating a single value.

reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
hasValue(value: V): boolean;
/**

@@ -137,5 +202,7 @@ * Time Complexity: O(n)

print(): void;
abstract isEmpty(): boolean;
abstract clone(): any;
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
}
export declare abstract class IterableElementBase<V> {
export declare abstract class IterableElementBase<E = any, C = any> {
/**

@@ -154,3 +221,3 @@ * Time Complexity: O(n)

*/
[Symbol.iterator](...args: any[]): IterableIterator<V>;
[Symbol.iterator](...args: any[]): IterableIterator<E>;
/**

@@ -166,3 +233,3 @@ * Time Complexity: O(n)

*/
values(): IterableIterator<V>;
values(): IterableIterator<E>;
/**

@@ -186,3 +253,3 @@ * Time Complexity: O(n)

*/
every(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean;
every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
/**

@@ -206,3 +273,3 @@ * Time Complexity: O(n)

*/
some(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean;
some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
/**

@@ -225,3 +292,3 @@ * Time Complexity: O(n)

*/
forEach(callbackfn: ElementCallback<V, void>, thisArg?: any): void;
forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void;
/**

@@ -235,2 +302,38 @@ * Time Complexity: O(n)

*
* The `find` function iterates over the elements of an array-like object and returns the first
* element that satisfies the provided callback function.
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
* the array. It takes three arguments: the current element being processed, the index of the current
* element, and the array itself. The function should return a boolean value indicating whether the
* current element matches the desired condition.
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
* be passed as the `this` value to the `callbackfn` function. If `thisArg
* @returns The `find` method returns the first element in the array that satisfies the provided
* callback function. If no element satisfies the callback function, `undefined` is returned.
*/
find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given element exists in a collection.
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
* represents the element that we want to check for existence in the collection.
* @returns a boolean value. It returns true if the element is found in the collection, and false
* otherwise.
*/
has(element: E): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `reduce` function iterates over the elements of an array-like object and applies a callback

@@ -245,3 +348,3 @@ * function to reduce them into a single value.

*/
reduce<U>(callbackfn: ReduceElementCallback<V, U>, initialValue: U): U;
reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U;
/**

@@ -252,3 +355,5 @@ * Time Complexity: O(n)

print(): void;
protected abstract _getIterator(...args: any[]): IterableIterator<V>;
abstract isEmpty(): boolean;
abstract clone(): C;
protected abstract _getIterator(...args: any[]): IterableIterator<E>;
}

@@ -154,2 +154,96 @@ "use strict";

*
* The `find` function iterates over the entries of a collection and returns the first value for
* which the callback function returns true.
* @param callbackfn - The callback function that will be called for each entry in the collection. It
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
* the collection. It should return a boolean value indicating whether the current entry matches the
* desired condition.
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
* be passed as the `this` value to the `callbackfn` function. If `thisArg
* @returns The method `find` returns the value of the first element in the iterable that satisfies
* the provided callback function. If no element satisfies the callback function, `undefined` is
* returned.
*/
find(callbackfn, thisArg) {
let index = 0;
for (const item of this) {
const [key, value] = item;
if (callbackfn.call(thisArg, value, key, index++, this))
return item;
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given key exists in a collection.
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
* the key that we want to check for existence in the data structure.
* @returns a boolean value. It returns true if the key is found in the collection, and false
* otherwise.
*/
has(key) {
for (const item of this) {
const [itemKey] = item;
if (itemKey === key)
return true;
}
return false;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given value exists in a collection.
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
* collection.
* @returns a boolean value, either true or false.
*/
hasValue(value) {
for (const [, elementValue] of this) {
if (elementValue === value)
return true;
}
return false;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `get` function retrieves the value associated with a given key from a collection.
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
* searched for in the collection.
* @returns The `get` method returns the value associated with the specified key if it exists in the
* collection, otherwise it returns `undefined`.
*/
get(key) {
for (const item of this) {
const [itemKey, value] = item;
if (itemKey === key)
return value;
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `reduce` function iterates over key-value pairs and applies a callback function to each pair,

@@ -176,9 +270,2 @@ * accumulating a single value.

}
hasValue(value) {
for (const [, elementValue] of this) {
if (elementValue === value)
return true;
}
return false;
}
/**

@@ -310,2 +397,51 @@ * Time Complexity: O(n)

*
* The `find` function iterates over the elements of an array-like object and returns the first
* element that satisfies the provided callback function.
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
* the array. It takes three arguments: the current element being processed, the index of the current
* element, and the array itself. The function should return a boolean value indicating whether the
* current element matches the desired condition.
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
* be passed as the `this` value to the `callbackfn` function. If `thisArg
* @returns The `find` method returns the first element in the array that satisfies the provided
* callback function. If no element satisfies the callback function, `undefined` is returned.
*/
find(callbackfn, thisArg) {
let index = 0;
for (const item of this) {
if (callbackfn.call(thisArg, item, index++, this))
return item;
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given element exists in a collection.
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
* represents the element that we want to check for existence in the collection.
* @returns a boolean value. It returns true if the element is found in the collection, and false
* otherwise.
*/
has(element) {
for (const ele of this) {
if (ele === element)
return true;
}
return false;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `reduce` function iterates over the elements of an array-like object and applies a callback

@@ -312,0 +448,0 @@ * function to reduce them into a single value.

89

dist/data-structures/binary-tree/avl-tree.d.ts

@@ -11,3 +11,3 @@ /**

import { IBinaryTree } from '../../interfaces';
export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
height: number;

@@ -25,6 +25,6 @@ constructor(key: K, value?: V);

*/
export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
export declare class AVLTree<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, NODE, TREE> = AVLTree<K, V, NODE, AVLTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
/**
* The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
* objects. It represents a collection of nodes that will be added to the AVL tree during

@@ -36,3 +36,3 @@ * initialization.

*/
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: AVLTreeOptions<K>);
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeOptions<K>);
/**

@@ -44,6 +44,6 @@ * The function creates a new AVL tree node with the specified key and value.

* type `V`, which means it can be any value that is assignable to the `value` property of the
* node type `N`.
* node type `NODE`.
* @returns a new AVLTreeNode object with the specified key and value.
*/
createNode(key: K, value?: V): N;
createNode(key: K, value?: V): NODE;
/**

@@ -59,6 +59,6 @@ * The function creates a new AVL tree with the specified options and returns it.

* The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
*/
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
/**

@@ -81,3 +81,3 @@ * Time Complexity: O(log n)

*/
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
/**

@@ -99,12 +99,12 @@ * Time Complexity: O(log n)

* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
* parameter of type `N
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
* parameter of type `NODE
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
*/
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<N>[];
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<NODE>[];
/**
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
* tree.
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
* needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
* node where the values from the source node will be swapped to.

@@ -114,7 +114,6 @@ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`

*/
protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
*/

@@ -126,11 +125,10 @@ /**

* The function calculates the balance factor of a node in a binary tree.
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
* height of the left subtree from the height of the right subtree.
*/
protected _balanceFactor(node: N): number;
protected _balanceFactor(node: NODE): number;
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
*/

@@ -143,24 +141,20 @@ /**

* right children.
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
*/
protected _updateHeight(node: N): void;
protected _updateHeight(node: NODE): void;
/**
* Time Complexity: O(log n)
* Time Complexity: O(1)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(log n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
* to restore balance in an AVL tree after inserting a node.
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
* AVL tree that needs to be balanced.
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void;
protected _balanceLL(A: NODE): void;
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
*/

@@ -171,6 +165,6 @@ /**

*
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceLL(A: N): void;
protected _balanceLR(A: NODE): void;
/**

@@ -184,6 +178,6 @@ * Time Complexity: O(1)

*
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceLR(A: N): void;
protected _balanceRR(A: NODE): void;
/**

@@ -197,19 +191,22 @@ * Time Complexity: O(1)

*
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceRR(A: N): void;
protected _balanceRL(A: NODE): void;
/**
* Time Complexity: O(1)
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(1)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
* to restore balance in an AVL tree after inserting a node.
* @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
* AVL tree that needs to be balanced.
*/
protected _balanceRL(A: N): void;
protected _replaceNode(oldNode: N, newNode: N): N;
protected _balancePath(node: KeyOrNodeOrEntry<K, V, NODE>): void;
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
}

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

* The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
* objects. It represents a collection of nodes that will be added to the AVL tree during

@@ -50,3 +50,3 @@ * initialization.

* type `V`, which means it can be any value that is assignable to the `value` property of the
* node type `N`.
* node type `NODE`.
* @returns a new AVLTreeNode object with the specified key and value.

@@ -69,3 +69,3 @@ */

* The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.

@@ -117,4 +117,4 @@ */

* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
* parameter of type `N
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
* parameter of type `NODE
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
*/

@@ -135,5 +135,5 @@ delete(identifier, callback = this._defaultOneParamCallback) {

* tree.
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
* needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
* node where the values from the source node will be swapped to.

@@ -165,3 +165,2 @@ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`

* Space Complexity: O(1)
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
*/

@@ -173,3 +172,3 @@ /**

* The function calculates the balance factor of a node in a binary tree.
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the

@@ -191,3 +190,2 @@ * height of the left subtree from the height of the right subtree.

* Space Complexity: O(1)
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
*/

@@ -200,3 +198,3 @@ /**

* right children.
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
*/

@@ -216,59 +214,4 @@ _updateHeight(node) {

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
* to restore balance in an AVL tree after inserting a node.
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
* AVL tree that needs to be balanced.
*/
_balancePath(node) {
node = this.ensureNode(node);
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
for (let i = 0; i < path.length; i++) {
// second O(log n)
const A = path[i];
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
this._updateHeight(A); // first O(1)
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
switch (this._balanceFactor(A) // second O(1)
) {
case -2:
if (A && A.left) {
if (this._balanceFactor(A.left) <= 0) {
// second O(1)
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
this._balanceLL(A);
}
else {
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
this._balanceLR(A);
}
}
break;
case +2:
if (A && A.right) {
if (this._balanceFactor(A.right) >= 0) {
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
this._balanceRR(A);
}
else {
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
this._balanceRL(A);
}
}
}
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
}
}
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
*/

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

* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/

@@ -322,3 +265,3 @@ _balanceLL(A) {

* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/

@@ -379,3 +322,3 @@ _balanceLR(A) {

* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/

@@ -422,3 +365,3 @@ _balanceRR(A) {

* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/

@@ -470,2 +413,56 @@ _balanceRL(A) {

}
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
* to restore balance in an AVL tree after inserting a node.
* @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
* AVL tree that needs to be balanced.
*/
_balancePath(node) {
node = this.ensureNode(node);
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
for (let i = 0; i < path.length; i++) {
// second O(log n)
const A = path[i];
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
this._updateHeight(A); // first O(1)
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
switch (this._balanceFactor(A) // second O(1)
) {
case -2:
if (A && A.left) {
if (this._balanceFactor(A.left) <= 0) {
// second O(1)
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
this._balanceLL(A);
}
else {
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
this._balanceLR(A);
}
}
break;
case +2:
if (A && A.right) {
if (this._balanceFactor(A.right) >= 0) {
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
this._balanceRR(A);
}
else {
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
this._balanceRL(A);
}
}
}
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
}
}
_replaceNode(oldNode, newNode) {

@@ -472,0 +469,0 @@ newNode.height = oldNode.height;

@@ -15,16 +15,44 @@ /**

* @template V - The type of data stored in the node.
* @template N - The type of the family relationship in the binary tree.
* @template NODE - The type of the family relationship in the binary tree.
*/
export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
key: K;
value?: V;
parent?: N;
parent?: NODE;
/**
* The constructor function initializes an object with a key and an optional value.
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
* constructor. It is used to set the value of the "key" property of the object being created.
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
* value associated with the key in the constructor.
*/
constructor(key: K, value?: V);
protected _left?: N | null;
get left(): N | null | undefined;
set left(v: N | null | undefined);
protected _right?: N | null;
get right(): N | null | undefined;
set right(v: N | null | undefined);
protected _left?: NODE | null;
/**
* The function returns the value of the `_left` property, which can be of type `NODE`, `null`, or
* `undefined`.
* @returns The left node of the current node is being returned. It can be either a NODE object,
* null, or undefined.
*/
get left(): NODE | null | undefined;
/**
* The function sets the left child of a node and updates its parent reference.
* @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
* `undefined`.
*/
set left(v: NODE | null | undefined);
protected _right?: NODE | null;
/**
* The function returns the right node of a binary tree or null if it doesn't exist.
* @returns The method is returning the value of the `_right` property, which can be a `NODE` object,
* `null`, or `undefined`.
*/
get right(): NODE | null | undefined;
/**
* The function sets the right child of a node and updates its parent.
* @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
* `undefined`.
*/
set right(v: NODE | null | undefined);
/**
* Get the position of the node within its family.

@@ -42,3 +70,3 @@ * @returns {FamilyPosition} - The family position of the node.

*/
export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, NODE, TREE> = BinaryTree<K, V, NODE, BinaryTreeNested<K, V, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, NODE, TREE> {
iterationType: IterationType;

@@ -54,8 +82,21 @@ /**

*/
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: BinaryTreeOptions<K>);
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions<K>);
protected _extractor: (key: K) => number;
/**
* The function returns the value of the `_extractor` property.
* @returns The `_extractor` property is being returned.
*/
get extractor(): (key: K) => number;
protected _root?: N | null;
get root(): N | null | undefined;
protected _root?: NODE | null;
/**
* The function returns the root node, which can be of type NODE, null, or undefined.
* @returns The method is returning the value of the `_root` property, which can be of type `NODE`,
* `null`, or `undefined`.
*/
get root(): NODE | null | undefined;
protected _size: number;
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number;

@@ -66,5 +107,5 @@ /**

* @param {V} value - The value for the new node.
* @returns {N} - The newly created BinaryTreeNode.
* @returns {NODE} - The newly created BinaryTreeNode.
*/
createNode(key: K, value?: V): N;
createNode(key: K, value?: V): NODE;
/**

@@ -79,10 +120,10 @@ * The function creates a binary tree with the given options.

/**
* The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If no value
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If no value
* is provided, it will be `undefined`.
* @returns a value of type N (node), or null, or undefined.
* @returns a value of type NODE (node), or null, or undefined.
*/
exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | null | undefined;
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | null | undefined;
/**

@@ -98,3 +139,3 @@ * Time Complexity: O(n)

* key, otherwise it returns the key itself.
* @param {K | N | null | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`,
* @param {K | NODE | null | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`,
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.

@@ -107,21 +148,17 @@ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the

*/
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
/**
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,N>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class N.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class NODE.
*/
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
/**
* The function checks if a given value is an entry in a binary tree node.
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,N> - A generic type representing a node in a binary tree. It has
* two type parameters V and N, representing the value and node type respectively.
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
* two type parameters V and NODE, representing the value and node type respectively.
* @returns a boolean value.
*/
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is BTNEntry<K, V>;
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
/**
* Time complexity: O(n)
* Space complexity: O(log n)
*/
/**
* The function checks if a given node is a real node by verifying if it is an instance of

@@ -132,3 +169,3 @@ * BinaryTreeNode and its key is not NaN.

*/
isRealNode(node: KeyOrNodeOrEntry<K, V, N>): node is N;
isRealNode(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE;
/**

@@ -139,3 +176,3 @@ * The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.

*/
isNIL(node: KeyOrNodeOrEntry<K, V, N>): boolean;
isNIL(node: KeyOrNodeOrEntry<K, V, NODE>): boolean;
/**

@@ -146,9 +183,9 @@ * The function checks if a given node is a real node or null.

*/
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, N>): node is N | null;
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
/**
* Time Complexity O(log n) - O(n)
* Time Complexity O(n)
* Space Complexity O(1)
*/
/**
* Time Complexity O(log n) - O(n)
* Time Complexity O(n)
* Space Complexity O(1)

@@ -160,7 +197,7 @@ *

* @param {V} [value] - The value to be inserted into the binary tree.
* @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
* @returns The function `add` returns either a node (`NODE`), `null`, or `undefined`.
*/
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
/**
* Time Complexity: O(k log n) - O(k * n)
* Time Complexity: O(k * n)
* Space Complexity: O(1)

@@ -170,3 +207,3 @@ * Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.

/**
* Time Complexity: O(k log n) - O(k * n)
* Time Complexity: O(k * n)
* Space Complexity: O(1)

@@ -178,5 +215,5 @@ *

* @param [values] - An optional iterable of values that will be assigned to each node being added.
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
* @returns The function `addMany` returns an array of `NODE`, `null`, or `undefined` values.
*/
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): boolean[];
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
/**

@@ -193,3 +230,3 @@ * Time Complexity: O(k * n)

* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries. These can be of type
* KeyOrNodeOrEntry<K, V, N>.
* KeyOrNodeOrEntry<K, V, NODE>.
* @param [values] - The `values` parameter is an optional iterable that contains the values to be

@@ -200,71 +237,63 @@ * associated with the keys or nodes or entries in the `keysOrNodesOrEntries` parameter. If provided,

*/
refill(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): void;
refill(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): void;
delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
delete<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<NODE>[];
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
getNode<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
/**
* Time Complexity: O(k * n)
* Space Complexity: O(1)
* "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
*/
delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<N>[];
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<N>[];
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
* Space Complexity: O(log n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
* Space Complexity: O(log n)
*
* The function calculates the depth of a given node in a binary tree.
* @param {K | N | null | undefined} dist - The `dist` parameter represents the node in
* the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
* `undefined`.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
* @returns the depth of the `dist` relative to the `beginRoot`.
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
* recursive or iterative iteration.
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
* It is used to find the node with the matching key value.
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
* the node with the given key should be performed iteratively or recursively. It has two possible
* values:
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
* found in the binary tree. If no node is found, it returns `undefined`.
*/
getDepth(dist: KeyOrNodeOrEntry<K, V, N>, beginRoot?: KeyOrNodeOrEntry<K, V, N>): number;
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
has<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
/**
* Time Complexity: O(n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
* iterative traversal.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node of the binary tree from which we want to calculate the height. It can be of type
* `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
* height of the tree using a recursive approach or an iterative approach. It can have two possible
* values:
* @returns the height of the binary tree.
* Clear the binary tree, removing all nodes.
*/
getHeight(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): number;
clear(): void;
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
* recursive or iterative approach.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
* type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
* to calculate the minimum height of a binary tree. It can have two possible values:
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
* Check if the binary tree is empty.
* @returns {boolean} - True if the binary tree is empty, false otherwise.
*/
getMinHeight(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): number;
isEmpty(): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
*/

@@ -277,82 +306,93 @@ /**

* height of the tree.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
* for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
* value of a binary tree node), `NODE` (a node of a binary tree), `null`, or `undefined`. If
* @returns a boolean value.
*/
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V, N>): boolean;
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
* Space Complexity: O(1)
*/
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
/**
* Time Complexity: O(n)
* Space Complexity: O(log n).
* Space Complexity: O(1)
*
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the root
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
* possible values:
* @returns a boolean value.
*/
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(log n).
* Space Complexity: O(1)
*/
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
* Space Complexity: O(1)
*
* The function calculates the depth of a given node in a binary tree.
* @param {K | NODE | null | undefined} dist - The `dist` parameter represents the node in
* the binary tree whose depth we want to find. It can be of type `K`, `NODE`, `null`, or
* `undefined`.
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
* `NODE` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
* @returns the depth of the `dist` relative to the `beginRoot`.
*/
getDepth(dist: KeyOrNodeOrEntry<K, V, NODE>, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): number;
/**
* Time Complexity: O(n)
* Space Complexity: O(log n)
*
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
* recursive or iterative iteration.
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
* It is used to find the node with the matching key value.
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
* the node with the given key should be performed iteratively or recursively. It has two possible
* values:
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
* found in the binary tree. If no node is found, it returns `undefined`.
*/
getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* Time Complexity: O(n)
* Space Complexity: O(log n)
*
* Clear the binary tree, removing all nodes.
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
* iterative traversal.
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node of the binary tree from which we want to calculate the height. It can be of type
* `K`, `NODE`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
* height of the tree using a recursive approach or an iterative approach. It can have two possible
* values:
* @returns the height of the binary tree.
*/
clear(): void;
getHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* Time Complexity: O(n)
* Space Complexity: O(log n)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* Time Complexity: O(n)
* Space Complexity: O(log n)
*
* Check if the binary tree is empty.
* @returns {boolean} - True if the binary tree is empty, false otherwise.
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
* recursive or iterative approach.
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
* type `K`, `NODE`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
* to calculate the minimum height of a binary tree. It can have two possible values:
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
*/
isEmpty(): boolean;
getMinHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
/**
* Time Complexity: O(log n)
* Space Complexity: O(log n)
* /
/**
* Time Complexity: O(log n)
* Space Complexity: O(log n)
*
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
* structure, with the option to reverse the order of the nodes.
* @param {K | N | null | undefined} beginNode - The `beginRoot` parameter represents the
* starting node from which you want to find the path to the root. It can be of type `K`, `N`,
* @param {K | NODE | null | undefined} beginNode - The `beginRoot` parameter represents the
* starting node from which you want to find the path to the root. It can be of type `K`, `NODE`,
* `null`, or `undefined`.

@@ -362,5 +402,5 @@ * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the

* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
* @returns The function `getPathToRoot` returns an array of nodes (`NODE[]`).
*/
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V, N>, isReverse?: boolean): N[];
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
/**

@@ -376,11 +416,11 @@ * Time Complexity: O(log n)

* iteratively.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `N` (a
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `NODE` (a
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
* @returns The function `getLeftMost` returns the leftmost node (`NODE`) in the binary tree. If there
* is no leftmost node, it returns `null` or `undefined` depending on the input.
*/
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
/**

@@ -396,4 +436,4 @@ * Time Complexity: O(log n)

* iteratively.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node from which we want to find the rightmost node. It can be of type `K`, `N`,
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node from which we want to find the rightmost node. It can be of type `K`, `NODE`,
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the

@@ -403,6 +443,6 @@ * current object.

* type of iteration to use when finding the rightmost node. It can have one of two values:
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
* @returns The function `getRightMost` returns the rightmost node (`NODE`) in a binary tree. If there
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
*/
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
/**

@@ -413,29 +453,12 @@ * Time Complexity: O(log n)

/**
* Time Complexity: O(n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
* possible values:
* @returns a boolean value.
* The function returns the predecessor of a given node in a tree.
* @param {NODE} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
* tree.
* @returns the predecessor of the given 'node'.
*/
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
dfs<C extends BTNCallback<N | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
getPredecessor(node: NODE): NODE;
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
bfs<C extends BTNCallback<N | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
listLevels<C extends BTNCallback<N | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
/**
* Time Complexity: O(log n)

@@ -448,15 +471,14 @@ * Space Complexity: O(1)

*
* The function returns the predecessor of a given node in a tree.
* @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
* tree.
* @returns the predecessor of the given 'node'.
*/
getPredecessor(node: N): N;
/**
* The function `getSuccessor` returns the next node in a binary tree given a current node.
* @param {K | N | null} [x] - The parameter `x` can be of type `K`, `N`, or `null`.
* @param {K | NODE | null} [x] - The parameter `x` can be of type `K`, `NODE`, or `null`.
* @returns the successor of the given node or key. The successor is the node that comes immediately
* after the given node in the inorder traversal of the binary tree.
*/
getSuccessor(x?: K | N | null): N | null | undefined;
getSuccessor(x?: K | NODE | null): NODE | null | undefined;
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
/**

@@ -473,3 +495,3 @@ * Time complexity: O(n)

* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the tree. It takes a single parameter of type `N` (the type of the nodes in the tree) and returns
* the tree. It takes a single parameter of type `NODE` (the type of the nodes in the tree) and returns
* a value of any type.

@@ -479,3 +501,3 @@ * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function

* following values:
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate

@@ -487,3 +509,3 @@ * the root of the tree. If no value is provided, the default value is the root of the tree.

*/
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>): ReturnType<C>[];
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
/**

@@ -551,3 +573,3 @@ * Time complexity: O(n)

* The `print` function is used to display a binary tree structure in a visually appealing way.
* @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
* @param {K | NODE | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | NODE | null |
* undefined`. It represents the root node of a binary tree. The root node can have one of the

@@ -557,29 +579,52 @@ * following types:

*/
print(beginRoot?: KeyOrNodeOrEntry<K, V, N>, options?: BinaryTreePrintOptions): void;
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
protected _defaultOneParamCallback: (node: N | null | undefined) => K | undefined;
print(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): void;
/**
* The function `_getIterator` is a protected generator function that returns an iterator for the
* key-value pairs in a binary search tree.
* @param node - The `node` parameter represents the current node in the binary search tree. It is an
* optional parameter with a default value of `this.root`, which means if no node is provided, the
* root node of the tree will be used as the starting point for iteration.
* @returns The function `_getIterator` returns an `IterableIterator` of key-value pairs `[K, V |
* undefined]`.
*/
protected _getIterator(node?: NODE | null | undefined): IterableIterator<[K, V | undefined]>;
/**
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
* taking into account various options such as whether to show null, undefined, or NaN nodes.
* @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
* It can be of type `NODE`, `null`, or `undefined`.
* @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
* following properties:
* @returns The function `_displayAux` returns a `NodeDisplayLayout` which is an array containing the
* following elements:
* 1. `mergedLines`: An array of strings representing the lines of the node display.
* 2. `totalWidth`: The total width of the node display.
* 3. `totalHeight`: The total height of the node display.
* 4. `middleIndex`: The index of the middle character
*/
protected _displayAux(node: NODE | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
protected _defaultOneParamCallback: (node: NODE | null | undefined) => K | undefined;
/**
* Swap the data of two nodes in the binary tree.
* @param {N} srcNode - The source node to swap.
* @param {N} destNode - The destination node to swap.
* @returns {N} - The destination node after the swap.
* @param {NODE} srcNode - The source node to swap.
* @param {NODE} destNode - The destination node to swap.
* @returns {NODE} - The destination node after the swap.
*/
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V, N>, destNode: KeyOrNodeOrEntry<K, V, N>): N | undefined;
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V, NODE>, destNode: KeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
/**
* The function replaces an old node with a new node in a binary tree.
* @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
* tree.
* @param {N} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* tree.
* @returns The method is returning the newNode.
*/
protected _replaceNode(oldNode: N, newNode: N): N;
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
/**
* The function sets the root property of an object to a given value, and if the value is not null,
* it also sets the parent property of the value to undefined.
* @param {N | null | undefined} v - The parameter `v` is of type `N | null | undefined`, which means it can either be of
* type `N` or `null`.
* @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`, which means it can either be of
* type `NODE` or `null`.
*/
protected _setRoot(v: N | null | undefined): void;
protected _setRoot(v: NODE | null | undefined): void;
}

@@ -12,25 +12,11 @@ /**

import { IBinaryTree } from '../../interfaces';
export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, N> {
parent?: N;
export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
parent?: NODE;
constructor(key: K, value?: V);
protected _left?: N;
/**
* Get the left child node.
*/
get left(): N | undefined;
/**
* Set the left child node.
* @param {N | undefined} v - The left child node.
*/
set left(v: N | undefined);
protected _right?: N;
/**
* Get the right child node.
*/
get right(): N | undefined;
/**
* Set the right child node.
* @param {N | undefined} v - The right child node.
*/
set right(v: N | undefined);
protected _left?: NODE;
get left(): NODE | undefined;
set left(v: NODE | undefined);
protected _right?: NODE;
get right(): NODE | undefined;
set right(v: NODE | undefined);
}

@@ -46,3 +32,3 @@ /**

*/
export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, N, TREE> = BST<K, V, N, BSTNested<K, V, N>>> extends BinaryTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
/**

@@ -56,5 +42,5 @@ * This is the constructor function for a binary search tree class in TypeScript, which initializes

*/
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: BSTOptions<K>);
protected _root?: N;
get root(): N | undefined;
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K>);
protected _root?: NODE;
get root(): NODE | undefined;
protected _variant: BSTVariant;

@@ -70,3 +56,3 @@ get variant(): BSTVariant;

*/
createNode(key: K, value?: V): N;
createNode(key: K, value?: V): NODE;
/**

@@ -81,14 +67,13 @@ * The function creates a new binary search tree with the specified options.

/**
* The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
* otherwise it returns undefined.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
* @returns a node of type N or undefined.
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
* @returns a node of type NODE or undefined.
*/
exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined;
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
/**
* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Average case for a balanced tree. Space for the recursive call stack in the worst case.
*/

@@ -101,19 +86,18 @@ /**

* otherwise it returns the key itself.
* @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
* `undefined`.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
* @returns either a node object (N) or undefined.
* @returns either a node object (NODE) or undefined.
*/
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | undefined;
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
/**
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
*/
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
*/

@@ -132,11 +116,10 @@ /**

*/
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
/**
* Time Complexity: O(k log n)
* Space Complexity: O(k)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
* Space Complexity: O(k + log n)
*/
/**
* Time Complexity: O(k log n)
* Space Complexity: O(k)
* Space Complexity: O(k + log n)
*

@@ -157,5 +140,5 @@ * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally

* `this.iterationType`, which suggests that it is a property of the current object.
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
* @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
*/
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
/**

@@ -176,10 +159,9 @@ * Time Complexity: O(log n)

* values:
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
* found in the binary tree. If no node is found, it returns `undefined`.
*/
getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
/**
* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
* Space Complexity: O(k + log n)
* /

@@ -189,3 +171,3 @@

* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Space Complexity: O(k + log n)
*

@@ -197,5 +179,5 @@ * The function `getNodes` returns an array of nodes that match a given identifier, using either a

* callback function `C`.
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
* argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
* function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
* function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
* @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the

@@ -205,3 +187,3 @@ * first node that matches the identifier. If set to true, the function will return an array

* searching for all nodes that match the identifier and return an array containing
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
* for the traversal. It can be either a key value or a node object. If it is undefined, the

@@ -211,5 +193,5 @@ * traversal will start from the root of the tree.

* performed on the binary tree. It can have two possible values:
* @returns The method returns an array of nodes (`N[]`).
* @returns The method returns an array of nodes (`NODE[]`).
*/
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
/**

@@ -238,3 +220,3 @@ * Time complexity: O(n)

*/
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
/**

@@ -261,3 +243,3 @@ * Time complexity: O(n)

*/
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
/**

@@ -274,3 +256,3 @@ * Time complexity: O(n)

* @param {C} callback - The `callback` parameter is a generic type `C` that extends
* `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
* during the level listing process.

@@ -286,16 +268,15 @@ * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the

*/
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[][];
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).

@@ -306,7 +287,6 @@ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,

*/
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, N>): K | undefined;
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): K | undefined;
/**
* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
*/

@@ -321,3 +301,3 @@ /**

* that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
* parameter of type `N` (the node type) and returns a value of any type.
* parameter of type `NODE` (the node type) and returns a value of any type.
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to

@@ -327,3 +307,3 @@ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type

* `lesserOrGreater` are
* @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
* @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
* binary tree that you want to traverse from. It can be specified either by its key, by the node

@@ -336,3 +316,3 @@ * object itself, or it can be left undefined to start the traversal from the root of the tree.

*/
lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
/**

@@ -364,4 +344,4 @@ * Time Complexity: O(log n)

/**
* Time Complexity: O(n) - Building a balanced tree from a sorted array.
* Space Complexity: O(n) - Additional space is required for the sorted array.
* Time Complexity: O(n)
* Space Complexity: O(log n)
*/

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

isAVLBalanced(iterationType?: IterationType): boolean;
protected _setRoot(v: N | undefined): void;
protected _setRoot(v: NODE | undefined): void;
/**

@@ -381,0 +361,0 @@ * The function compares two values using a comparator function and returns whether the first value

@@ -14,12 +14,5 @@ "use strict";

}
/**
* Get the left child node.
*/
get left() {
return this._left;
}
/**
* Set the left child node.
* @param {N | undefined} v - The left child node.
*/
set left(v) {

@@ -31,12 +24,5 @@ if (v) {

}
/**
* Get the right child node.
*/
get right() {
return this._right;
}
/**
* Set the right child node.
* @param {N | undefined} v - The right child node.
*/
set right(v) {

@@ -108,10 +94,10 @@ if (v) {

/**
* The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
* otherwise it returns undefined.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
* @returns a node of type N or undefined.
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
* @returns a node of type NODE or undefined.
*/
exemplarToNode(keyOrNodeOrEntry, value) {
keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
let node;

@@ -144,3 +130,2 @@ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {

* Space Complexity: O(log n)
* Average case for a balanced tree. Space for the recursive call stack in the worst case.
*/

@@ -153,7 +138,7 @@ /**

* otherwise it returns the key itself.
* @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
* `undefined`.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
* @returns either a node object (N) or undefined.
* @returns either a node object (NODE) or undefined.
*/

@@ -177,3 +162,3 @@ ensureNode(keyOrNodeOrEntry, iterationType = types_1.IterationType.ITERATIVE) {

* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.

@@ -187,3 +172,2 @@ */

* Space Complexity: O(1)
* - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
*/

@@ -203,3 +187,3 @@ /**

add(keyOrNodeOrEntry, value) {
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
if (newNode === undefined)

@@ -228,3 +212,2 @@ return false;

current.left = newNode;
newNode.parent = current;
this._size++;

@@ -238,3 +221,2 @@ return true;

current.right = newNode;
newNode.parent = current;
this._size++;

@@ -250,8 +232,7 @@ return true;

* Time Complexity: O(k log n)
* Space Complexity: O(k)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
* Space Complexity: O(k + log n)
*/
/**
* Time Complexity: O(k log n)
* Space Complexity: O(k)
* Space Complexity: O(k + log n)
*

@@ -272,3 +253,3 @@ * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally

* `this.iterationType`, which suggests that it is a property of the current object.
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
* @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
*/

@@ -364,3 +345,3 @@ addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {

* values:
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
* found in the binary tree. If no node is found, it returns `undefined`.

@@ -401,4 +382,3 @@ */

* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
* Space Complexity: O(k + log n)
* /

@@ -408,3 +388,3 @@

* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Space Complexity: O(k + log n)
*

@@ -416,5 +396,5 @@ * The function `getNodes` returns an array of nodes that match a given identifier, using either a

* callback function `C`.
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
* argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
* function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
* function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
* @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the

@@ -424,3 +404,3 @@ * first node that matches the identifier. If set to true, the function will return an array

* searching for all nodes that match the identifier and return an array containing
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
* for the traversal. It can be either a key value or a node object. If it is undefined, the

@@ -430,3 +410,3 @@ * traversal will start from the root of the tree.

* performed on the binary tree. It can have two possible values:
* @returns The method returns an array of nodes (`N[]`).
* @returns The method returns an array of nodes (`NODE[]`).
*/

@@ -489,21 +469,2 @@ getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {

}
// /**
// * The function overrides the subTreeTraverse method and returns the result of calling the super
// * method with the provided arguments.
// * @param {C} callback - The `callback` parameter is a function that will be called for each node in
// * the subtree traversal. It should accept a single parameter of type `N`, which represents a node in
// * the tree. The return type of the callback function can be any type.
// * @param beginRoot - The `beginRoot` parameter is the starting point for traversing the subtree. It
// * can be either a key, a node, or an entry.
// * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
// * be performed during the traversal of the subtree. It can have one of the following values:
// * @returns The method is returning an array of the return type of the callback function.
// */
// override subTreeTraverse<C extends BTNCallback<N>>(
// callback: C = this._defaultOneParamCallback as C,
// beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
// iterationType = this.iterationType
// ): ReturnType<C>[] {
// return super.subTreeTraverse(callback, beginRoot, iterationType, false);
// }
/**

@@ -570,3 +531,3 @@ * Time complexity: O(n)

* @param {C} callback - The `callback` parameter is a generic type `C` that extends
* `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
* during the level listing process.

@@ -586,14 +547,13 @@ * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the

/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).

@@ -625,3 +585,2 @@ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,

* Space Complexity: O(log n)
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
*/

@@ -636,3 +595,3 @@ /**

* that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
* parameter of type `N` (the node type) and returns a value of any type.
* parameter of type `NODE` (the node type) and returns a value of any type.
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to

@@ -642,3 +601,3 @@ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type

* `lesserOrGreater` are
* @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
* @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
* binary tree that you want to traverse from. It can be specified either by its key, by the node

@@ -752,4 +711,4 @@ * object itself, or it can be left undefined to start the traversal from the root of the tree.

/**
* Time Complexity: O(n) - Building a balanced tree from a sorted array.
* Space Complexity: O(n) - Additional space is required for the sorted array.
* Time Complexity: O(n)
* Space Complexity: O(log n)
*/

@@ -756,0 +715,0 @@ /**

@@ -8,6 +8,6 @@ /**

*/
import { BinaryTreeDeleteResult, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
import { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
import { BST, BSTNode } from './bst';
import { IBinaryTree } from '../../interfaces';
export declare class RedBlackTreeNode<K = any, V = any, N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
color: RBTNColor;

@@ -23,8 +23,8 @@ constructor(key: K, value?: V, color?: RBTNColor);

*/
export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, N, TREE> = RedBlackTree<K, V, N, RedBlackTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
Sentinel: N;
export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
Sentinel: NODE;
/**
* This is the constructor function for a Red-Black Tree data structure in TypeScript, which
* initializes the tree with optional nodes and options.
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
* objects. It represents the initial nodes that will be added to the RBTree during its

@@ -37,5 +37,5 @@ * construction. If this parameter is provided, the `addMany` method is called to add all the

*/
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: RBTreeOptions<K>);
protected _root: N;
get root(): N;
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K>);
protected _root: NODE;
get root(): NODE;
protected _size: number;

@@ -55,3 +55,3 @@ get size(): number;

*/
createNode(key: K, value?: V, color?: RBTNColor): N;
createNode(key: K, value?: V, color?: RBTNColor): NODE;
/**

@@ -66,26 +66,22 @@ * The function creates a Red-Black Tree with the specified options and returns it.

/**
* The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
* is provided, it will be used when creating the new node. If no value is provided, the new node
* @returns a node of type N or undefined.
* @returns a node of type NODE or undefined.
*/
exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined;
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
/**
* The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode
* class.
*/
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
isRealNode(node: NODE | undefined): node is NODE;
/**
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
* Space Complexity: O(1)
*/
isRealNode(node: N | undefined): node is N;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* on average (where n is the number of nodes in the tree)
* On average (where n is the number of nodes in the tree)
*/

@@ -102,9 +98,8 @@ /**

* being added to the binary search tree.
* @returns The method `add` returns either the newly added node (`N`) or `undefined`.
* @returns The method `add` returns either the newly added node (`NODE`) or `undefined`.
*/
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* on average (where n is the number of nodes in the tree)
*/

@@ -121,11 +116,8 @@ /**

* you don't want to
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` and
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` and
* returns a value of type `ReturnType<C>`. It is used to determine if a node should be deleted based
* on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
* @returns an array of `BinaryTreeDeleteResult<N>`.
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
*/
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
getNode<C extends BTNCallback<N, N>>(identifier: N | undefined, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
/**

@@ -139,8 +131,20 @@ * Time Complexity: O(log n)

*
* The function returns the predecessor of a given node in a red-black tree.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `RedBlackTreeNode`, which represents a node in a
* Red-Black Tree.
* @returns the predecessor of the given RedBlackTreeNode 'x'.
* The function `getNode` retrieves a single node from a binary tree based on a given identifier and
* callback function.
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value used to
* identify the node you want to retrieve. It can be of any type that is the return type of the `C`
* callback function. If the `identifier` is `undefined`, it means you want to retrieve the first
* node that matches the other criteria
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the binary tree. It is used to determine if a node matches the given identifier. The `callback`
* function should take a single parameter of type `NODE` (the type of the nodes in the binary tree) and
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is the starting point for
* searching for a node in a binary tree. It can be either a key value or a node object. If it is not
* provided, the search will start from the root of the binary tree.
* @param iterationType - The `iterationType` parameter is a variable that determines the type of
* iteration to be performed when searching for nodes in the binary tree. It is used in the
* `getNodes` method, which is called within the `getNode` method.
* @returns a value of type `NODE`, `null`, or `undefined`.
*/
getPredecessor(x: N): N;
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: import("../../types").IterationType): NODE | null | undefined;
/**

@@ -151,4 +155,18 @@ * Time Complexity: O(1)

clear(): void;
protected _setRoot(v: N): void;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function returns the predecessor of a given node in a red-black tree.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `RedBlackTreeNode`, which represents a node in a
* Red-Black Tree.
* @returns the predecessor of the given RedBlackTreeNode 'x'.
*/
getPredecessor(x: NODE): NODE;
protected _setRoot(v: NODE): void;
/**
* Time Complexity: O(1)

@@ -162,5 +180,5 @@ * Space Complexity: O(1)

* The function performs a left rotation on a binary tree node.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `N`, which likely represents a node in a binary tree.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `NODE`, which likely represents a node in a binary tree.
*/
protected _leftRotate(x: N): void;
protected _leftRotate(x: NODE): void;
/**

@@ -178,3 +196,3 @@ * Time Complexity: O(1)

*/
protected _rightRotate(x: N): void;
protected _rightRotate(x: NODE): void;
/**

@@ -188,6 +206,19 @@ * Time Complexity: O(log n)

*
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
* @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
* red-black tree.
*/
protected _fixInsert(k: NODE): void;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function `_fixDelete` is used to fix the red-black tree after a node deletion.
* @param {RedBlackTreeNode} x - The parameter `x` represents a node in a Red-Black Tree (RBT).
*/
protected _fixDelete(x: N): void;
protected _fixDelete(x: NODE): void;
/**

@@ -205,21 +236,8 @@ * Time Complexity: O(1)

*/
protected _rbTransplant(u: N, v: N): void;
protected _rbTransplant(u: NODE, v: NODE): void;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
* @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
* red-black tree.
*/
protected _fixInsert(k: N): void;
/**
* The function replaces an old node with a new node while preserving the color of the old node.
* @param {N} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
* data structure. It is of type `N`, which is the type of the nodes in the data structure.
* @param {N} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
* data structure. It is of type `NODE`, which is the type of the nodes in the data structure.
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* data structure.

@@ -229,3 +247,3 @@ * @returns The method is returning the result of calling the `_replaceNode` method from the

*/
protected _replaceNode(oldNode: N, newNode: N): N;
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
}

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

* initializes the tree with optional nodes and options.
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
* objects. It represents the initial nodes that will be added to the RBTree during its

@@ -80,10 +80,10 @@ * construction. If this parameter is provided, the `addMany` method is called to add all the

/**
* The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
* is provided, it will be used when creating the new node. If no value is provided, the new node
* @returns a node of type N or undefined.
* @returns a node of type NODE or undefined.
*/
exemplarToNode(keyOrNodeOrEntry, value) {
keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
let node;

@@ -115,3 +115,3 @@ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {

* The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode

@@ -123,6 +123,2 @@ * class.

}
/**
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
* Space Complexity: O(1)
*/
isRealNode(node) {

@@ -136,3 +132,3 @@ if (node === this.Sentinel || node === undefined)

* Space Complexity: O(1)
* on average (where n is the number of nodes in the tree)
* On average (where n is the number of nodes in the tree)
*/

@@ -149,6 +145,6 @@ /**

* being added to the binary search tree.
* @returns The method `add` returns either the newly added node (`N`) or `undefined`.
* @returns The method `add` returns either the newly added node (`NODE`) or `undefined`.
*/
add(keyOrNodeOrEntry, value) {
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
if (newNode === undefined)

@@ -203,3 +199,2 @@ return false;

* Space Complexity: O(1)
* on average (where n is the number of nodes in the tree)
*/

@@ -216,6 +211,6 @@ /**

* you don't want to
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` and
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` and
* returns a value of type `ReturnType<C>`. It is used to determine if a node should be deleted based
* on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
* @returns an array of `BinaryTreeDeleteResult<N>`.
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
*/

@@ -296,4 +291,4 @@ delete(identifier, callback = this._defaultOneParamCallback) {

* the binary tree. It is used to determine if a node matches the given identifier. The `callback`
* function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is the starting point for
* function should take a single parameter of type `NODE` (the type of the nodes in the binary tree) and
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is the starting point for
* searching for a node in a binary tree. It can be either a key value or a node object. If it is not

@@ -304,3 +299,3 @@ * provided, the search will start from the root of the binary tree.

* `getNodes` method, which is called within the `getNode` method.
* @returns a value of type `N`, `null`, or `undefined`.
* @returns a value of type `NODE`, `null`, or `undefined`.
*/

@@ -315,2 +310,10 @@ getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {

/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
clear() {
this._root = this.Sentinel;
this._size = 0;
}
/**
* Time Complexity: O(log n)

@@ -339,10 +342,2 @@ * Space Complexity: O(1)

}
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
clear() {
this._root = this.Sentinel;
this._size = 0;
}
_setRoot(v) {

@@ -363,3 +358,3 @@ if (v) {

* The function performs a left rotation on a binary tree node.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `N`, which likely represents a node in a binary tree.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `NODE`, which likely represents a node in a binary tree.
*/

@@ -430,2 +425,59 @@ _leftRotate(x) {

*
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
* @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
* red-black tree.
*/
_fixInsert(k) {
let u;
while (k.parent && k.parent.color === 1) {
if (k.parent.parent && k.parent === k.parent.parent.right) {
u = k.parent.parent.left;
if (u && u.color === 1) {
u.color = types_1.RBTNColor.BLACK;
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
k = k.parent.parent;
}
else {
if (k === k.parent.left) {
k = k.parent;
this._rightRotate(k);
}
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
this._leftRotate(k.parent.parent);
}
}
else {
u = k.parent.parent.right;
if (u && u.color === 1) {
u.color = types_1.RBTNColor.BLACK;
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
k = k.parent.parent;
}
else {
if (k === k.parent.right) {
k = k.parent;
this._leftRotate(k);
}
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
this._rightRotate(k.parent.parent);
}
}
if (k === this.root) {
break;
}
}
this.root.color = types_1.RBTNColor.BLACK;
}
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function `_fixDelete` is used to fix the red-black tree after a node deletion.

@@ -523,63 +575,6 @@ * @param {RedBlackTreeNode} x - The parameter `x` represents a node in a Red-Black Tree (RBT).

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
* @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
* red-black tree.
*/
_fixInsert(k) {
let u;
while (k.parent && k.parent.color === 1) {
if (k.parent.parent && k.parent === k.parent.parent.right) {
u = k.parent.parent.left;
if (u && u.color === 1) {
u.color = types_1.RBTNColor.BLACK;
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
k = k.parent.parent;
}
else {
if (k === k.parent.left) {
k = k.parent;
this._rightRotate(k);
}
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
this._leftRotate(k.parent.parent);
}
}
else {
u = k.parent.parent.right;
if (u && u.color === 1) {
u.color = types_1.RBTNColor.BLACK;
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
k = k.parent.parent;
}
else {
if (k === k.parent.right) {
k = k.parent;
this._leftRotate(k);
}
k.parent.color = types_1.RBTNColor.BLACK;
k.parent.parent.color = types_1.RBTNColor.RED;
this._rightRotate(k.parent.parent);
}
}
if (k === this.root) {
break;
}
}
this.root.color = types_1.RBTNColor.BLACK;
}
/**
* The function replaces an old node with a new node while preserving the color of the old node.
* @param {N} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
* data structure. It is of type `N`, which is the type of the nodes in the data structure.
* @param {N} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
* data structure. It is of type `NODE`, which is the type of the nodes in the data structure.
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* data structure.

@@ -586,0 +581,0 @@ * @returns The method is returning the result of calling the `_replaceNode` method from the

@@ -12,3 +12,3 @@ /**

import { AVLTree, AVLTreeNode } from './avl-tree';
export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNodeNested<K, V>> extends AVLTreeNode<K, V, N> {
export declare class TreeMultimapNode<K = any, V = any, NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
count: number;

@@ -30,4 +30,4 @@ /**

*/
export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>> extends AVLTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: TreeMultimapOptions<K>);
export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, NODE, TREE> = TreeMultimap<K, V, NODE, TreeMultimapNested<K, V, NODE>>> extends AVLTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultimapOptions<K>);
private _count;

@@ -39,3 +39,3 @@ get count(): number;

* distinguish one node from another in the tree.
* @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
* @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of

@@ -45,7 +45,7 @@ * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.

*/
createNode(key: K, value?: V, count?: number): N;
createNode(key: K, value?: V, count?: number): NODE;
createTree(options?: TreeMultimapOptions<K>): TREE;
/**
* The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
* can be one of the following:

@@ -57,16 +57,15 @@ * @param {V} [value] - The `value` parameter is an optional argument that represents the value

* times the value should be added to the node. If not provided, it defaults to 1.
* @returns a node of type `N` or `undefined`.
* @returns a node of type `NODE` or `undefined`.
*/
exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): N | undefined;
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
/**
* The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
* class.
*/
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
*/

@@ -89,45 +88,11 @@ /**

*/
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
/**
* Time Complexity: O(k log n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(k log n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function overrides the addMany method to add multiple keys, nodes, or entries to a data
* structure.
* @param keysOrNodesOrEntries - The parameter `keysOrNodesOrEntries` is an iterable that can contain
* either keys, nodes, or entries.
* @returns The method is returning an array of type `N | undefined`.
*/
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>): boolean[];
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
* tree using either a recursive or iterative approach.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when building the balanced binary search tree. It can have two possible
* values:
* @returns a boolean value.
*/
perfectlyBalance(iterationType?: IterationType): boolean;
/**
* Time Complexity: O(k log n)
* Space Complexity: O(1)
* logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(k log n)
* Space Complexity: O(1)
*
* The `delete` function in TypeScript is used to remove a node from a binary tree, taking into

@@ -146,5 +111,5 @@ * account the count of the node and balancing the tree if necessary.

* decremented by 1 and
* @returns an array of `BinaryTreeDeleteResult<N>`.
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
*/
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<N>[];
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
/**

@@ -162,2 +127,18 @@ * Time Complexity: O(1)

/**
* Time Complexity: O(n log n)
* Space Complexity: O(log n)
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(log n)
*
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
* tree using either a recursive or iterative approach.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when building the balanced binary search tree. It can have two possible
* values:
* @returns a boolean value.
*/
perfectlyBalance(iterationType?: IterationType): boolean;
/**
* Time complexity: O(n)

@@ -176,5 +157,5 @@ * Space complexity: O(n)

* The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
* which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
* which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
* node where the values from the source node will be swapped to.

@@ -184,4 +165,4 @@ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`

*/
protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
protected _replaceNode(oldNode: N, newNode: N): N;
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
}

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

* distinguish one node from another in the tree.
* @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
* @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of

@@ -56,4 +56,4 @@ * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.

/**
* The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
* can be one of the following:

@@ -65,5 +65,5 @@ * @param {V} [value] - The `value` parameter is an optional argument that represents the value

* times the value should be added to the node. If not provided, it defaults to 1.
* @returns a node of type `N` or `undefined`.
* @returns a node of type `NODE` or `undefined`.
*/
exemplarToNode(keyOrNodeOrEntry, value, count = 1) {
keyValueOrEntryToNode(keyOrNodeOrEntry, value, count = 1) {
let node;

@@ -95,3 +95,3 @@ if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {

* The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode

@@ -106,3 +106,2 @@ * class.

* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
*/

@@ -126,3 +125,3 @@ /**

add(keyOrNodeOrEntry, value, count = 1) {
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
if (newNode === undefined)

@@ -138,80 +137,9 @@ return false;

/**
* Time Complexity: O(k log n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(k log n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function overrides the addMany method to add multiple keys, nodes, or entries to a data
* structure.
* @param keysOrNodesOrEntries - The parameter `keysOrNodesOrEntries` is an iterable that can contain
* either keys, nodes, or entries.
* @returns The method is returning an array of type `N | undefined`.
*/
addMany(keysOrNodesOrEntries) {
return super.addMany(keysOrNodesOrEntries);
}
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
* tree using either a recursive or iterative approach.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when building the balanced binary search tree. It can have two possible
* values:
* @returns a boolean value.
*/
perfectlyBalance(iterationType = this.iterationType) {
const sorted = this.dfs(node => node, 'in'), n = sorted.length;
if (sorted.length < 1)
return false;
this.clear();
if (iterationType === types_1.IterationType.RECURSIVE) {
const buildBalanceBST = (l, r) => {
if (l > r)
return;
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
buildBalanceBST(l, m - 1);
buildBalanceBST(m + 1, r);
};
buildBalanceBST(0, n - 1);
return true;
}
else {
const stack = [[0, n - 1]];
while (stack.length > 0) {
const popped = stack.pop();
if (popped) {
const [l, r] = popped;
if (l <= r) {
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
stack.push([m + 1, r]);
stack.push([l, m - 1]);
}
}
}
return true;
}
}
/**
* Time Complexity: O(k log n)
* Space Complexity: O(1)
* logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(k log n)
* Space Complexity: O(1)
*
* The `delete` function in TypeScript is used to remove a node from a binary tree, taking into

@@ -230,3 +158,3 @@ * account the count of the node and balancing the tree if necessary.

* decremented by 1 and
* @returns an array of `BinaryTreeDeleteResult<N>`.
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
*/

@@ -306,2 +234,53 @@ delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {

/**
* Time Complexity: O(n log n)
* Space Complexity: O(log n)
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(log n)
*
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
* tree using either a recursive or iterative approach.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when building the balanced binary search tree. It can have two possible
* values:
* @returns a boolean value.
*/
perfectlyBalance(iterationType = this.iterationType) {
const sorted = this.dfs(node => node, 'in'), n = sorted.length;
if (sorted.length < 1)
return false;
this.clear();
if (iterationType === types_1.IterationType.RECURSIVE) {
const buildBalanceBST = (l, r) => {
if (l > r)
return;
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
buildBalanceBST(l, m - 1);
buildBalanceBST(m + 1, r);
};
buildBalanceBST(0, n - 1);
return true;
}
else {
const stack = [[0, n - 1]];
while (stack.length > 0) {
const popped = stack.pop();
if (popped) {
const [l, r] = popped;
if (l <= r) {
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
stack.push([m + 1, r]);
stack.push([l, m - 1]);
}
}
}
return true;
}
}
/**
* Time complexity: O(n)

@@ -324,5 +303,5 @@ * Space complexity: O(n)

* The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
* which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
* which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
* node where the values from the source node will be swapped to.

@@ -329,0 +308,0 @@ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`

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

get vertexMap(): Map<VertexKey, VO>;
set vertexMap(v: Map<VertexKey, VO>);
/**

@@ -45,0 +46,0 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

@@ -50,2 +50,5 @@ "use strict";

}
set vertexMap(v) {
this._vertexMap = v;
}
/**

@@ -52,0 +55,0 @@ * Time Complexity: O(1) - Constant time for Map lookup.

@@ -44,4 +44,6 @@ /**

get outEdgeMap(): Map<VO, EO[]>;
set outEdgeMap(v: Map<VO, EO[]>);
protected _inEdgeMap: Map<VO, EO[]>;
get inEdgeMap(): Map<VO, EO[]>;
set inEdgeMap(v: Map<VO, EO[]>);
/**

@@ -332,2 +334,14 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

/**
* The isEmpty function checks if the graph is empty.
*
* @return A boolean value
*/
isEmpty(): boolean;
/**
* The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
*
* @return A new instance of the directedgraph class
*/
clone(): DirectedGraph<V, E, VO, EO>;
/**
* Time Complexity: O(1)

@@ -334,0 +348,0 @@ * Space Complexity: O(1)

@@ -50,5 +50,11 @@ "use strict";

}
set outEdgeMap(v) {
this._outEdgeMap = v;
}
get inEdgeMap() {
return this._inEdgeMap;
}
set inEdgeMap(v) {
this._inEdgeMap = v;
}
/**

@@ -532,2 +538,22 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

/**
* The isEmpty function checks if the graph is empty.
*
* @return A boolean value
*/
isEmpty() {
return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
}
/**
* The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
*
* @return A new instance of the directedgraph class
*/
clone() {
const cloned = new DirectedGraph();
cloned.vertexMap = new Map(this.vertexMap);
cloned.inEdgeMap = new Map(this.inEdgeMap);
cloned.outEdgeMap = new Map(this.outEdgeMap);
return cloned;
}
/**
* Time Complexity: O(1)

@@ -534,0 +560,0 @@ * Space Complexity: O(1)

@@ -73,2 +73,10 @@ import type { MapGraphCoordinate, VertexKey } from '../../types';

createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
/**
* The override function is used to override the default behavior of a function.
* In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
* The clone() function returns a new graph that is an exact copy of the original graph.
*
* @return A mapgraph&lt;v, e, vo, eo&gt;
*/
clone(): MapGraph<V, E, VO, EO>;
}

@@ -92,3 +92,17 @@ "use strict";

}
/**
* The override function is used to override the default behavior of a function.
* In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
* The clone() function returns a new graph that is an exact copy of the original graph.
*
* @return A mapgraph&lt;v, e, vo, eo&gt;
*/
clone() {
const cloned = new MapGraph(this.originCoord, this.bottomRight);
cloned.vertexMap = new Map(this.vertexMap);
cloned.inEdgeMap = new Map(this.inEdgeMap);
cloned.outEdgeMap = new Map(this.outEdgeMap);
return cloned;
}
}
exports.MapGraph = MapGraph;

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

get edgeMap(): Map<VO, EO[]>;
set edgeMap(v: Map<VO, EO[]>);
/**

@@ -198,2 +199,17 @@ * The function creates a new vertex with an optional value and returns it.

/**
* The isEmpty function checks if the graph is empty.
* @return True if the graph is empty and false otherwise
*/
isEmpty(): boolean;
/**
* The clone function creates a new UndirectedGraph object and copies the
* vertexMap and edgeMap from this graph to the new one. This is done by
* assigning each of these properties to their respective counterparts in the
* cloned graph. The clone function returns a reference to this newly created,
* cloned UndirectedGraph object.
*
* @return A new instance of the undirectedgraph class
*/
clone(): UndirectedGraph<V, E, VO, EO>;
/**
* Time Complexity: O(1)

@@ -200,0 +216,0 @@ * Space Complexity: O(1)

@@ -47,2 +47,5 @@ "use strict";

}
set edgeMap(v) {
this._edgeMap = v;
}
/**

@@ -330,2 +333,24 @@ * The function creates a new vertex with an optional value and returns it.

/**
* The isEmpty function checks if the graph is empty.
* @return True if the graph is empty and false otherwise
*/
isEmpty() {
return this.vertexMap.size === 0 && this.edgeMap.size === 0;
}
/**
* The clone function creates a new UndirectedGraph object and copies the
* vertexMap and edgeMap from this graph to the new one. This is done by
* assigning each of these properties to their respective counterparts in the
* cloned graph. The clone function returns a reference to this newly created,
* cloned UndirectedGraph object.
*
* @return A new instance of the undirectedgraph class
*/
clone() {
const cloned = new UndirectedGraph();
cloned.vertexMap = new Map(this.vertexMap);
cloned.edgeMap = new Map(this.edgeMap);
return cloned;
}
/**
* Time Complexity: O(1)

@@ -332,0 +357,0 @@ * Space Complexity: O(1)

@@ -28,9 +28,38 @@ /**

*/
constructor(rawCollection?: Iterable<R>, options?: HashMapOptions<K, V, R>);
constructor(rawCollection?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
protected _toEntryFn: (rawElement: R) => [K, V];
/**
* The function returns the value of the _toEntryFn property.
* @returns The function being returned is `this._toEntryFn`.
*/
get toEntryFn(): (rawElement: R) => [K, V];
/**
* The hasFn function is a function that takes in an item and returns a boolean
* indicating whether the item is contained within the hash table.
*
* @return The hash function
*/
get hasFn(): (key: K) => string;
protected _size: number;
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number;
/**
* The function checks if a given element is an array with exactly two elements.
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
* data type.
* @returns a boolean value.
*/
isEntry(rawElement: any): rawElement is [K, V];
/**
* The function checks if the size of an object is equal to zero and returns a boolean value.
* @returns A boolean value indicating whether the size of the object is 0 or not.
*/
isEmpty(): boolean;
/**
* The clear() function resets the state of an object by clearing its internal store, object map, and
* size.
*/
clear(): void;

@@ -54,3 +83,3 @@ /**

*/
setMany(rawCollection: Iterable<R>): boolean[];
setMany(rawCollection: Iterable<R | [K, V]>): boolean[];
/**

@@ -81,2 +110,10 @@ * The `get` function retrieves a value from a map based on a given key, either from an object map or

/**
* The clone function creates a new HashMap with the same key-value pairs as
* this one. The clone function is useful for creating a copy of an existing
* HashMap, and then modifying that copy without affecting the original.
*
* @return A new hashmap with the same values as this one
*/
clone(): HashMap<K, V, R>;
/**
* Time Complexity: O(n)

@@ -121,2 +158,10 @@ * Space Complexity: O(n)

filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
/**
* The put function sets a value in a data structure using a specified key.
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
* to the function.
* @param {V} value - The value parameter represents the value that you want to associate with the
* specified key in the data structure.
* @returns The method is returning a boolean value.
*/
put(key: K, value: V): boolean;

@@ -137,3 +182,3 @@ /**

*/
export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;

@@ -144,4 +189,23 @@ protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;

protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
constructor(entries?: Iterable<[K, V]>, options?: LinkedHashMapOptions<K>);
/**
* The constructor initializes a LinkedHashMap object with an optional raw collection and options.
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
* used to initialize the HashMapLinked instance with key-value pairs. Each element in the
* `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
* then added to the HashMap
* @param [options] - The `options` parameter is an optional object that can contain the following
* properties:
*/
constructor(rawCollection?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
protected _toEntryFn: (rawElement: R) => [K, V];
/**
* The function returns the value of the _toEntryFn property.
* @returns The function being returned is `this._toEntryFn`.
*/
get toEntryFn(): (rawElement: R) => [K, V];
protected _size: number;
/**
* The function returns the size of an object.
* @returns The size of the object.
*/
get size(): number;

@@ -188,4 +252,18 @@ /**

set(key: K, value?: V): boolean;
/**
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
* using a provided function, and sets each key-value pair in the current object, returning an array
* of booleans indicating the success of each set operation.
* @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
* R.
* @returns The `setMany` function returns an array of booleans.
*/
setMany(rawCollection: Iterable<R>): boolean[];
/**
* The function checks if a given key exists in a map, using different logic depending on whether the
* key is a weak key or not.
* @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
* @returns The method `has` is returning a boolean value.
*/
has(key: K): boolean;
setMany(entries: Iterable<[K, V]>): boolean[];
/**

@@ -209,10 +287,10 @@ * Time Complexity: O(1)

*
* The function `getAt` retrieves the key-value pair at a specified index in a linked list.
* The function `at` retrieves the key-value pair at a specified index in a linked list.
* @param {number} index - The index parameter is a number that represents the position of the
* element we want to retrieve from the data structure.
* @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
* @returns The method `at(index: number)` is returning an array containing the key-value pair at
* the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
* where `K` is the key and `V` is the value.
*/
getAt(index: number): V | undefined;
at(index: number): V | undefined;
/**

@@ -230,3 +308,3 @@ * Time Complexity: O(1)

/**
* Time Complexity: O(n), where n is the index.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -250,2 +328,9 @@ *

/**
* The function checks if a given element is an array with exactly two elements.
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
* data type.
* @returns a boolean value.
*/
isEntry(rawElement: any): rawElement is [K, V];
/**
* Time Complexity: O(1)

@@ -257,2 +342,15 @@ * Space Complexity: O(1)

clear(): void;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
* the original.
* @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
* of the original `LinkedHashMap` object.
*/
clone(): LinkedHashMap<K, V>;

@@ -294,15 +392,23 @@ /**

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
put(key: K, value: V): boolean;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The put function sets a value in a data structure using a specified key.
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
* to the function.
* @param {V} value - The value parameter represents the value that you want to associate with the
* specified key in the data structure.
* @returns The method is returning a boolean value.
*/
put(key: K, value: V): boolean;
protected _hashFn: (key: K) => string;
protected _objHashFn: (key: K) => object;
/**
* Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
* Time Complexity: O(n)
* Space Complexity: O(1)
* where n is the number of entries in the LinkedHashMap.
*

@@ -309,0 +415,0 @@ * The above function is an iterator that yields key-value pairs from a linked list.

@@ -48,14 +48,45 @@ "use strict";

}
/**
* The function returns the value of the _toEntryFn property.
* @returns The function being returned is `this._toEntryFn`.
*/
get toEntryFn() {
return this._toEntryFn;
}
/**
* The hasFn function is a function that takes in an item and returns a boolean
* indicating whether the item is contained within the hash table.
*
* @return The hash function
*/
get hasFn() {
return this._hashFn;
}
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size() {
return this._size;
}
/**
* The function checks if a given element is an array with exactly two elements.
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
* data type.
* @returns a boolean value.
*/
isEntry(rawElement) {
return Array.isArray(rawElement) && rawElement.length === 2;
}
/**
* The function checks if the size of an object is equal to zero and returns a boolean value.
* @returns A boolean value indicating whether the size of the object is 0 or not.
*/
isEmpty() {
return this.size === 0;
}
/**
* The clear() function resets the state of an object by clearing its internal store, object map, and
* size.
*/
clear() {

@@ -101,3 +132,12 @@ this._store = {};

for (const rawEle of rawCollection) {
const [key, value] = this.toEntryFn(rawEle);
let key, value;
if (this.isEntry(rawEle)) {
key = rawEle[0];
value = rawEle[1];
}
else {
const item = this.toEntryFn(rawEle);
key = item[0];
value = item[1];
}
results.push(this.set(key, value));

@@ -165,2 +205,12 @@ }

/**
* The clone function creates a new HashMap with the same key-value pairs as
* this one. The clone function is useful for creating a copy of an existing
* HashMap, and then modifying that copy without affecting the original.
*
* @return A new hashmap with the same values as this one
*/
clone() {
return new HashMap(this, { hashFn: this._hashFn, toEntryFn: this.toEntryFn });
}
/**
* Time Complexity: O(n)

@@ -221,2 +271,10 @@ * Space Complexity: O(n)

}
/**
* The put function sets a value in a data structure using a specified key.
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
* to the function.
* @param {V} value - The value parameter represents the value that you want to associate with the
* specified key in the data structure.
* @returns The method is returning a boolean value.
*/
put(key, value) {

@@ -266,11 +324,25 @@ return this.set(key, value);

class LinkedHashMap extends base_1.IterableEntryBase {
constructor(entries, options) {
/**
* The constructor initializes a LinkedHashMap object with an optional raw collection and options.
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
* used to initialize the HashMapLinked instance with key-value pairs. Each element in the
* `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
* then added to the HashMap
* @param [options] - The `options` parameter is an optional object that can contain the following
* properties:
*/
constructor(rawCollection = [], options) {
super();
this._noObjMap = {};
this._objMap = new WeakMap();
this._toEntryFn = (rawElement) => {
if (this.isEntry(rawElement)) {
// TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
return rawElement;
}
else {
throw new Error("If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
}
};
this._size = 0;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
this._hashFn = (key) => String(key);

@@ -281,3 +353,3 @@ this._objHashFn = (key) => key;

if (options) {
const { hashFn, objHashFn } = options;
const { hashFn, objHashFn, toEntryFn } = options;
if (hashFn)

@@ -287,9 +359,24 @@ this._hashFn = hashFn;

this._objHashFn = objHashFn;
if (toEntryFn) {
this._toEntryFn = toEntryFn;
}
}
if (entries) {
for (const el of entries) {
this.set(el[0], el[1]);
if (rawCollection) {
for (const el of rawCollection) {
const [key, value] = this.toEntryFn(el);
this.set(key, value);
}
}
}
/**
* The function returns the value of the _toEntryFn property.
* @returns The function being returned is `this._toEntryFn`.
*/
get toEntryFn() {
return this._toEntryFn;
}
/**
* The function returns the size of an object.
* @returns The size of the object.
*/
get size() {

@@ -400,2 +487,24 @@ return this._size;

}
/**
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
* using a provided function, and sets each key-value pair in the current object, returning an array
* of booleans indicating the success of each set operation.
* @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
* R.
* @returns The `setMany` function returns an array of booleans.
*/
setMany(rawCollection) {
const results = [];
for (const rawEle of rawCollection) {
const [key, value] = this.toEntryFn(rawEle);
results.push(this.set(key, value));
}
return results;
}
/**
* The function checks if a given key exists in a map, using different logic depending on whether the
* key is a weak key or not.
* @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
* @returns The method `has` is returning a boolean value.
*/
has(key) {

@@ -411,10 +520,2 @@ if ((0, utils_1.isWeakKey)(key)) {

}
setMany(entries) {
const results = [];
for (const entry of entries) {
const [key, value] = entry;
results.push(this.set(key, value));
}
return results;
}
/**

@@ -449,10 +550,10 @@ * Time Complexity: O(1)

*
* The function `getAt` retrieves the key-value pair at a specified index in a linked list.
* The function `at` retrieves the key-value pair at a specified index in a linked list.
* @param {number} index - The index parameter is a number that represents the position of the
* element we want to retrieve from the data structure.
* @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
* @returns The method `at(index: number)` is returning an array containing the key-value pair at
* the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
* where `K` is the key and `V` is the value.
*/
getAt(index) {
at(index) {
(0, utils_1.rangeCheck)(index, 0, this._size - 1);

@@ -502,3 +603,3 @@ let node = this._head;

/**
* Time Complexity: O(n), where n is the index.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -531,2 +632,11 @@ *

/**
* The function checks if a given element is an array with exactly two elements.
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
* data type.
* @returns a boolean value.
*/
isEntry(rawElement) {
return Array.isArray(rawElement) && rawElement.length === 2;
}
/**
* Time Complexity: O(1)

@@ -542,2 +652,15 @@ * Space Complexity: O(1)

}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
* the original.
* @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
* of the original `LinkedHashMap` object.
*/
clone() {

@@ -605,5 +728,16 @@ const cloned = new LinkedHashMap([], { hashFn: this._hashFn, objHashFn: this._objHashFn });

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The put function sets a value in a data structure using a specified key.
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
* to the function.
* @param {V} value - The value parameter represents the value that you want to associate with the
* specified key in the data structure.
* @returns The method is returning a boolean value.
*/
put(key, value) {

@@ -613,4 +747,5 @@ return this.set(key, value);

/**
* Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
* Time Complexity: O(n)
* Space Complexity: O(1)
* where n is the number of entries in the LinkedHashMap.
*

@@ -617,0 +752,0 @@ * The above function is an iterator that yields key-value pairs from a linked list.

@@ -22,6 +22,24 @@ /**

export declare class Heap<E = any> extends IterableElementBase<E> {
/**
* The constructor initializes a heap data structure with optional elements and options.
* @param elements - The `elements` parameter is an iterable object that contains the initial
* elements to be added to the heap. It is an optional parameter and if not provided, the heap will
* be initialized as empty.
* @param [options] - The `options` parameter is an optional object that can contain additional
* configuration options for the heap. In this case, it is used to specify a custom comparator
* function for comparing elements in the heap. The comparator function is used to determine the
* order of elements in the heap.
*/
constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
protected _comparator: (a: E, b: E) => number;
/**
* The function returns the value of the _comparator property.
* @returns The `_comparator` property is being returned.
*/
get comparator(): (a: E, b: E) => number;
protected _elements: E[];
/**
* The function returns an array of elements.
* @returns The elements array is being returned.
*/
get elements(): E[];

@@ -47,7 +65,8 @@ /**

/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)
* where n is the number of elements in the heap.
*/
/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)

@@ -60,7 +79,8 @@ *

/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)
* where n is the number of elements in the heap.
*/
/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)

@@ -73,2 +93,5 @@ *

/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* Peek at the top element of the heap without removing it.

@@ -234,2 +257,5 @@ * @returns The top element or undefined if the heap is empty.

map<T>(callback: ElementCallback<E, T>, comparator: Comparator<T>, thisArg?: any): Heap<T>;
/**
* The function `_getIterator` returns an iterable iterator for the elements in the class.
*/
protected _getIterator(): IterableIterator<E>;

@@ -266,13 +292,47 @@ /**

marked: boolean;
/**
* The constructor function initializes an object with an element and a degree, and sets the marked
* property to false.
* @param {E} element - The "element" parameter represents the value or data that will be stored in
* the node of a data structure. It can be any type of data, such as a number, string, object, or
* even another data structure.
* @param [degree=0] - The degree parameter represents the degree of the element in a data structure
* called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
* degree is set to 0 when a new node is created.
*/
constructor(element: E, degree?: number);
}
export declare class FibonacciHeap<E> {
/**
* The constructor function initializes a FibonacciHeap object with an optional comparator function.
* @param [comparator] - The `comparator` parameter is an optional argument that represents a
* function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
* will be used to determine the order of elements in the heap. If no comparator function is
* provided, a default comparator function will be used.
*/
constructor(comparator?: Comparator<E>);
protected _root?: FibonacciHeapNode<E>;
/**
* The function returns the root node of a Fibonacci heap.
* @returns The method is returning either a FibonacciHeapNode object or undefined.
*/
get root(): FibonacciHeapNode<E> | undefined;
protected _size: number;
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number;
protected _min?: FibonacciHeapNode<E>;
/**
* The function returns the minimum node in a Fibonacci heap.
* @returns The method is returning the minimum node of the Fibonacci heap, which is of type
* `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
*/
get min(): FibonacciHeapNode<E> | undefined;
protected _comparator: Comparator<E>;
/**
* The function returns the comparator used for comparing elements.
* @returns The `_comparator` property of the object.
*/
get comparator(): Comparator<E>;

@@ -434,7 +494,7 @@ /**

/**
* Time Complexity: O(n log n), where n is the number of elements in the heap.
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n log n), where n is the number of elements in the heap.
* Time Complexity: O(n log n)
* Space Complexity: O(n)

@@ -441,0 +501,0 @@ *

@@ -24,2 +24,12 @@ "use strict";

class Heap extends base_1.IterableElementBase {
/**
* The constructor initializes a heap data structure with optional elements and options.
* @param elements - The `elements` parameter is an iterable object that contains the initial
* elements to be added to the heap. It is an optional parameter and if not provided, the heap will
* be initialized as empty.
* @param [options] - The `options` parameter is an optional object that can contain additional
* configuration options for the heap. In this case, it is used to specify a custom comparator
* function for comparing elements in the heap. The comparator function is used to determine the
* order of elements in the heap.
*/
constructor(elements = [], options) {

@@ -48,5 +58,13 @@ super();

}
/**
* The function returns the value of the _comparator property.
* @returns The `_comparator` property is being returned.
*/
get comparator() {
return this._comparator;
}
/**
* The function returns an array of elements.
* @returns The elements array is being returned.
*/
get elements() {

@@ -79,7 +97,8 @@ return this._elements;

/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)
* where n is the number of elements in the heap.
*/
/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)

@@ -95,7 +114,8 @@ *

/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)
* where n is the number of elements in the heap.
*/
/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)

@@ -118,2 +138,5 @@ *

/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* Peek at the top element of the heap without removing it.

@@ -369,2 +392,5 @@ * @returns The top element or undefined if the heap is empty.

}
/**
* The function `_getIterator` returns an iterable iterator for the elements in the class.
*/
*_getIterator() {

@@ -428,2 +454,12 @@ for (const element of this.elements) {

class FibonacciHeapNode {
/**
* The constructor function initializes an object with an element and a degree, and sets the marked
* property to false.
* @param {E} element - The "element" parameter represents the value or data that will be stored in
* the node of a data structure. It can be any type of data, such as a number, string, object, or
* even another data structure.
* @param [degree=0] - The degree parameter represents the degree of the element in a data structure
* called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
* degree is set to 0 when a new node is created.
*/
constructor(element, degree = 0) {

@@ -437,2 +473,9 @@ this.element = element;

class FibonacciHeap {
/**
* The constructor function initializes a FibonacciHeap object with an optional comparator function.
* @param [comparator] - The `comparator` parameter is an optional argument that represents a
* function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
* will be used to determine the order of elements in the heap. If no comparator function is
* provided, a default comparator function will be used.
*/
constructor(comparator) {

@@ -446,11 +489,28 @@ this._size = 0;

}
/**
* The function returns the root node of a Fibonacci heap.
* @returns The method is returning either a FibonacciHeapNode object or undefined.
*/
get root() {
return this._root;
}
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size() {
return this._size;
}
/**
* The function returns the minimum node in a Fibonacci heap.
* @returns The method is returning the minimum node of the Fibonacci heap, which is of type
* `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
*/
get min() {
return this._min;
}
/**
* The function returns the comparator used for comparing elements.
* @returns The `_comparator` property of the object.
*/
get comparator() {

@@ -738,7 +798,7 @@ return this._comparator;

/**
* Time Complexity: O(n log n), where n is the number of elements in the heap.
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n log n), where n is the number of elements in the heap.
* Time Complexity: O(n log n)
* Space Complexity: O(n)

@@ -745,0 +805,0 @@ *

@@ -29,17 +29,34 @@ /**

/**
* The constructor initializes the linked list with an empty head, tail, and size.
* The constructor initializes a linked list with optional elements.
* @param elements - The `elements` parameter is an optional iterable object that contains the
* initial elements to be added to the data structure. It defaults to an empty array if no elements
* are provided.
*/
constructor(elements?: Iterable<E>);
protected _head: DoublyLinkedListNode<E> | undefined;
/**
* The `head` function returns the first node of a doubly linked list.
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
*/
get head(): DoublyLinkedListNode<E> | undefined;
protected _tail: DoublyLinkedListNode<E> | undefined;
/**
* The `tail` function returns the last node of a doubly linked list.
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
* `undefined`.
*/
get tail(): DoublyLinkedListNode<E> | undefined;
protected _size: number;
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number;
/**
* Time Complexity: O(n), where n is the size of the input array.
* Time Complexity: O(n)
* Space Complexity: O(n)
* where n is the number of elements in the linked list.
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -56,3 +73,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -104,3 +121,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -118,3 +135,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -132,10 +149,10 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
* @param {number} index - The index parameter is a number that represents the position of the element we want to

@@ -146,9 +163,9 @@ * retrieve from the list.

*/
getAt(index: number): E | undefined;
at(index: number): E | undefined;
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -165,7 +182,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -181,7 +198,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -199,7 +216,8 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
* where n is the number of elements in the linked list.
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -218,7 +236,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -236,3 +254,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -248,3 +266,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -260,3 +278,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(1)
* Space Complexity: O(1)

@@ -270,3 +288,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(1)
* Space Complexity: O(1)

@@ -279,24 +297,9 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback: (value: E) => boolean): E | undefined;
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Space Complexity: O(1)
*
* The function returns the index of the first occurrence of a given value in a linked list.

@@ -310,7 +313,7 @@ * @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -327,7 +330,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -343,3 +346,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -352,7 +355,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -365,2 +368,16 @@ *

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
* as the original list.
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
* is a copy of the original list.
*/
clone(): DoublyLinkedList<E>;
/**
* Time Complexity: O(1)

@@ -435,3 +452,3 @@ * Space Complexity: O(1)

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -449,3 +466,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -452,0 +469,0 @@ */

@@ -26,3 +26,6 @@ "use strict";

/**
* The constructor initializes the linked list with an empty head, tail, and size.
* The constructor initializes a linked list with optional elements.
* @param elements - The `elements` parameter is an optional iterable object that contains the
* initial elements to be added to the data structure. It defaults to an empty array if no elements
* are provided.
*/

@@ -40,8 +43,21 @@ constructor(elements = []) {

}
/**
* The `head` function returns the first node of a doubly linked list.
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
*/
get head() {
return this._head;
}
/**
* The `tail` function returns the last node of a doubly linked list.
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
* `undefined`.
*/
get tail() {
return this._tail;
}
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size() {

@@ -51,7 +67,8 @@ return this._size;

/**
* Time Complexity: O(n), where n is the size of the input array.
* Time Complexity: O(n)
* Space Complexity: O(n)
* where n is the number of elements in the linked list.
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -71,3 +88,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -96,7 +113,3 @@ *

static fromArray(data) {
const doublyLinkedList = new DoublyLinkedList();
for (const item of data) {
doublyLinkedList.push(item);
}
return doublyLinkedList;
return new DoublyLinkedList(data);
}

@@ -156,3 +169,3 @@ /**

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -184,3 +197,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -211,10 +224,10 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
* @param {number} index - The index parameter is a number that represents the position of the element we want to

@@ -225,3 +238,3 @@ * retrieve from the list.

*/
getAt(index) {
at(index) {
if (index < 0 || index >= this.size)

@@ -236,7 +249,7 @@ return undefined;

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -261,7 +274,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -286,7 +299,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -324,7 +337,8 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
* where n is the number of elements in the linked list.
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -366,7 +380,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -407,3 +421,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -437,3 +451,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -474,3 +488,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(1)
* Space Complexity: O(1)

@@ -486,3 +500,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(1)
* Space Complexity: O(1)

@@ -499,33 +513,9 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback) {
let current = this.head;
while (current) {
if (callback(current.value)) {
return current.value;
}
current = current.next;
}
return undefined;
}
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Space Complexity: O(1)
*
* The function returns the index of the first occurrence of a given value in a linked list.

@@ -550,7 +540,7 @@ * @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -576,7 +566,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -601,3 +591,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -618,7 +608,7 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -639,2 +629,18 @@ *

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
* as the original list.
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
* is a copy of the original list.
*/
clone() {
return new DoublyLinkedList(this.values());
}
/**
* Time Complexity: O(1)

@@ -731,3 +737,3 @@ * Space Complexity: O(1)

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -747,3 +753,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -750,0 +756,0 @@ */

@@ -22,18 +22,35 @@ /**

/**
* The constructor initializes the linked list with an empty head, tail, and length.
* The constructor initializes a new instance of a class with an optional iterable of elements.
* @param elements - The `elements` parameter is an optional iterable object that contains the
* initial elements to be added to the instance of the class. If no `elements` are provided, an empty
* array will be used as the default value.
*/
constructor(elements?: Iterable<E>);
protected _head: SinglyLinkedListNode<E> | undefined;
/**
* The `head` function returns the first node of a singly linked list.
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
*/
get head(): SinglyLinkedListNode<E> | undefined;
protected _tail: SinglyLinkedListNode<E> | undefined;
/**
* The `tail` function returns the last node of a singly linked list.
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
*/
get tail(): SinglyLinkedListNode<E> | undefined;
protected _size: number;
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number;
/**
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
* Time Complexity: O(n)
* Space Complexity: O(n)
* Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Linear space, as it creates a new node for each element in the array.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -47,8 +64,10 @@ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given

/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
* Constant time, as it involves basic pointer adjustments.
* Constant space, as it only creates a new node.
*/
/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -61,8 +80,8 @@ * The `push` function adds a new node with the given value to the end of a singly linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -75,8 +94,9 @@ * The `push` function adds a new node with the given value to the end of a singly linked list.

/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
* Linear time in the worst case, as it may need to traverse the list to find the last element.
*/
/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -90,8 +110,8 @@ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail

/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -105,8 +125,8 @@ * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -118,8 +138,8 @@ * The `shift()` function removes and returns the value of the first node in a linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -131,8 +151,8 @@ * The `pollFirst()` function removes and returns the value of the first node in a linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -145,8 +165,8 @@ * The unshift function adds a new node with the given value to the beginning of a singly linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -159,23 +179,24 @@ * The addFirst function adds a new node with the given value to the beginning of a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
* Linear time, where n is the index, as it may need to traverse the list to find the desired node.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
* The function `at` returns the value at a specified index in a linked list, or undefined if the index is out of range.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
* @returns The method `at(index: number): E | undefined` returns the value at the specified index in the linked list, or
* `undefined` if the index is out of bounds.
*/
getAt(index: number): E | undefined;
at(index: number): E | undefined;
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -190,8 +211,8 @@ * The function `getNodeAt` returns the node at a given index in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -206,8 +227,8 @@ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -222,8 +243,8 @@ * The delete function removes a node with a specific value from a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -250,8 +271,10 @@ * The `addAt` function inserts a value at a specified index in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
* Time Complexity: O(n)
* Space Complexity: O(n)
* Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Linear space, as it creates an array with the same length as the list.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -263,8 +286,8 @@ * The `toArray` function converts a linked list into an array.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -276,24 +299,9 @@ * The `reverse` function reverses the order of the nodes in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback: (value: E) => boolean): E | undefined;
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
*
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.

@@ -306,8 +314,8 @@ * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -322,8 +330,8 @@ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -339,8 +347,8 @@ * The `addBefore` function inserts a new value before an existing value in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -356,8 +364,8 @@ * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -377,2 +385,16 @@ * The function counts the number of occurrences of a given value in a linked list.

*
* The `clone` function returns a new instance of the `SinglyLinkedList` class with the same values
* as the original list.
* @returns The `clone()` method is returning a new instance of the `SinglyLinkedList` class, which
* is a clone of the original list.
*/
clone(): SinglyLinkedList<E>;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function creates a new SinglyLinkedList by iterating over the elements of the current

@@ -411,3 +433,6 @@ * list and applying a callback function to each element to determine if it should be included in the

map<T>(callback: ElementCallback<E, T>, thisArg?: any): SinglyLinkedList<T>;
/**
* The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
*/
protected _getIterator(): IterableIterator<E>;
}

@@ -19,3 +19,6 @@ "use strict";

/**
* The constructor initializes the linked list with an empty head, tail, and length.
* The constructor initializes a new instance of a class with an optional iterable of elements.
* @param elements - The `elements` parameter is an optional iterable object that contains the
* initial elements to be added to the instance of the class. If no `elements` are provided, an empty
* array will be used as the default value.
*/

@@ -30,8 +33,20 @@ constructor(elements = []) {

}
/**
* The `head` function returns the first node of a singly linked list.
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
*/
get head() {
return this._head;
}
/**
* The `tail` function returns the last node of a singly linked list.
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
*/
get tail() {
return this._tail;
}
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size() {

@@ -41,8 +56,10 @@ return this._size;

/**
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
* Time Complexity: O(n)
* Space Complexity: O(n)
* Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Linear space, as it creates a new node for each element in the array.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -62,8 +79,10 @@ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given

/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
* Constant time, as it involves basic pointer adjustments.
* Constant space, as it only creates a new node.
*/
/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -88,8 +107,8 @@ * The `push` function adds a new node with the given value to the end of a singly linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -104,8 +123,9 @@ * The `push` function adds a new node with the given value to the end of a singly linked list.

/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
* Linear time in the worst case, as it may need to traverse the list to find the last element.
*/
/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -138,8 +158,8 @@ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail

/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -155,8 +175,8 @@ * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -175,8 +195,8 @@ * The `shift()` function removes and returns the value of the first node in a linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -190,8 +210,8 @@ * The `pollFirst()` function removes and returns the value of the first node in a linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -216,8 +236,8 @@ * The unshift function adds a new node with the given value to the beginning of a singly linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -232,16 +252,17 @@ * The addFirst function adds a new node with the given value to the beginning of a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
* Linear time, where n is the index, as it may need to traverse the list to find the desired node.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
* The function `at` returns the value at a specified index in a linked list, or undefined if the index is out of range.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
* @returns The method `at(index: number): E | undefined` returns the value at the specified index in the linked list, or
* `undefined` if the index is out of bounds.
*/
getAt(index) {
at(index) {
if (index < 0 || index >= this.size)

@@ -256,8 +277,8 @@ return undefined;

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -278,8 +299,8 @@ * The function `getNodeAt` returns the node at a given index in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -310,8 +331,8 @@ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -358,8 +379,8 @@ * The delete function removes a node with a specific value from a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -409,8 +430,10 @@ * The `addAt` function inserts a value at a specified index in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
* Time Complexity: O(n)
* Space Complexity: O(n)
* Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Linear space, as it creates an array with the same length as the list.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -430,8 +453,8 @@ * The `toArray` function converts a linked list into an array.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -457,33 +480,9 @@ * The `reverse` function reverses the order of the nodes in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback) {
let current = this.head;
while (current) {
if (callback(current.value)) {
return current.value;
}
current = current.next;
}
return undefined;
}
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
*
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.

@@ -507,8 +506,8 @@ * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -532,8 +531,8 @@ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -575,8 +574,8 @@ * The `addBefore` function inserts a new value before an existing value in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -611,8 +610,8 @@ * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -642,2 +641,18 @@ * The function counts the number of occurrences of a given value in a linked list.

*
* The `clone` function returns a new instance of the `SinglyLinkedList` class with the same values
* as the original list.
* @returns The `clone()` method is returning a new instance of the `SinglyLinkedList` class, which
* is a clone of the original list.
*/
clone() {
return new SinglyLinkedList(this.values());
}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function creates a new SinglyLinkedList by iterating over the elements of the current

@@ -694,2 +709,5 @@ * list and applying a callback function to each element to determine if it should be included in the

}
/**
* The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
*/
*_getIterator() {

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

@@ -16,18 +16,42 @@ /**

export declare class SkipList<K, V> {
/**
* The constructor function initializes a SkipLinkedList object with optional options and elements.
* @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
* is used to initialize the SkipLinkedList with the given key-value pairs. If no elements are
* provided, the SkipLinkedList will be empty.
* @param {SkipLinkedListOptions} [options] - The `options` parameter is an optional object that can
* contain two properties:
*/
constructor(elements?: Iterable<[K, V]>, options?: SkipLinkedListOptions);
protected _head: SkipListNode<K, V>;
/**
* The function returns the head node of a SkipList.
* @returns The method is returning a SkipListNode object with generic key type K and value type V.
*/
get head(): SkipListNode<K, V>;
protected _level: number;
/**
* The function returns the value of the private variable _level.
* @returns The level property of the object.
*/
get level(): number;
protected _maxLevel: number;
/**
* The function returns the maximum level.
* @returns The value of the variable `_maxLevel` is being returned.
*/
get maxLevel(): number;
protected _probability: number;
/**
* The function returns the probability value.
* @returns The probability value stored in the private variable `_probability` is being returned.
*/
get probability(): number;
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -39,8 +63,8 @@ * Get the value of the first element (the smallest element) in the Skip List.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -52,8 +76,8 @@ * Get the value of the last element (the largest element) in the Skip List.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -67,8 +91,8 @@ * The add function adds a new node with a given key and value to a Skip List data structure.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -82,17 +106,19 @@ * The function `get` retrieves the value associated with a given key from a skip list data structure.

/**
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* The function checks if a key exists in a data structure.
* @param {K} key - The parameter "key" is of type K, which represents the type of the key being
* checked.
* @returns a boolean value.
*/
has(key: K): boolean;
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -106,8 +132,8 @@ * The `delete` function removes a node with a specific key from a Skip List data structure.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -120,8 +146,8 @@ * Get the value of the first element in the Skip List that is greater than the given key.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -134,8 +160,9 @@ * Get the value of the last element in the Skip List that is less than the given key.

/**
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
* Space Complexity: O(1) - constant space.
* Time Complexity: O(maxLevel)
* Space Complexity: O(1)
* where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
*/
/**
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
* Space Complexity: O(1) - constant space.
* Time Complexity: O(maxLevel)
* Space Complexity: O(1)
*

@@ -142,0 +169,0 @@ * The function "_randomLevel" generates a random level based on a given probability and maximum level.

@@ -13,2 +13,10 @@ "use strict";

class SkipList {
/**
* The constructor function initializes a SkipLinkedList object with optional options and elements.
* @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
* is used to initialize the SkipLinkedList with the given key-value pairs. If no elements are
* provided, the SkipLinkedList will be empty.
* @param {SkipLinkedListOptions} [options] - The `options` parameter is an optional object that can
* contain two properties:
*/
constructor(elements = [], options) {

@@ -31,11 +39,27 @@ this._head = new SkipListNode(undefined, undefined, this.maxLevel);

}
/**
* The function returns the head node of a SkipList.
* @returns The method is returning a SkipListNode object with generic key type K and value type V.
*/
get head() {
return this._head;
}
/**
* The function returns the value of the private variable _level.
* @returns The level property of the object.
*/
get level() {
return this._level;
}
/**
* The function returns the maximum level.
* @returns The value of the variable `_maxLevel` is being returned.
*/
get maxLevel() {
return this._maxLevel;
}
/**
* The function returns the probability value.
* @returns The probability value stored in the private variable `_probability` is being returned.
*/
get probability() {

@@ -45,8 +69,8 @@ return this._probability;

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -61,8 +85,8 @@ * Get the value of the first element (the smallest element) in the Skip List.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -82,8 +106,8 @@ * Get the value of the last element (the largest element) in the Skip List.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -114,8 +138,8 @@ * The add function adds a new node with a given key and value to a Skip List data structure.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -141,8 +165,10 @@ * The function `get` retrieves the value associated with a given key from a skip list data structure.

/**
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* The function checks if a key exists in a data structure.
* @param {K} key - The parameter "key" is of type K, which represents the type of the key being
* checked.
* @returns a boolean value.
*/

@@ -153,8 +179,8 @@ has(key) {

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -191,8 +217,8 @@ * The `delete` function removes a node with a specific key from a Skip List data structure.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -214,8 +240,8 @@ * Get the value of the first element in the Skip List that is greater than the given key.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -240,8 +266,9 @@ * Get the value of the last element in the Skip List that is less than the given key.

/**
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
* Space Complexity: O(1) - constant space.
* Time Complexity: O(maxLevel)
* Space Complexity: O(1)
* where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
*/
/**
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
* Space Complexity: O(1) - constant space.
* Time Complexity: O(maxLevel)
* Space Complexity: O(1)
*

@@ -248,0 +275,0 @@ * The function "_randomLevel" generates a random level based on a given probability and maximum level.

@@ -19,9 +19,33 @@ /**

protected _rows: number;
/**
* The function returns the number of rows.
* @returns The number of rows.
*/
get rows(): number;
protected _cols: number;
/**
* The function returns the value of the private variable _cols.
* @returns The number of columns.
*/
get cols(): number;
protected _data: number[][];
/**
* The function returns a two-dimensional array of numbers.
* @returns The data property, which is a two-dimensional array of numbers.
*/
get data(): number[][];
/**
* The above function returns the value of the _addFn property.
* @returns The value of the property `_addFn` is being returned.
*/
get addFn(): (a: number | undefined, b: number) => number | undefined;
/**
* The function returns the value of the _subtractFn property.
* @returns The `_subtractFn` property is being returned.
*/
get subtractFn(): (a: number, b: number) => number;
/**
* The function returns the value of the _multiplyFn property.
* @returns The `_multiplyFn` property is being returned.
*/
get multiplyFn(): (a: number, b: number) => number;

@@ -97,5 +121,2 @@ /**

dot(matrix: Matrix): Matrix | undefined;
protected _addFn(a: number | undefined, b: number): number | undefined;
protected _subtractFn(a: number, b: number): number;
protected _multiplyFn(a: number, b: number): number;
/**

@@ -109,4 +130,14 @@ * The function checks if a given row and column index is valid within a specified range.

*/
protected isValidIndex(row: number, col: number): boolean;
isValidIndex(row: number, col: number): boolean;
/**
* The `clone` function returns a new instance of the Matrix class with the same data and properties
* as the original instance.
* @returns The `clone()` method is returning a new instance of the `Matrix` class with the same data
* and properties as the current instance.
*/
clone(): Matrix;
protected _addFn(a: number | undefined, b: number): number | undefined;
protected _subtractFn(a: number, b: number): number;
protected _multiplyFn(a: number, b: number): number;
/**
* The function `_swapRows` swaps the positions of two rows in an array.

@@ -113,0 +144,0 @@ * @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.

@@ -47,17 +47,41 @@ "use strict";

}
/**
* The function returns the number of rows.
* @returns The number of rows.
*/
get rows() {
return this._rows;
}
/**
* The function returns the value of the private variable _cols.
* @returns The number of columns.
*/
get cols() {
return this._cols;
}
/**
* The function returns a two-dimensional array of numbers.
* @returns The data property, which is a two-dimensional array of numbers.
*/
get data() {
return this._data;
}
/**
* The above function returns the value of the _addFn property.
* @returns The value of the property `_addFn` is being returned.
*/
get addFn() {
return this._addFn;
}
/**
* The function returns the value of the _subtractFn property.
* @returns The `_subtractFn` property is being returned.
*/
get subtractFn() {
return this._subtractFn;
}
/**
* The function returns the value of the _multiplyFn property.
* @returns The `_multiplyFn` property is being returned.
*/
get multiplyFn() {

@@ -336,2 +360,28 @@ return this._multiplyFn;

}
/**
* The function checks if a given row and column index is valid within a specified range.
* @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
* matrix. It is a number that indicates the specific row in the matrix.
* @param {number} col - The "col" parameter represents the column index in a two-dimensional array
* or grid. It is used to check if the given column index is valid within the bounds of the grid.
* @returns A boolean value is being returned.
*/
isValidIndex(row, col) {
return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
}
/**
* The `clone` function returns a new instance of the Matrix class with the same data and properties
* as the original instance.
* @returns The `clone()` method is returning a new instance of the `Matrix` class with the same data
* and properties as the current instance.
*/
clone() {
return new Matrix(this.data, {
rows: this.rows,
cols: this.cols,
addFn: this.addFn,
subtractFn: this.subtractFn,
multiplyFn: this.multiplyFn
});
}
_addFn(a, b) {

@@ -349,13 +399,2 @@ if (a === undefined)

/**
* The function checks if a given row and column index is valid within a specified range.
* @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
* matrix. It is a number that indicates the specific row in the matrix.
* @param {number} col - The "col" parameter represents the column index in a two-dimensional array
* or grid. It is used to check if the given column index is valid within the bounds of the grid.
* @returns A boolean value is being returned.
*/
isValidIndex(row, col) {
return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
}
/**
* The function `_swapRows` swaps the positions of two rows in an array.

@@ -362,0 +401,0 @@ * @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.

@@ -24,6 +24,32 @@ /**

protected readonly _bucketSize: number;
/**
* The constructor initializes a Deque object with an optional iterable of elements and options.
* @param elements - An iterable object (such as an array or a Set) that contains the initial
* elements to be added to the deque. It can also be an object with a `length` or `size` property
* that represents the number of elements in the iterable object. If no elements are provided, an
* empty deque
* @param {DequeOptions} [options] - The `options` parameter is an optional object that can contain
* configuration options for the deque. In this code, it is used to set the `bucketSize` option,
* which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
* or is not a number
*/
constructor(elements?: IterableWithSizeOrLength<E>, options?: DequeOptions);
/**
* The bucketSize function returns the size of the bucket.
*
* @return The size of the bucket
*/
get bucketSize(): number;
protected _buckets: E[][];
/**
* The buckets function returns the buckets property of the object.
*
* @return The buckets property
*/
get buckets(): E[][];
protected _size: number;
/**
* The size function returns the number of items in the stack.
* @return The number of values in the set
*/
get size(): number;

@@ -36,2 +62,6 @@ /**

get first(): E | undefined;
/**
* The last function returns the last element in the queue.
* @return The last element in the array
*/
get last(): E | undefined;

@@ -121,3 +151,3 @@ /**

*
* The `getAt` function retrieves an element at a specified position in an array-like data structure.
* The `at` function retrieves an element at a specified position in an array-like data structure.
* @param {number} pos - The `pos` parameter represents the position of the element that you want to

@@ -128,3 +158,3 @@ * retrieve from the data structure. It is of type `number` and should be a valid index within the

*/
getAt(pos: number): E;
at(pos: number): E;
/**

@@ -177,5 +207,7 @@ * Time Complexity: O(1)

* cut. It is a number that indicates the index of the character where the cut should be made.
* @param {boolean} isCutSelf - If true, the original deque will not be cut, and return a new deque
* @returns The method is returning the updated size of the data structure.
*/
cut(pos: number): number;
cut(pos: number, isCutSelf?: boolean): Deque<E>;
cutRest(pos: number, isCutSelf?: boolean): Deque<E>;
/**

@@ -276,18 +308,2 @@ * Time Complexity: O(n)

*
* The `find` function iterates over the elements in a deque and returns the first element for which
* the callback function returns true, or undefined if no such element is found.
* @param callback - A function that takes three parameters: element, index, and deque. It should
* return a boolean value indicating whether the element satisfies a certain condition.
* @returns The method `find` returns the first element in the deque that satisfies the condition
* specified by the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback: (element: E, index: number, deque: Deque<E>) => boolean): E | undefined;
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function "indexOf" returns the index of the first occurrence of a given element in an array,

@@ -321,2 +337,16 @@ * or -1 if the element is not found.

*
* The `clone()` function returns a new instance of the `Deque` class with the same elements and
* bucket size as the original instance.
* @returns The `clone()` method is returning a new instance of the `Deque` class with the same
* elements as the original deque (`this`) and the same bucket size.
*/
clone(): Deque<E>;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function creates a new deque containing elements from the original deque that satisfy

@@ -323,0 +353,0 @@ * a given predicate function.

@@ -14,2 +14,13 @@ "use strict";

class Deque extends base_1.IterableElementBase {
/**
* The constructor initializes a Deque object with an optional iterable of elements and options.
* @param elements - An iterable object (such as an array or a Set) that contains the initial
* elements to be added to the deque. It can also be an object with a `length` or `size` property
* that represents the number of elements in the iterable object. If no elements are provided, an
* empty deque
* @param {DequeOptions} [options] - The `options` parameter is an optional object that can contain
* configuration options for the deque. In this code, it is used to set the `bucketSize` option,
* which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
* or is not a number
*/
constructor(elements = [], options) {

@@ -54,5 +65,22 @@ super();

}
/**
* The bucketSize function returns the size of the bucket.
*
* @return The size of the bucket
*/
get bucketSize() {
return this._bucketSize;
}
/**
* The buckets function returns the buckets property of the object.
*
* @return The buckets property
*/
get buckets() {
return this._buckets;
}
/**
* The size function returns the number of items in the stack.
* @return The number of values in the set
*/
get size() {

@@ -71,2 +99,6 @@ return this._size;

}
/**
* The last function returns the last element in the queue.
* @return The last element in the array
*/
get last() {

@@ -232,3 +264,3 @@ if (this.size === 0)

while (index < this.size) {
yield this.getAt(index);
yield this.at(index);
index++;

@@ -244,3 +276,3 @@ }

while (index >= 0) {
yield this.getAt(index);
yield this.at(index);
index--;

@@ -257,3 +289,3 @@ }

*
* The `getAt` function retrieves an element at a specified position in an array-like data structure.
* The `at` function retrieves an element at a specified position in an array-like data structure.
* @param {number} pos - The `pos` parameter represents the position of the element that you want to

@@ -264,3 +296,3 @@ * retrieve from the data structure. It is of type `number` and should be a valid index within the

*/
getAt(pos) {
at(pos) {
(0, utils_1.rangeCheck)(pos, 0, this.size - 1);

@@ -323,5 +355,5 @@ const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);

for (let i = pos; i < this.size; ++i) {
arr.push(this.getAt(i));
arr.push(this.at(i));
}
this.cut(pos - 1);
this.cut(pos - 1, true);
for (let i = 0; i < num; ++i)

@@ -346,15 +378,45 @@ this.push(element);

* cut. It is a number that indicates the index of the character where the cut should be made.
* @param {boolean} isCutSelf - If true, the original deque will not be cut, and return a new deque
* @returns The method is returning the updated size of the data structure.
*/
cut(pos) {
if (pos < 0) {
this.clear();
return 0;
cut(pos, isCutSelf = false) {
if (isCutSelf) {
if (pos < 0) {
this.clear();
return this;
}
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
this._bucketLast = bucketIndex;
this._lastInBucket = indexInBucket;
this._size = pos + 1;
return this;
}
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
this._bucketLast = bucketIndex;
this._lastInBucket = indexInBucket;
this._size = pos + 1;
return this.size;
else {
const newDeque = new Deque([], { bucketSize: this._bucketSize });
for (let i = 0; i <= pos; i++) {
newDeque.push(this.at(i));
}
return newDeque;
}
}
cutRest(pos, isCutSelf = false) {
if (isCutSelf) {
if (pos < 0) {
this.clear();
return this;
}
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
this._bucketFirst = bucketIndex;
this._firstInBucket = indexInBucket;
this._size = this._size - pos;
return this;
}
else {
const newDeque = new Deque([], { bucketSize: this._bucketSize });
for (let i = pos; i < this.size; i++) {
newDeque.push(this.at(i));
}
return newDeque;
}
}
/**

@@ -415,3 +477,3 @@ * Time Complexity: O(n)

while (i < size) {
const oldElement = this.getAt(i);
const oldElement = this.at(i);
if (oldElement !== element) {

@@ -423,3 +485,3 @@ this.setAt(index, oldElement);

}
this.cut(index - 1);
this.cut(index - 1, true);
return true;

@@ -468,5 +530,5 @@ }

let index = 1;
let prev = this.getAt(0);
let prev = this.at(0);
for (let i = 1; i < this.size; ++i) {
const cur = this.getAt(i);
const cur = this.at(i);
if (cur !== prev) {

@@ -477,3 +539,3 @@ prev = cur;

}
this.cut(index - 1);
this.cut(index - 1, true);
return this;

@@ -498,3 +560,3 @@ }

for (let i = 0; i < this.size; ++i) {
arr.push(this.getAt(i));
arr.push(this.at(i));
}

@@ -551,26 +613,2 @@ arr.sort(comparator);

*
* The `find` function iterates over the elements in a deque and returns the first element for which
* the callback function returns true, or undefined if no such element is found.
* @param callback - A function that takes three parameters: element, index, and deque. It should
* return a boolean value indicating whether the element satisfies a certain condition.
* @returns The method `find` returns the first element in the deque that satisfies the condition
* specified by the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback) {
for (let i = 0; i < this.size; ++i) {
const element = this.getAt(i);
if (callback(element, i, this)) {
return element;
}
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function "indexOf" returns the index of the first occurrence of a given element in an array,

@@ -585,3 +623,3 @@ * or -1 if the element is not found.

for (let i = 0; i < this.size; ++i) {
if (this.getAt(i) === element) {
if (this.at(i) === element) {
return i;

@@ -614,2 +652,18 @@ }

*
* The `clone()` function returns a new instance of the `Deque` class with the same elements and
* bucket size as the original instance.
* @returns The `clone()` method is returning a new instance of the `Deque` class with the same
* elements as the original deque (`this`) and the same bucket size.
*/
clone() {
return new Deque([...this], { bucketSize: this.bucketSize });
}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function creates a new deque containing elements from the original deque that satisfy

@@ -724,3 +778,3 @@ * a given predicate function.

for (let i = 0; i < this.size; ++i) {
yield this.getAt(i);
yield this.at(i);
}

@@ -727,0 +781,0 @@ }

@@ -27,4 +27,12 @@ /**

protected _elements: E[];
/**
* The elements function returns the elements of this set.
* @return An array of the elements in the stack
*/
get elements(): E[];
protected _offset: number;
/**
* The offset function returns the offset of the current page.
* @return The value of the private variable _offset
*/
get offset(): number;

@@ -98,2 +106,14 @@ /**

/**
* The delete function removes an element from the list.
* @param element: E Specify the element to be deleted
* @return A boolean value indicating whether the element was successfully deleted or not
*/
delete(element: E): boolean;
/**
* The deleteAt function deletes the element at a given index.
* @param index: number Determine the index of the element to be deleted
* @return A boolean value
*/
deleteAt(index: number): boolean;
/**
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.

@@ -158,3 +178,3 @@ * Space Complexity: O(1) - no additional space is used.

*/
getAt(index: number): E | undefined;
at(index: number): E | undefined;
/**

@@ -189,8 +209,9 @@ * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.

/**
* Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
* Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
* Time Complexity: O(n)
* Space Complexity: O(n)
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
*/
/**
* Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
* Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -274,2 +295,15 @@ * The `clone()` function returns a new Queue object with the same elements as the original Queue.

peek(): E | undefined;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
* the current instance.
* @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
* values as the original `LinkedListQueue`.
*/
clone(): LinkedListQueue<E>;
}

@@ -31,5 +31,13 @@ "use strict";

}
/**
* The elements function returns the elements of this set.
* @return An array of the elements in the stack
*/
get elements() {
return this._elements;
}
/**
* The offset function returns the offset of the current page.
* @return The value of the private variable _offset
*/
get offset() {

@@ -128,2 +136,20 @@ return this._offset;

/**
* The delete function removes an element from the list.
* @param element: E Specify the element to be deleted
* @return A boolean value indicating whether the element was successfully deleted or not
*/
delete(element) {
const index = this.elements.indexOf(element);
return this.deleteAt(index);
}
/**
* The deleteAt function deletes the element at a given index.
* @param index: number Determine the index of the element to be deleted
* @return A boolean value
*/
deleteAt(index) {
const spliced = this.elements.splice(index, 1);
return spliced.length === 1;
}
/**
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.

@@ -196,3 +222,3 @@ * Space Complexity: O(1) - no additional space is used.

*/
getAt(index) {
at(index) {
return this.elements[index];

@@ -236,8 +262,9 @@ }

/**
* Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
* Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
* Time Complexity: O(n)
* Space Complexity: O(n)
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
*/
/**
* Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
* Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -355,3 +382,18 @@ * The `clone()` function returns a new Queue object with the same elements as the original Queue.

}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
* the current instance.
* @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
* values as the original `LinkedListQueue`.
*/
clone() {
return new LinkedListQueue(this.values());
}
}
exports.LinkedListQueue = LinkedListQueue;

@@ -27,2 +27,6 @@ /**

protected _elements: E[];
/**
* The elements function returns the elements of this set.
* @return An array of elements
*/
get elements(): E[];

@@ -92,2 +96,14 @@ /**

/**
* The delete function removes an element from the stack.
* @param element: E Specify the element to be deleted
* @return A boolean value indicating whether the element was successfully deleted or not
*/
delete(element: E): boolean;
/**
* The deleteAt function deletes the element at a given index.
* @param index: number Determine the index of the element to be deleted
* @return A boolean value
*/
deleteAt(index: number): boolean;
/**
* Time Complexity: O(n)

@@ -94,0 +110,0 @@ * Space Complexity: O(n)

@@ -28,2 +28,6 @@ "use strict";

}
/**
* The elements function returns the elements of this set.
* @return An array of elements
*/
get elements() {

@@ -112,2 +116,20 @@ return this._elements;

/**
* The delete function removes an element from the stack.
* @param element: E Specify the element to be deleted
* @return A boolean value indicating whether the element was successfully deleted or not
*/
delete(element) {
const index = this.elements.indexOf(element);
return this.deleteAt(index);
}
/**
* The deleteAt function deletes the element at a given index.
* @param index: number Determine the index of the element to be deleted
* @return A boolean value
*/
deleteAt(index) {
const spliced = this.elements.splice(index, 1);
return spliced.length === 1;
}
/**
* Time Complexity: O(n)

@@ -114,0 +136,0 @@ * Space Complexity: O(n)

@@ -33,9 +33,28 @@ /**

*/
export declare class Trie extends IterableElementBase<string> {
export declare class Trie extends IterableElementBase<string, Trie> {
/**
* The constructor function for the Trie class.
* @param words: Iterable string Initialize the trie with a set of words
* @param options?: TrieOptions Allow the user to pass in options for the trie
* @return This
*/
constructor(words?: Iterable<string>, options?: TrieOptions);
protected _size: number;
/**
* The size function returns the size of the stack.
* @return The number of elements in the list
*/
get size(): number;
protected _caseSensitive: boolean;
/**
* The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
*
* @return The value of the _casesensitive private variable
*/
get caseSensitive(): boolean;
protected _root: TrieNode;
/**
* The root function returns the root node of the tree.
* @return The root node
*/
get root(): TrieNode;

@@ -69,2 +88,7 @@ /**

/**
* The isEmpty function checks if the size of the queue is 0.
* @return True if the size of the queue is 0
*/
isEmpty(): boolean;
/**
* Time Complexity: O(M), where M is the length of the word being deleted.

@@ -167,2 +191,15 @@ * Space Complexity: O(M) - Due to the recursive DFS approach.

*
* The `clone` function returns a new instance of the Trie class with the same values and case
* sensitivity as the original Trie.
* @returns A new instance of the Trie class is being returned.
*/
clone(): Trie;
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function takes a predicate function and returns a new array containing all the

@@ -169,0 +206,0 @@ * elements for which the predicate function returns true.

@@ -31,2 +31,8 @@ "use strict";

class Trie extends base_1.IterableElementBase {
/**
* The constructor function for the Trie class.
* @param words: Iterable string Initialize the trie with a set of words
* @param options?: TrieOptions Allow the user to pass in options for the trie
* @return This
*/
constructor(words = [], options) {

@@ -47,8 +53,21 @@ super();

}
/**
* The size function returns the size of the stack.
* @return The number of elements in the list
*/
get size() {
return this._size;
}
/**
* The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
*
* @return The value of the _casesensitive private variable
*/
get caseSensitive() {
return this._caseSensitive;
}
/**
* The root function returns the root node of the tree.
* @return The root node
*/
get root() {

@@ -112,2 +131,9 @@ return this._root;

/**
* The isEmpty function checks if the size of the queue is 0.
* @return True if the size of the queue is 0
*/
isEmpty() {
return this.size === 0;
}
/**
* Time Complexity: O(M), where M is the length of the word being deleted.

@@ -340,2 +366,17 @@ * Space Complexity: O(M) - Due to the recursive DFS approach.

*
* The `clone` function returns a new instance of the Trie class with the same values and case
* sensitivity as the original Trie.
* @returns A new instance of the Trie class is being returned.
*/
clone() {
return new Trie(this.values(), { caseSensitive: this.caseSensitive });
}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function takes a predicate function and returns a new array containing all the

@@ -342,0 +383,0 @@ * elements for which the predicate function returns true.

import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
import { IterationType } from "../../common";
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
export type BinaryTreeOptions<K> = {

@@ -6,0 +6,0 @@ iterationType?: IterationType;

@@ -7,9 +7,10 @@ export type HashMapLinkedNode<K, V> = {

};
export type LinkedHashMapOptions<K> = {
export type LinkedHashMapOptions<K, V, R> = {
hashFn?: (key: K) => string;
objHashFn?: (key: K) => object;
toEntryFn?: (rawElement: R) => [K, V];
};
export type HashMapOptions<K, V, T> = {
export type HashMapOptions<K, V, R> = {
hashFn?: (key: K) => string;
toEntryFn?: (rawElement: T) => [K, V];
toEntryFn?: (rawElement: R) => [K, V];
};

@@ -16,0 +17,0 @@ export type HashMapStoreItem<K, V> = {

@@ -8,1 +8,2 @@ export type ToThunkFn = () => ReturnType<TrlFn>;

export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export type Any = string | number | boolean | object | null | undefined | symbol;
{
"name": "heap-typed",
"version": "1.50.1",
"version": "1.50.2",
"description": "Heap. Javascript & Typescript Data Structure.",

@@ -134,4 +134,4 @@ "main": "dist/index.js",

"dependencies": {
"data-structure-typed": "^1.50.0"
"data-structure-typed": "^1.50.2"
}
}

@@ -157,2 +157,3 @@ import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';

*/
/**

@@ -162,2 +163,100 @@ * Time Complexity: O(n)

*
* The `find` function iterates over the entries of a collection and returns the first value for
* which the callback function returns true.
* @param callbackfn - The callback function that will be called for each entry in the collection. It
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
* the collection. It should return a boolean value indicating whether the current entry matches the
* desired condition.
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
* be passed as the `this` value to the `callbackfn` function. If `thisArg
* @returns The method `find` returns the value of the first element in the iterable that satisfies
* the provided callback function. If no element satisfies the callback function, `undefined` is
* returned.
*/
find(callbackfn: EntryCallback<K, V, [K, V]>, thisArg?: any): [K, V] | undefined {
let index = 0;
for (const item of this) {
const [key, value] = item;
if (callbackfn.call(thisArg, value, key, index++, this)) return item;
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given key exists in a collection.
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
* the key that we want to check for existence in the data structure.
* @returns a boolean value. It returns true if the key is found in the collection, and false
* otherwise.
*/
has(key: K): boolean {
for (const item of this) {
const [itemKey] = item;
if (itemKey === key) return true;
}
return false;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given value exists in a collection.
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
* collection.
* @returns a boolean value, either true or false.
*/
hasValue(value: V): boolean {
for (const [, elementValue] of this) {
if (elementValue === value) return true;
}
return false;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `get` function retrieves the value associated with a given key from a collection.
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
* searched for in the collection.
* @returns The `get` method returns the value associated with the specified key if it exists in the
* collection, otherwise it returns `undefined`.
*/
get(key: K): V | undefined {
for (const item of this) {
const [itemKey, value] = item;
if (itemKey === key) return value;
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `reduce` function iterates over key-value pairs and applies a callback function to each pair,

@@ -185,9 +284,2 @@ * accumulating a single value.

hasValue(value: V): boolean {
for (const [, elementValue] of this) {
if (elementValue === value) return true;
}
return false;
}
/**

@@ -201,6 +293,10 @@ * Time Complexity: O(n)

abstract isEmpty(): boolean;
abstract clone(): any;
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
}
export abstract class IterableElementBase<V> {
export abstract class IterableElementBase<E = any, C = any> {
/**

@@ -219,3 +315,3 @@ * Time Complexity: O(n)

*/
* [Symbol.iterator](...args: any[]): IterableIterator<V> {
* [Symbol.iterator](...args: any[]): IterableIterator<E> {
yield* this._getIterator(...args);

@@ -234,3 +330,3 @@ }

*/
* values(): IterableIterator<V> {
* values(): IterableIterator<E> {
for (const item of this) {

@@ -259,6 +355,6 @@ yield item;

*/
every(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean {
every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean {
let index = 0;
for (const item of this) {
if (!predicate.call(thisArg, item as V, index++, this)) {
if (!predicate.call(thisArg, item, index++, this)) {
return false;

@@ -288,6 +384,6 @@ }

*/
some(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean {
some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean {
let index = 0;
for (const item of this) {
if (predicate.call(thisArg, item as V, index++, this)) {
if (predicate.call(thisArg, item, index++, this)) {
return true;

@@ -303,2 +399,3 @@ }

*/
/**

@@ -317,6 +414,6 @@ * Time Complexity: O(n)

*/
forEach(callbackfn: ElementCallback<V, void>, thisArg?: any): void {
forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void {
let index = 0;
for (const item of this) {
callbackfn.call(thisArg, item as V, index++, this);
callbackfn.call(thisArg, item, index++, this);
}

@@ -329,2 +426,3 @@ }

*/
/**

@@ -334,2 +432,53 @@ * Time Complexity: O(n)

*
* The `find` function iterates over the elements of an array-like object and returns the first
* element that satisfies the provided callback function.
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
* the array. It takes three arguments: the current element being processed, the index of the current
* element, and the array itself. The function should return a boolean value indicating whether the
* current element matches the desired condition.
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
* be passed as the `this` value to the `callbackfn` function. If `thisArg
* @returns The `find` method returns the first element in the array that satisfies the provided
* callback function. If no element satisfies the callback function, `undefined` is returned.
*/
find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined {
let index = 0;
for (const item of this) {
if (callbackfn.call(thisArg, item, index++, this)) return item;
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function checks if a given element exists in a collection.
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
* represents the element that we want to check for existence in the collection.
* @returns a boolean value. It returns true if the element is found in the collection, and false
* otherwise.
*/
has(element: E): boolean {
for (const ele of this) {
if (ele === element) return true;
}
return false;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `reduce` function iterates over the elements of an array-like object and applies a callback

@@ -344,7 +493,7 @@ * function to reduce them into a single value.

*/
reduce<U>(callbackfn: ReduceElementCallback<V, U>, initialValue: U): U {
reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U {
let accumulator = initialValue;
let index = 0;
for (const item of this) {
accumulator = callbackfn(accumulator, item as V, index++, this);
accumulator = callbackfn(accumulator, item as E, index++, this);
}

@@ -362,3 +511,7 @@ return accumulator;

protected abstract _getIterator(...args: any[]): IterableIterator<V>;
abstract isEmpty(): boolean;
abstract clone(): C;
protected abstract _getIterator(...args: any[]): IterableIterator<E>;
}

@@ -20,7 +20,7 @@ /**

export class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<
K,
V,
N
> {
export class AVLTreeNode<
K = any,
V = any,
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>
> extends BSTNode<K, V, NODE> {
height: number;

@@ -46,10 +46,10 @@

V = any,
N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, NODE, TREE> = AVLTree<K, V, NODE, AVLTreeNested<K, V, NODE>>
>
extends BST<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE> {
extends BST<K, V, NODE, TREE>
implements IBinaryTree<K, V, NODE, TREE> {
/**
* The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
* objects. It represents a collection of nodes that will be added to the AVL tree during

@@ -61,3 +61,3 @@ * initialization.

*/
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: AVLTreeOptions<K>) {
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: AVLTreeOptions<K>) {
super([], options);

@@ -73,7 +73,7 @@ if (keysOrNodesOrEntries) super.addMany(keysOrNodesOrEntries);

* type `V`, which means it can be any value that is assignable to the `value` property of the
* node type `N`.
* node type `NODE`.
* @returns a new AVLTreeNode object with the specified key and value.
*/
override createNode(key: K, value?: V): N {
return new AVLTreeNode<K, V, N>(key, value) as N;
override createNode(key: K, value?: V): NODE {
return new AVLTreeNode<K, V, NODE>(key, value) as NODE;
}

@@ -89,3 +89,3 @@

override createTree(options?: AVLTreeOptions<K>): TREE {
return new AVLTree<K, V, N, TREE>([], {
return new AVLTree<K, V, NODE, TREE>([], {
iterationType: this.iterationType,

@@ -99,6 +99,6 @@ variant: this.variant,

* The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
*/
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
return keyOrNodeOrEntry instanceof AVLTreeNode;

@@ -125,3 +125,3 @@ }

*/
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean {
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
if (keyOrNodeOrEntry === null) return false;

@@ -150,9 +150,9 @@ const inserted = super.add(keyOrNodeOrEntry, value);

* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
* parameter of type `N
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
* parameter of type `NODE
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
*/
override delete<C extends BTNCallback<N>>(
override delete<C extends BTNCallback<NODE>>(
identifier: ReturnType<C>,
callback: C = this._defaultOneParamCallback as C
): BinaryTreeDeleteResult<N>[] {
): BinaryTreeDeleteResult<NODE>[] {
if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;

@@ -171,5 +171,5 @@ const deletedResults = super.delete(identifier, callback);

* tree.
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
* needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
* node where the values from the source node will be swapped to.

@@ -179,3 +179,6 @@ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`

*/
protected override _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined {
protected override _swapProperties(
srcNode: BSTNKeyOrNode<K, NODE>,
destNode: BSTNKeyOrNode<K, NODE>
): NODE | undefined {
srcNode = this.ensureNode(srcNode);

@@ -208,3 +211,2 @@ destNode = this.ensureNode(destNode);

* Space Complexity: O(1)
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
*/

@@ -217,7 +219,7 @@

* The function calculates the balance factor of a node in a binary tree.
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
* height of the left subtree from the height of the right subtree.
*/
protected _balanceFactor(node: N): number {
protected _balanceFactor(node: NODE): number {
if (!node.right)

@@ -235,3 +237,2 @@ // node has no right subtree

* Space Complexity: O(1)
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
*/

@@ -245,5 +246,5 @@

* right children.
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
*/
protected _updateHeight(node: N): void {
protected _updateHeight(node: NODE): void {
if (!node.left && !node.right) node.height = 0;

@@ -258,60 +259,4 @@ else if (!node.left) {

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
* to restore balance in an AVL tree after inserting a node.
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
* AVL tree that needs to be balanced.
*/
protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void {
node = this.ensureNode(node);
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
for (let i = 0; i < path.length; i++) {
// second O(log n)
const A = path[i];
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
this._updateHeight(A); // first O(1)
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
switch (
this._balanceFactor(A) // second O(1)
) {
case -2:
if (A && A.left) {
if (this._balanceFactor(A.left) <= 0) {
// second O(1)
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
this._balanceLL(A);
} else {
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
this._balanceLR(A);
}
}
break;
case +2:
if (A && A.right) {
if (this._balanceFactor(A.right) >= 0) {
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
this._balanceRR(A);
} else {
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
this._balanceRL(A);
}
}
}
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
}
}
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
* constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
*/

@@ -324,5 +269,5 @@

* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceLL(A: N): void {
protected _balanceLL(A: NODE): void {
const parentOfA = A.parent;

@@ -363,5 +308,5 @@ const B = A.left;

* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceLR(A: N): void {
protected _balanceLR(A: NODE): void {
const parentOfA = A.parent;

@@ -420,5 +365,5 @@ const B = A.left;

* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceRR(A: N): void {
protected _balanceRR(A: NODE): void {
const parentOfA = A.parent;

@@ -464,5 +409,5 @@ const B = A.right;

* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
* @param {N} A - A is a node in a binary tree.
* @param {NODE} A - A is a node in a binary tree.
*/
protected _balanceRL(A: N): void {
protected _balanceRL(A: NODE): void {
const parentOfA = A.parent;

@@ -510,3 +455,58 @@ const B = A.right;

protected _replaceNode(oldNode: N, newNode: N): N {
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
* to restore balance in an AVL tree after inserting a node.
* @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
* AVL tree that needs to be balanced.
*/
protected _balancePath(node: KeyOrNodeOrEntry<K, V, NODE>): void {
node = this.ensureNode(node);
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
for (let i = 0; i < path.length; i++) {
// second O(log n)
const A = path[i];
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
this._updateHeight(A); // first O(1)
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
switch (
this._balanceFactor(A) // second O(1)
) {
case -2:
if (A && A.left) {
if (this._balanceFactor(A.left) <= 0) {
// second O(1)
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
this._balanceLL(A);
} else {
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
this._balanceLR(A);
}
}
break;
case +2:
if (A && A.right) {
if (this._balanceFactor(A.right) >= 0) {
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
this._balanceRR(A);
} else {
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
this._balanceRL(A);
}
}
}
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
}
}
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
newNode.height = oldNode.height;

@@ -513,0 +513,0 @@

@@ -21,8 +21,8 @@ /**

export class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTNodeNested<K, V>> extends BinaryTreeNode<
export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<
K,
V,
N
NODE
> {
override parent?: N;
override parent?: NODE;

@@ -36,18 +36,11 @@ constructor(key: K, value?: V) {

protected override _left?: N;
protected override _left?: NODE;
/**
* Get the left child node.
*/
override get left(): N | undefined {
override get left(): NODE | undefined {
return this._left;
}
/**
* Set the left child node.
* @param {N | undefined} v - The left child node.
*/
override set left(v: N | undefined) {
override set left(v: NODE | undefined) {
if (v) {
v.parent = this as unknown as N;
v.parent = this as unknown as NODE;
}

@@ -57,18 +50,11 @@ this._left = v;

protected override _right?: N;
protected override _right?: NODE;
/**
* Get the right child node.
*/
override get right(): N | undefined {
override get right(): NODE | undefined {
return this._right;
}
/**
* Set the right child node.
* @param {N | undefined} v - The right child node.
*/
override set right(v: N | undefined) {
override set right(v: NODE | undefined) {
if (v) {
v.parent = this as unknown as N;
v.parent = this as unknown as NODE;
}

@@ -91,7 +77,7 @@ this._right = v;

V = any,
N extends BSTNode<K, V, N> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, N, TREE> = BST<K, V, N, BSTNested<K, V, N>>
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>
>
extends BinaryTree<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE> {
extends BinaryTree<K, V, NODE, TREE>
implements IBinaryTree<K, V, NODE, TREE> {
/**

@@ -105,3 +91,3 @@ * This is the constructor function for a binary search tree class in TypeScript, which initializes

*/
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: BSTOptions<K>) {
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: BSTOptions<K>) {
super([], options);

@@ -119,5 +105,5 @@

protected override _root?: N;
protected override _root?: NODE;
override get root(): N | undefined {
override get root(): NODE | undefined {
return this._root;

@@ -140,4 +126,4 @@ }

*/
override createNode(key: K, value?: V): N {
return new BSTNode<K, V, N>(key, value) as N;
override createNode(key: K, value?: V): NODE {
return new BSTNode<K, V, NODE>(key, value) as NODE;
}

@@ -153,3 +139,3 @@

override createTree(options?: Partial<BSTOptions<K>>): TREE {
return new BST<K, V, N, TREE>([], {
return new BST<K, V, NODE, TREE>([], {
iterationType: this.iterationType,

@@ -162,11 +148,11 @@ variant: this.variant,

/**
* The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
* otherwise it returns undefined.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
* @returns a node of type N or undefined.
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
* @returns a node of type NODE or undefined.
*/
override exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined {
let node: N | undefined;
override keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
let node: NODE | undefined;
if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {

@@ -194,3 +180,2 @@ return;

* Space Complexity: O(log n)
* Average case for a balanced tree. Space for the recursive call stack in the worst case.
*/

@@ -204,13 +189,13 @@

* otherwise it returns the key itself.
* @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
* `undefined`.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
* @returns either a node object (N) or undefined.
* @returns either a node object (NODE) or undefined.
*/
override ensureNode(
keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>,
keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>,
iterationType = IterationType.ITERATIVE
): N | undefined {
let res: N | undefined;
): NODE | undefined {
let res: NODE | undefined;
if (this.isRealNode(keyOrNodeOrEntry)) {

@@ -228,6 +213,6 @@ res = keyOrNodeOrEntry;

* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
*/
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
return keyOrNodeOrEntry instanceof BSTNode;

@@ -239,3 +224,2 @@ }

* Space Complexity: O(1)
* - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
*/

@@ -255,4 +239,4 @@

*/
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean {
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
if (newNode === undefined) return false;

@@ -283,3 +267,2 @@

current.left = newNode;
newNode.parent = current;
this._size++;

@@ -292,3 +275,2 @@ return true;

current.right = newNode;
newNode.parent = current;
this._size++;

@@ -306,4 +288,3 @@ return true;

* Time Complexity: O(k log n)
* Space Complexity: O(k)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
* Space Complexity: O(k + log n)
*/

@@ -313,3 +294,3 @@

* Time Complexity: O(k log n)
* Space Complexity: O(k)
* Space Complexity: O(k + log n)
*

@@ -330,6 +311,6 @@ * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally

* `this.iterationType`, which suggests that it is a property of the current object.
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
* @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
*/
override addMany(
keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>,
keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>,
values?: Iterable<V | undefined>,

@@ -356,5 +337,5 @@ isBalanceAdd = true,

const realBTNExemplars: BTNodePureExemplar<K, V, N>[] = [];
const realBTNExemplars: BTNodePureExemplar<K, V, NODE>[] = [];
const isRealBTNExemplar = (kve: KeyOrNodeOrEntry<K, V, N>): kve is BTNodePureExemplar<K, V, N> => {
const isRealBTNExemplar = (kve: KeyOrNodeOrEntry<K, V, NODE>): kve is BTNodePureExemplar<K, V, NODE> => {
if (kve === undefined || kve === null) return false;

@@ -368,3 +349,3 @@ return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));

let sorted: BTNodePureExemplar<K, V, N>[] = [];
let sorted: BTNodePureExemplar<K, V, NODE>[] = [];

@@ -384,3 +365,3 @@ sorted = realBTNExemplars.sort((a, b) => {

const _dfs = (arr: BTNodePureExemplar<K, V, N>[]) => {
const _dfs = (arr: BTNodePureExemplar<K, V, NODE>[]) => {
if (arr.length === 0) return;

@@ -438,9 +419,9 @@

* values:
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
* found in the binary tree. If no node is found, it returns `undefined`.
*/
override getNodeByKey(key: K, iterationType = IterationType.ITERATIVE): N | undefined {
override getNodeByKey(key: K, iterationType = IterationType.ITERATIVE): NODE | undefined {
if (!this.root) return undefined;
if (iterationType === IterationType.RECURSIVE) {
const _dfs = (cur: N): N | undefined => {
const _dfs = (cur: NODE): NODE | undefined => {
if (cur.key === key) return cur;

@@ -455,3 +436,3 @@ if (!cur.left && !cur.right) return;

} else {
const queue = new Queue<N>([this.root]);
const queue = new Queue<NODE>([this.root]);
while (queue.size > 0) {

@@ -470,4 +451,3 @@ const cur = queue.shift();

* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
* Space Complexity: O(k + log n)
* /

@@ -477,3 +457,3 @@

* Time Complexity: O(log n)
* Space Complexity: O(log n)
* Space Complexity: O(k + log n)
*

@@ -485,5 +465,5 @@ * The function `getNodes` returns an array of nodes that match a given identifier, using either a

* callback function `C`.
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` as its
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
* argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
* function type that extends the `BTNCallback<N>` type. The `BTNCallback<N>` type is
* function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
* @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the

@@ -493,3 +473,3 @@ * first node that matches the identifier. If set to true, the function will return an array

* searching for all nodes that match the identifier and return an array containing
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
* for the traversal. It can be either a key value or a node object. If it is undefined, the

@@ -499,17 +479,17 @@ * traversal will start from the root of the tree.

* performed on the binary tree. It can have two possible values:
* @returns The method returns an array of nodes (`N[]`).
* @returns The method returns an array of nodes (`NODE[]`).
*/
override getNodes<C extends BTNCallback<N>>(
override getNodes<C extends BTNCallback<NODE>>(
identifier: ReturnType<C> | undefined,
callback: C = this._defaultOneParamCallback as C,
onlyOne = false,
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
beginRoot: KeyOrNodeOrEntry<K, V, NODE> = this.root,
iterationType = this.iterationType
): N[] {
): NODE[] {
beginRoot = this.ensureNode(beginRoot);
if (!beginRoot) return [];
const ans: N[] = [];
const ans: NODE[] = [];
if (iterationType === IterationType.RECURSIVE) {
const _traverse = (cur: N) => {
const _traverse = (cur: NODE) => {
const callbackResult = callback(cur);

@@ -534,3 +514,3 @@ if (callbackResult === identifier) {

} else {
const queue = new Queue<N>([beginRoot]);
const queue = new Queue<NODE>([beginRoot]);
while (queue.size > 0) {

@@ -559,22 +539,2 @@ const cur = queue.shift();

// /**
// * The function overrides the subTreeTraverse method and returns the result of calling the super
// * method with the provided arguments.
// * @param {C} callback - The `callback` parameter is a function that will be called for each node in
// * the subtree traversal. It should accept a single parameter of type `N`, which represents a node in
// * the tree. The return type of the callback function can be any type.
// * @param beginRoot - The `beginRoot` parameter is the starting point for traversing the subtree. It
// * can be either a key, a node, or an entry.
// * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
// * be performed during the traversal of the subtree. It can have one of the following values:
// * @returns The method is returning an array of the return type of the callback function.
// */
// override subTreeTraverse<C extends BTNCallback<N>>(
// callback: C = this._defaultOneParamCallback as C,
// beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
// iterationType = this.iterationType
// ): ReturnType<C>[] {
// return super.subTreeTraverse(callback, beginRoot, iterationType, false);
// }
/**

@@ -604,6 +564,6 @@ * Time complexity: O(n)

*/
override dfs<C extends BTNCallback<N>>(
override dfs<C extends BTNCallback<NODE>>(
callback: C = this._defaultOneParamCallback as C,
pattern: DFSOrderPattern = 'in',
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
beginRoot: KeyOrNodeOrEntry<K, V, NODE> = this.root,
iterationType: IterationType = IterationType.ITERATIVE

@@ -636,5 +596,5 @@ ): ReturnType<C>[] {

*/
override bfs<C extends BTNCallback<N>>(
override bfs<C extends BTNCallback<NODE>>(
callback: C = this._defaultOneParamCallback as C,
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
beginRoot: KeyOrNodeOrEntry<K, V, NODE> = this.root,
iterationType = this.iterationType

@@ -657,3 +617,3 @@ ): ReturnType<C>[] {

* @param {C} callback - The `callback` parameter is a generic type `C` that extends
* `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
* during the level listing process.

@@ -669,5 +629,5 @@ * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the

*/
override listLevels<C extends BTNCallback<N>>(
override listLevels<C extends BTNCallback<NODE>>(
callback: C = this._defaultOneParamCallback as C,
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
beginRoot: KeyOrNodeOrEntry<K, V, NODE> = this.root,
iterationType = this.iterationType

@@ -679,15 +639,14 @@ ): ReturnType<C>[][] {

/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).

@@ -698,3 +657,3 @@ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,

*/
lastKey(beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root): K | undefined {
lastKey(beginRoot: KeyOrNodeOrEntry<K, V, NODE> = this.root): K | undefined {
let current = this.ensureNode(beginRoot);

@@ -720,3 +679,2 @@ if (!current) return undefined;

* Space Complexity: O(log n)
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
*/

@@ -732,3 +690,3 @@

* that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
* parameter of type `N` (the node type) and returns a value of any type.
* parameter of type `NODE` (the node type) and returns a value of any type.
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to

@@ -738,3 +696,3 @@ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type

* `lesserOrGreater` are
* @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
* @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
* binary tree that you want to traverse from. It can be specified either by its key, by the node

@@ -747,10 +705,10 @@ * object itself, or it can be left undefined to start the traversal from the root of the tree.

*/
lesserOrGreaterTraverse<C extends BTNCallback<N>>(
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(
callback: C = this._defaultOneParamCallback as C,
lesserOrGreater: CP = CP.lt,
targetNode: KeyOrNodeOrEntry<K, V, N> = this.root,
targetNode: KeyOrNodeOrEntry<K, V, NODE> = this.root,
iterationType = this.iterationType
): ReturnType<C>[] {
targetNode = this.ensureNode(targetNode);
const ans: ReturnType<BTNCallback<N>>[] = [];
const ans: ReturnType<BTNCallback<NODE>>[] = [];
if (!targetNode) return ans;

@@ -762,3 +720,3 @@ if (!this.root) return ans;

if (iterationType === IterationType.RECURSIVE) {
const _traverse = (cur: N) => {
const _traverse = (cur: NODE) => {
const compared = this._compare(cur.key, targetKey);

@@ -775,3 +733,3 @@ if (compared === lesserOrGreater) ans.push(callback(cur));

} else {
const queue = new Queue<N>([this.root]);
const queue = new Queue<NODE>([this.root]);
while (queue.size > 0) {

@@ -855,4 +813,4 @@ const cur = queue.shift();

/**
* Time Complexity: O(n) - Building a balanced tree from a sorted array.
* Space Complexity: O(n) - Additional space is required for the sorted array.
* Time Complexity: O(n)
* Space Complexity: O(log n)
*/

@@ -875,3 +833,3 @@

if (iterationType === IterationType.RECURSIVE) {
const _height = (cur: N | undefined): number => {
const _height = (cur: NODE | undefined): number => {
if (!cur) return 0;

@@ -885,6 +843,6 @@ const leftHeight = _height(cur.left),

} else {
const stack: N[] = [];
let node: N | undefined = this.root,
last: N | undefined = undefined;
const depths: Map<N, number> = new Map();
const stack: NODE[] = [];
let node: NODE | undefined = this.root,
last: NODE | undefined = undefined;
const depths: Map<NODE, number> = new Map();

@@ -915,3 +873,3 @@ while (stack.length > 0 || node) {

protected _setRoot(v: N | undefined) {
protected _setRoot(v: NODE | undefined) {
if (v) {

@@ -918,0 +876,0 @@ v.parent = undefined;

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

BTNCallback,
IterationType,
KeyOrNodeOrEntry,

@@ -27,4 +26,4 @@ RBTNColor,

V = any,
N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNodeNested<K, V>
> extends BSTNode<K, V, N> {
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>
> extends BSTNode<K, V, NODE> {
color: RBTNColor;

@@ -48,8 +47,8 @@

V = any,
N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, N, TREE> = RedBlackTree<K, V, N, RedBlackTreeNested<K, V, N>>
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>
>
extends BST<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE> {
Sentinel: N = new RedBlackTreeNode<K, V>(NaN as K) as unknown as N;
extends BST<K, V, NODE, TREE>
implements IBinaryTree<K, V, NODE, TREE> {
Sentinel: NODE = new RedBlackTreeNode<K, V>(NaN as K) as unknown as NODE;

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

* initializes the tree with optional nodes and options.
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
* objects. It represents the initial nodes that will be added to the RBTree during its

@@ -68,3 +67,3 @@ * construction. If this parameter is provided, the `addMany` method is called to add all the

*/
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: RBTreeOptions<K>) {
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: RBTreeOptions<K>) {
super([], options);

@@ -76,5 +75,5 @@

protected _root: N;
protected _root: NODE;
get root(): N {
get root(): NODE {
return this._root;

@@ -101,4 +100,4 @@ }

*/
override createNode(key: K, value?: V, color: RBTNColor = RBTNColor.BLACK): N {
return new RedBlackTreeNode<K, V, N>(key, value, color) as N;
override createNode(key: K, value?: V, color: RBTNColor = RBTNColor.BLACK): NODE {
return new RedBlackTreeNode<K, V, NODE>(key, value, color) as NODE;
}

@@ -114,3 +113,3 @@

override createTree(options?: RBTreeOptions<K>): TREE {
return new RedBlackTree<K, V, N, TREE>([], {
return new RedBlackTree<K, V, NODE, TREE>([], {
iterationType: this.iterationType,

@@ -122,11 +121,11 @@ ...options

/**
* The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
* is provided, it will be used when creating the new node. If no value is provided, the new node
* @returns a node of type N or undefined.
* @returns a node of type NODE or undefined.
*/
override exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined {
let node: N | undefined;
override keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
let node: NODE | undefined;

@@ -154,16 +153,11 @@ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {

* The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode
* class.
*/
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
return keyOrNodeOrEntry instanceof RedBlackTreeNode;
}
/**
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
* Space Complexity: O(1)
*/
override isRealNode(node: N | undefined): node is N {
override isRealNode(node: NODE | undefined): node is NODE {
if (node === this.Sentinel || node === undefined) return false;

@@ -176,3 +170,3 @@ return node instanceof RedBlackTreeNode;

* Space Complexity: O(1)
* on average (where n is the number of nodes in the tree)
* On average (where n is the number of nodes in the tree)
*/

@@ -190,6 +184,6 @@

* being added to the binary search tree.
* @returns The method `add` returns either the newly added node (`N`) or `undefined`.
* @returns The method `add` returns either the newly added node (`NODE`) or `undefined`.
*/
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean {
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
if (newNode === undefined) return false;

@@ -200,4 +194,4 @@

let y: N | undefined = undefined;
let x: N | undefined = this.root;
let y: NODE | undefined = undefined;
let x: NODE | undefined = this.root;

@@ -248,3 +242,2 @@ while (x !== this.Sentinel) {

* Space Complexity: O(1)
* on average (where n is the number of nodes in the tree)
*/

@@ -262,16 +255,16 @@

* you don't want to
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` and
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` and
* returns a value of type `ReturnType<C>`. It is used to determine if a node should be deleted based
* on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
* @returns an array of `BinaryTreeDeleteResult<N>`.
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
*/
delete<C extends BTNCallback<N>>(
delete<C extends BTNCallback<NODE>>(
identifier: ReturnType<C> | null | undefined,
callback: C = this._defaultOneParamCallback as C
): BinaryTreeDeleteResult<N>[] {
const ans: BinaryTreeDeleteResult<N>[] = [];
): BinaryTreeDeleteResult<NODE>[] {
const ans: BinaryTreeDeleteResult<NODE>[] = [];
if (identifier === null) return ans;
const helper = (node: N | undefined): void => {
let z: N = this.Sentinel;
let x: N | undefined, y: N;
const helper = (node: NODE | undefined): void => {
let z: NODE = this.Sentinel;
let x: NODE | undefined, y: NODE;
while (node !== this.Sentinel) {

@@ -329,23 +322,2 @@ if (node && callback(node) === identifier) {

getNode<C extends BTNCallback<N, K>>(
identifier: K,
callback?: C,
beginRoot?: N | undefined,
iterationType?: IterationType
): N | undefined;
getNode<C extends BTNCallback<N, N>>(
identifier: N | undefined,
callback?: C,
beginRoot?: N | undefined,
iterationType?: IterationType
): N | undefined;
getNode<C extends BTNCallback<N>>(
identifier: ReturnType<C>,
callback: C,
beginRoot?: N | undefined,
iterationType?: IterationType
): N | undefined;
/**

@@ -368,4 +340,4 @@ * Time Complexity: O(log n)

* the binary tree. It is used to determine if a node matches the given identifier. The `callback`
* function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is the starting point for
* function should take a single parameter of type `NODE` (the type of the nodes in the binary tree) and
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is the starting point for
* searching for a node in a binary tree. It can be either a key value or a node object. If it is not

@@ -376,10 +348,10 @@ * provided, the search will start from the root of the binary tree.

* `getNodes` method, which is called within the `getNode` method.
* @returns a value of type `N`, `null`, or `undefined`.
* @returns a value of type `NODE`, `null`, or `undefined`.
*/
getNode<C extends BTNCallback<N>>(
getNode<C extends BTNCallback<NODE>>(
identifier: ReturnType<C> | undefined,
callback: C = this._defaultOneParamCallback as C,
beginRoot: BSTNKeyOrNode<K, N> = this.root,
beginRoot: BSTNKeyOrNode<K, NODE> = this.root,
iterationType = this.iterationType
): N | null | undefined {
): NODE | null | undefined {
if ((identifier as any) instanceof RedBlackTreeNode) callback = (node => node) as C;

@@ -391,2 +363,12 @@ beginRoot = this.ensureNode(beginRoot);

/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
override clear() {
this._root = this.Sentinel;
this._size = 0;
}
/**
* Time Complexity: O(log n)

@@ -405,3 +387,3 @@ * Space Complexity: O(1)

*/
override getPredecessor(x: N): N {
override getPredecessor(x: NODE): NODE {
if (this.isRealNode(x.left)) {

@@ -411,3 +393,3 @@ return this.getRightMost(x.left)!;

let y: N | undefined = x.parent;
let y: NODE | undefined = x.parent;
while (this.isRealNode(y) && x === y.left) {

@@ -421,13 +403,3 @@ x = y!;

/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
override clear() {
this._root = this.Sentinel;
this._size = 0;
}
protected override _setRoot(v: N) {
protected override _setRoot(v: NODE) {
if (v) {

@@ -449,7 +421,7 @@ v.parent = undefined;

* The function performs a left rotation on a binary tree node.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `N`, which likely represents a node in a binary tree.
* @param {RedBlackTreeNode} x - The parameter `x` is of type `NODE`, which likely represents a node in a binary tree.
*/
protected _leftRotate(x: N): void {
protected _leftRotate(x: NODE): void {
if (x.right) {
const y: N = x.right;
const y: NODE = x.right;
x.right = y.left;

@@ -485,5 +457,5 @@ if (y.left !== this.Sentinel) {

*/
protected _rightRotate(x: N): void {
protected _rightRotate(x: NODE): void {
if (x.left) {
const y: N = x.left;
const y: NODE = x.left;
x.left = y.right;

@@ -515,7 +487,66 @@ if (y.right !== this.Sentinel) {

*
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
* @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
* red-black tree.
*/
protected _fixInsert(k: NODE): void {
let u: NODE | undefined;
while (k.parent && k.parent.color === 1) {
if (k.parent.parent && k.parent === k.parent.parent.right) {
u = k.parent.parent.left;
if (u && u.color === 1) {
u.color = RBTNColor.BLACK;
k.parent.color = RBTNColor.BLACK;
k.parent.parent.color = RBTNColor.RED;
k = k.parent.parent;
} else {
if (k === k.parent.left) {
k = k.parent;
this._rightRotate(k);
}
k.parent!.color = RBTNColor.BLACK;
k.parent!.parent!.color = RBTNColor.RED;
this._leftRotate(k.parent!.parent!);
}
} else {
u = k.parent.parent!.right;
if (u && u.color === 1) {
u.color = RBTNColor.BLACK;
k.parent.color = RBTNColor.BLACK;
k.parent.parent!.color = RBTNColor.RED;
k = k.parent.parent!;
} else {
if (k === k.parent.right) {
k = k.parent;
this._leftRotate(k);
}
k.parent!.color = RBTNColor.BLACK;
k.parent!.parent!.color = RBTNColor.RED;
this._rightRotate(k.parent!.parent!);
}
}
if (k === this.root) {
break;
}
}
this.root.color = RBTNColor.BLACK;
}
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function `_fixDelete` is used to fix the red-black tree after a node deletion.
* @param {RedBlackTreeNode} x - The parameter `x` represents a node in a Red-Black Tree (RBT).
*/
protected _fixDelete(x: N): void {
let s: N | undefined;
protected _fixDelete(x: NODE): void {
let s: NODE | undefined;
while (x !== this.root && x.color === RBTNColor.BLACK) {

@@ -592,3 +623,3 @@ if (x.parent && x === x.parent.left) {

*/
protected _rbTransplant(u: N, v: N): void {
protected _rbTransplant(u: NODE, v: NODE): void {
if (u.parent === undefined) {

@@ -605,65 +636,6 @@ this._setRoot(v);

/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
* @param {RedBlackTreeNode} k - The parameter `k` is a RedBlackTreeNode object, which represents a node in a
* red-black tree.
*/
protected _fixInsert(k: N): void {
let u: N | undefined;
while (k.parent && k.parent.color === 1) {
if (k.parent.parent && k.parent === k.parent.parent.right) {
u = k.parent.parent.left;
if (u && u.color === 1) {
u.color = RBTNColor.BLACK;
k.parent.color = RBTNColor.BLACK;
k.parent.parent.color = RBTNColor.RED;
k = k.parent.parent;
} else {
if (k === k.parent.left) {
k = k.parent;
this._rightRotate(k);
}
k.parent!.color = RBTNColor.BLACK;
k.parent!.parent!.color = RBTNColor.RED;
this._leftRotate(k.parent!.parent!);
}
} else {
u = k.parent.parent!.right;
if (u && u.color === 1) {
u.color = RBTNColor.BLACK;
k.parent.color = RBTNColor.BLACK;
k.parent.parent!.color = RBTNColor.RED;
k = k.parent.parent!;
} else {
if (k === k.parent.right) {
k = k.parent;
this._leftRotate(k);
}
k.parent!.color = RBTNColor.BLACK;
k.parent!.parent!.color = RBTNColor.RED;
this._rightRotate(k.parent!.parent!);
}
}
if (k === this.root) {
break;
}
}
this.root.color = RBTNColor.BLACK;
}
/**
* The function replaces an old node with a new node while preserving the color of the old node.
* @param {N} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
* data structure. It is of type `N`, which is the type of the nodes in the data structure.
* @param {N} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
* data structure. It is of type `NODE`, which is the type of the nodes in the data structure.
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
* data structure.

@@ -673,3 +645,3 @@ * @returns The method is returning the result of calling the `_replaceNode` method from the

*/
protected _replaceNode(oldNode: N, newNode: N): N {
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
newNode.color = oldNode.color;

@@ -676,0 +648,0 @@

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

V = any,
N extends TreeMultimapNode<K, V, N> = TreeMultimapNodeNested<K, V>
> extends AVLTreeNode<K, V, N> {
NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNodeNested<K, V>
> extends AVLTreeNode<K, V, NODE> {
count: number;

@@ -51,8 +51,8 @@

V = any,
N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>,
TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>
NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>,
TREE extends TreeMultimap<K, V, NODE, TREE> = TreeMultimap<K, V, NODE, TreeMultimapNested<K, V, NODE>>
>
extends AVLTree<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE> {
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: TreeMultimapOptions<K>) {
extends AVLTree<K, V, NODE, TREE>
implements IBinaryTree<K, V, NODE, TREE> {
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: TreeMultimapOptions<K>) {
super([], options);

@@ -75,3 +75,3 @@ if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);

* distinguish one node from another in the tree.
* @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
* @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of

@@ -81,8 +81,8 @@ * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.

*/
override createNode(key: K, value?: V, count?: number): N {
return new TreeMultimapNode(key, value, count) as N;
override createNode(key: K, value?: V, count?: number): NODE {
return new TreeMultimapNode(key, value, count) as NODE;
}
override createTree(options?: TreeMultimapOptions<K>): TREE {
return new TreeMultimap<K, V, N, TREE>([], {
return new TreeMultimap<K, V, NODE, TREE>([], {
iterationType: this.iterationType,

@@ -95,4 +95,4 @@ variant: this.variant,

/**
* The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
* can be one of the following:

@@ -104,6 +104,10 @@ * @param {V} [value] - The `value` parameter is an optional argument that represents the value

* times the value should be added to the node. If not provided, it defaults to 1.
* @returns a node of type `N` or `undefined`.
* @returns a node of type `NODE` or `undefined`.
*/
override exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count = 1): N | undefined {
let node: N | undefined;
override keyValueOrEntryToNode(
keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>,
value?: V,
count = 1
): NODE | undefined {
let node: NODE | undefined;
if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {

@@ -130,7 +134,7 @@ return;

* The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
* class.
*/
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
return keyOrNodeOrEntry instanceof TreeMultimapNode;

@@ -142,3 +146,2 @@ }

* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
*/

@@ -162,4 +165,4 @@

*/
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count = 1): boolean {
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
if (newNode === undefined) return false;

@@ -176,86 +179,10 @@

/**
* Time Complexity: O(k log n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(k log n)
* Time Complexity: O(log n)
* Space Complexity: O(1)
*
* The function overrides the addMany method to add multiple keys, nodes, or entries to a data
* structure.
* @param keysOrNodesOrEntries - The parameter `keysOrNodesOrEntries` is an iterable that can contain
* either keys, nodes, or entries.
* @returns The method is returning an array of type `N | undefined`.
*/
override addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>): boolean[] {
return super.addMany(keysOrNodesOrEntries);
}
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
* tree using either a recursive or iterative approach.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when building the balanced binary search tree. It can have two possible
* values:
* @returns a boolean value.
*/
override perfectlyBalance(iterationType = this.iterationType): boolean {
const sorted = this.dfs(node => node, 'in'),
n = sorted.length;
if (sorted.length < 1) return false;
this.clear();
if (iterationType === IterationType.RECURSIVE) {
const buildBalanceBST = (l: number, r: number) => {
if (l > r) return;
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
buildBalanceBST(l, m - 1);
buildBalanceBST(m + 1, r);
};
buildBalanceBST(0, n - 1);
return true;
} else {
const stack: [[number, number]] = [[0, n - 1]];
while (stack.length > 0) {
const popped = stack.pop();
if (popped) {
const [l, r] = popped;
if (l <= r) {
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
stack.push([m + 1, r]);
stack.push([l, m - 1]);
}
}
}
return true;
}
}
/**
* Time Complexity: O(k log n)
* Space Complexity: O(1)
* logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
*/
/**
* Time Complexity: O(k log n)
* Space Complexity: O(1)
*
* The `delete` function in TypeScript is used to remove a node from a binary tree, taking into

@@ -274,18 +201,18 @@ * account the count of the node and balancing the tree if necessary.

* decremented by 1 and
* @returns an array of `BinaryTreeDeleteResult<N>`.
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
*/
override delete<C extends BTNCallback<N>>(
override delete<C extends BTNCallback<NODE>>(
identifier: ReturnType<C>,
callback: C = this._defaultOneParamCallback as C,
ignoreCount = false
): BinaryTreeDeleteResult<N>[] {
const deletedResult: BinaryTreeDeleteResult<N>[] = [];
): BinaryTreeDeleteResult<NODE>[] {
const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
if (!this.root) return deletedResult;
const curr: N | undefined = this.getNode(identifier, callback) ?? undefined;
const curr: NODE | undefined = this.getNode(identifier, callback) ?? undefined;
if (!curr) return deletedResult;
const parent: N | undefined = curr?.parent ? curr.parent : undefined;
let needBalanced: N | undefined = undefined,
orgCurrent: N | undefined = curr;
const parent: NODE | undefined = curr?.parent ? curr.parent : undefined;
let needBalanced: NODE | undefined = undefined,
orgCurrent: NODE | undefined = curr;

@@ -354,2 +281,56 @@ if (curr.count > 1 && !ignoreCount) {

/**
* Time Complexity: O(n log n)
* Space Complexity: O(log n)
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(log n)
*
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
* tree using either a recursive or iterative approach.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when building the balanced binary search tree. It can have two possible
* values:
* @returns a boolean value.
*/
override perfectlyBalance(iterationType = this.iterationType): boolean {
const sorted = this.dfs(node => node, 'in'),
n = sorted.length;
if (sorted.length < 1) return false;
this.clear();
if (iterationType === IterationType.RECURSIVE) {
const buildBalanceBST = (l: number, r: number) => {
if (l > r) return;
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
buildBalanceBST(l, m - 1);
buildBalanceBST(m + 1, r);
};
buildBalanceBST(0, n - 1);
return true;
} else {
const stack: [[number, number]] = [[0, n - 1]];
while (stack.length > 0) {
const popped = stack.pop();
if (popped) {
const [l, r] = popped;
if (l <= r) {
const m = l + Math.floor((r - l) / 2);
const midNode = sorted[m];
this.add(midNode.key, midNode.value, midNode.count);
stack.push([m + 1, r]);
stack.push([l, m - 1]);
}
}
}
return true;
}
}
/**
* Time complexity: O(n)

@@ -374,5 +355,5 @@ * Space complexity: O(n)

* The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
* which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
* which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
* node where the values from the source node will be swapped to.

@@ -382,3 +363,6 @@ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`

*/
protected override _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined {
protected override _swapProperties(
srcNode: BSTNKeyOrNode<K, NODE>,
destNode: BSTNKeyOrNode<K, NODE>
): NODE | undefined {
srcNode = this.ensureNode(srcNode);

@@ -408,3 +392,3 @@ destNode = this.ensureNode(destNode);

protected _replaceNode(oldNode: N, newNode: N): N {
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
newNode.count = oldNode.count + newNode.count;

@@ -411,0 +395,0 @@ return super._replaceNode(oldNode, newNode);

@@ -81,2 +81,6 @@ /**

set vertexMap(v: Map<VertexKey, VO>) {
this._vertexMap = v;
}
/**

@@ -83,0 +87,0 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

@@ -69,2 +69,6 @@ /**

set outEdgeMap(v: Map<VO, EO[]>) {
this._outEdgeMap = v;
}
protected _inEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();

@@ -76,2 +80,6 @@

set inEdgeMap(v: Map<VO, EO[]>) {
this._inEdgeMap = v;
}
/**

@@ -605,2 +613,24 @@ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.

/**
* The isEmpty function checks if the graph is empty.
*
* @return A boolean value
*/
isEmpty(): boolean {
return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
}
/**
* The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
*
* @return A new instance of the directedgraph class
*/
clone(): DirectedGraph<V, E, VO, EO> {
const cloned = new DirectedGraph<V, E, VO, EO>();
cloned.vertexMap = new Map<VertexKey, VO>(this.vertexMap);
cloned.inEdgeMap = new Map<VO, EO[]>(this.inEdgeMap);
cloned.outEdgeMap = new Map<VO, EO[]>(this.outEdgeMap);
return cloned;
}
/**
* Time Complexity: O(1)

@@ -607,0 +637,0 @@ * Space Complexity: O(1)

@@ -111,2 +111,17 @@ import type { MapGraphCoordinate, VertexKey } from '../../types';

}
/**
* The override function is used to override the default behavior of a function.
* In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
* The clone() function returns a new graph that is an exact copy of the original graph.
*
* @return A mapgraph&lt;v, e, vo, eo&gt;
*/
override clone(): MapGraph<V, E, VO, EO> {
const cloned = new MapGraph<V, E, VO, EO>(this.originCoord, this.bottomRight);
cloned.vertexMap = new Map<VertexKey, VO>(this.vertexMap);
cloned.inEdgeMap = new Map<VO, EO[]>(this.inEdgeMap);
cloned.outEdgeMap = new Map<VO, EO[]>(this.outEdgeMap);
return cloned;
}
}

@@ -67,2 +67,6 @@ /**

set edgeMap(v: Map<VO, EO[]>) {
this._edgeMap = v;
}
/**

@@ -370,2 +374,26 @@ * The function creates a new vertex with an optional value and returns it.

/**
* The isEmpty function checks if the graph is empty.
* @return True if the graph is empty and false otherwise
*/
isEmpty(): boolean {
return this.vertexMap.size === 0 && this.edgeMap.size === 0;
}
/**
* The clone function creates a new UndirectedGraph object and copies the
* vertexMap and edgeMap from this graph to the new one. This is done by
* assigning each of these properties to their respective counterparts in the
* cloned graph. The clone function returns a reference to this newly created,
* cloned UndirectedGraph object.
*
* @return A new instance of the undirectedgraph class
*/
clone(): UndirectedGraph<V, E, VO, EO> {
const cloned = new UndirectedGraph<V, E, VO, EO>();
cloned.vertexMap = new Map<VertexKey, VO>(this.vertexMap);
cloned.edgeMap = new Map<VO, EO[]>(this.edgeMap);
return cloned;
}
/**
* Time Complexity: O(1)

@@ -372,0 +400,0 @@ * Space Complexity: O(1)

@@ -35,3 +35,3 @@ /**

*/
constructor(rawCollection: Iterable<R> = [], options?: HashMapOptions<K, V, R>) {
constructor(rawCollection: Iterable<R | [K, V]> = [], options?: HashMapOptions<K, V, R>) {
super();

@@ -63,2 +63,6 @@ if (options) {

/**
* The function returns the value of the _toEntryFn property.
* @returns The function being returned is `this._toEntryFn`.
*/
get toEntryFn() {

@@ -68,4 +72,18 @@ return this._toEntryFn;

/**
* The hasFn function is a function that takes in an item and returns a boolean
* indicating whether the item is contained within the hash table.
*
* @return The hash function
*/
get hasFn() {
return this._hashFn;
}
protected _size = 0;
/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number {

@@ -75,2 +93,8 @@ return this._size;

/**
* The function checks if a given element is an array with exactly two elements.
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
* data type.
* @returns a boolean value.
*/
isEntry(rawElement: any): rawElement is [K, V] {

@@ -80,2 +104,6 @@ return Array.isArray(rawElement) && rawElement.length === 2;

/**
* The function checks if the size of an object is equal to zero and returns a boolean value.
* @returns A boolean value indicating whether the size of the object is 0 or not.
*/
isEmpty(): boolean {

@@ -85,2 +113,6 @@ return this.size === 0;

/**
* The clear() function resets the state of an object by clearing its internal store, object map, and
* size.
*/
clear() {

@@ -124,6 +156,14 @@ this._store = {};

*/
setMany(rawCollection: Iterable<R>): boolean[] {
setMany(rawCollection: Iterable<R | [K, V]>): boolean[] {
const results: boolean[] = [];
for (const rawEle of rawCollection) {
const [key, value] = this.toEntryFn(rawEle);
let key, value;
if (this.isEntry(rawEle)) {
key = rawEle[0];
value = rawEle[1];
} else {
const item = this.toEntryFn(rawEle);
key = item[0];
value = item[1];
}
results.push(this.set(key, value));

@@ -142,3 +182,3 @@ }

*/
get(key: K): V | undefined {
override get(key: K): V | undefined {
if (this._isObjKey(key)) {

@@ -158,3 +198,3 @@ return this._objMap.get(key);

*/
has(key: K): boolean {
override has(key: K): boolean {
if (this._isObjKey(key)) {

@@ -194,2 +234,13 @@ return this._objMap.has(key);

/**
* The clone function creates a new HashMap with the same key-value pairs as
* this one. The clone function is useful for creating a copy of an existing
* HashMap, and then modifying that copy without affecting the original.
*
* @return A new hashmap with the same values as this one
*/
clone(): HashMap<K, V, R> {
return new HashMap<K, V, R>(this, { hashFn: this._hashFn, toEntryFn: this.toEntryFn });
}
/**
* Time Complexity: O(n)

@@ -254,2 +305,10 @@ * Space Complexity: O(n)

/**
* The put function sets a value in a data structure using a specified key.
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
* to the function.
* @param {V} value - The value parameter represents the value that you want to associate with the
* specified key in the data structure.
* @returns The method is returning a boolean value.
*/
put(key: K, value: V): boolean {

@@ -302,3 +361,3 @@ return this.set(key, value);

*/
export class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>> = {};

@@ -310,3 +369,12 @@ protected _objMap = new WeakMap<object, HashMapLinkedNode<K, V | undefined>>();

constructor(entries?: Iterable<[K, V]>, options?: LinkedHashMapOptions<K>) {
/**
* The constructor initializes a LinkedHashMap object with an optional raw collection and options.
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
* used to initialize the HashMapLinked instance with key-value pairs. Each element in the
* `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
* then added to the HashMap
* @param [options] - The `options` parameter is an optional object that can contain the following
* properties:
*/
constructor(rawCollection: Iterable<R> = [], options?: LinkedHashMapOptions<K, V, R>) {
super();

@@ -317,10 +385,15 @@ this._sentinel = <HashMapLinkedNode<K, V>>{};

if (options) {
const { hashFn, objHashFn } = options;
const { hashFn, objHashFn, toEntryFn } = options;
if (hashFn) this._hashFn = hashFn;
if (objHashFn) this._objHashFn = objHashFn;
if (toEntryFn) {
this._toEntryFn = toEntryFn;
}
}
if (entries) {
for (const el of entries) {
this.set(el[0], el[1]);
if (rawCollection) {
for (const el of rawCollection) {
const [key, value] = this.toEntryFn(el);
this.set(key, value);
}

@@ -330,4 +403,27 @@ }

protected _toEntryFn: (rawElement: R) => [K, V] = (rawElement: R) => {
if (this.isEntry(rawElement)) {
// TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
return rawElement;
} else {
throw new Error(
"If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
);
}
};
/**
* The function returns the value of the _toEntryFn property.
* @returns The function being returned is `this._toEntryFn`.
*/
get toEntryFn() {
return this._toEntryFn;
}
protected _size = 0;
/**
* The function returns the size of an object.
* @returns The size of the object.
*/
get size() {

@@ -443,3 +539,26 @@ return this._size;

has(key: K): boolean {
/**
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
* using a provided function, and sets each key-value pair in the current object, returning an array
* of booleans indicating the success of each set operation.
* @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
* R.
* @returns The `setMany` function returns an array of booleans.
*/
setMany(rawCollection: Iterable<R>): boolean[] {
const results: boolean[] = [];
for (const rawEle of rawCollection) {
const [key, value] = this.toEntryFn(rawEle);
results.push(this.set(key, value));
}
return results;
}
/**
* The function checks if a given key exists in a map, using different logic depending on whether the
* key is a weak key or not.
* @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
* @returns The method `has` is returning a boolean value.
*/
override has(key: K): boolean {
if (isWeakKey(key)) {

@@ -454,11 +573,2 @@ const hash = this._objHashFn(key);

setMany(entries: Iterable<[K, V]>): boolean[] {
const results: boolean[] = [];
for (const entry of entries) {
const [key, value] = entry;
results.push(this.set(key, value));
}
return results;
}
/**

@@ -477,3 +587,3 @@ * Time Complexity: O(1)

*/
get(key: K): V | undefined {
override get(key: K): V | undefined {
if (isWeakKey(key)) {

@@ -494,10 +604,10 @@ const hash = this._objHashFn(key);

*
* The function `getAt` retrieves the key-value pair at a specified index in a linked list.
* The function `at` retrieves the key-value pair at a specified index in a linked list.
* @param {number} index - The index parameter is a number that represents the position of the
* element we want to retrieve from the data structure.
* @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
* @returns The method `at(index: number)` is returning an array containing the key-value pair at
* the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
* where `K` is the key and `V` is the value.
*/
getAt(index: number): V | undefined {
at(index: number): V | undefined {
rangeCheck(index, 0, this._size - 1);

@@ -554,3 +664,3 @@ let node = this._head;

/**
* Time Complexity: O(n), where n is the index.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -585,2 +695,12 @@ *

/**
* The function checks if a given element is an array with exactly two elements.
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
* data type.
* @returns a boolean value.
*/
isEntry(rawElement: any): rawElement is [K, V] {
return Array.isArray(rawElement) && rawElement.length === 2;
}
/**
* Time Complexity: O(1)

@@ -597,2 +717,16 @@ * Space Complexity: O(1)

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
* the original.
* @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
* of the original `LinkedHashMap` object.
*/
clone(): LinkedHashMap<K, V> {

@@ -663,6 +797,17 @@ const cloned = new LinkedHashMap<K, V>([], { hashFn: this._hashFn, objHashFn: this._objHashFn });

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* The put function sets a value in a data structure using a specified key.
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
* to the function.
* @param {V} value - The value parameter represents the value that you want to associate with the
* specified key in the data structure.
* @returns The method is returning a boolean value.
*/
put(key: K, value: V): boolean {

@@ -672,7 +817,2 @@ return this.set(key, value);

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
protected _hashFn: (key: K) => string = (key: K) => String(key);

@@ -683,4 +823,5 @@

/**
* Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
* Time Complexity: O(n)
* Space Complexity: O(1)
* where n is the number of entries in the LinkedHashMap.
*

@@ -687,0 +828,0 @@ * The above function is an iterator that yields key-value pairs from a linked list.

@@ -24,2 +24,12 @@ /**

export class Heap<E = any> extends IterableElementBase<E> {
/**
* The constructor initializes a heap data structure with optional elements and options.
* @param elements - The `elements` parameter is an iterable object that contains the initial
* elements to be added to the heap. It is an optional parameter and if not provided, the heap will
* be initialized as empty.
* @param [options] - The `options` parameter is an optional object that can contain additional
* configuration options for the heap. In this case, it is used to specify a custom comparator
* function for comparing elements in the heap. The comparator function is used to determine the
* order of elements in the heap.
*/
constructor(elements: Iterable<E> = [], options?: HeapOptions<E>) {

@@ -49,2 +59,6 @@ super();

/**
* The function returns the value of the _comparator property.
* @returns The `_comparator` property is being returned.
*/
get comparator() {

@@ -56,2 +70,6 @@ return this._comparator;

/**
* The function returns an array of elements.
* @returns The elements array is being returned.
*/
get elements(): E[] {

@@ -87,8 +105,9 @@ return this._elements;

/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)
* where n is the number of elements in the heap.
*/
/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)

@@ -105,8 +124,9 @@ *

/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)
* where n is the number of elements in the heap.
*/
/**
* Time Complexity: O(log n), where n is the number of elements in the heap.
* Time Complexity: O(log n)
* Space Complexity: O(1)

@@ -129,2 +149,5 @@ *

/**
* Time Complexity: O(1)
* Space Complexity: O(1)
*
* Peek at the top element of the heap without removing it.

@@ -400,2 +423,5 @@ * @returns The top element or undefined if the heap is empty.

/**
* The function `_getIterator` returns an iterable iterator for the elements in the class.
*/
protected* _getIterator(): IterableIterator<E> {

@@ -468,2 +494,12 @@ for (const element of this.elements) {

/**
* The constructor function initializes an object with an element and a degree, and sets the marked
* property to false.
* @param {E} element - The "element" parameter represents the value or data that will be stored in
* the node of a data structure. It can be any type of data, such as a number, string, object, or
* even another data structure.
* @param [degree=0] - The degree parameter represents the degree of the element in a data structure
* called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
* degree is set to 0 when a new node is created.
*/
constructor(element: E, degree = 0) {

@@ -477,2 +513,9 @@ this.element = element;

export class FibonacciHeap<E> {
/**
* The constructor function initializes a FibonacciHeap object with an optional comparator function.
* @param [comparator] - The `comparator` parameter is an optional argument that represents a
* function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
* will be used to determine the order of elements in the heap. If no comparator function is
* provided, a default comparator function will be used.
*/
constructor(comparator?: Comparator<E>) {

@@ -489,2 +532,6 @@ this.clear();

/**
* The function returns the root node of a Fibonacci heap.
* @returns The method is returning either a FibonacciHeapNode object or undefined.
*/
get root(): FibonacciHeapNode<E> | undefined {

@@ -496,2 +543,6 @@ return this._root;

/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number {

@@ -503,2 +554,7 @@ return this._size;

/**
* The function returns the minimum node in a Fibonacci heap.
* @returns The method is returning the minimum node of the Fibonacci heap, which is of type
* `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
*/
get min(): FibonacciHeapNode<E> | undefined {

@@ -510,2 +566,6 @@ return this._min;

/**
* The function returns the comparator used for comparing elements.
* @returns The `_comparator` property of the object.
*/
get comparator(): Comparator<E> {

@@ -824,3 +884,3 @@ return this._comparator;

/**
* Time Complexity: O(n log n), where n is the number of elements in the heap.
* Time Complexity: O(n log n)
* Space Complexity: O(n)

@@ -830,3 +890,3 @@ */

/**
* Time Complexity: O(n log n), where n is the number of elements in the heap.
* Time Complexity: O(n log n)
* Space Complexity: O(n)

@@ -833,0 +893,0 @@ *

@@ -36,3 +36,6 @@ /**

/**
* The constructor initializes the linked list with an empty head, tail, and size.
* The constructor initializes a linked list with optional elements.
* @param elements - The `elements` parameter is an optional iterable object that contains the
* initial elements to be added to the data structure. It defaults to an empty array if no elements
* are provided.
*/

@@ -53,2 +56,6 @@ constructor(elements: Iterable<E> = []) {

/**
* The `head` function returns the first node of a doubly linked list.
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
*/
get head(): DoublyLinkedListNode<E> | undefined {

@@ -60,2 +67,7 @@ return this._head;

/**
* The `tail` function returns the last node of a doubly linked list.
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
* `undefined`.
*/
get tail(): DoublyLinkedListNode<E> | undefined {

@@ -67,2 +79,6 @@ return this._tail;

/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number {

@@ -73,8 +89,9 @@ return this._size;

/**
* Time Complexity: O(n), where n is the size of the input array.
* Time Complexity: O(n)
* Space Complexity: O(n)
* where n is the number of elements in the linked list.
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -95,3 +112,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -121,7 +138,3 @@ *

static fromArray<E>(data: E[]) {
const doublyLinkedList = new DoublyLinkedList<E>();
for (const item of data) {
doublyLinkedList.push(item);
}
return doublyLinkedList;
return new DoublyLinkedList<E>(data);
}

@@ -183,3 +196,3 @@

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -211,3 +224,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -239,3 +252,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -245,6 +258,6 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
* @param {number} index - The index parameter is a number that represents the position of the element we want to

@@ -255,3 +268,3 @@ * retrieve from the list.

*/
getAt(index: number): E | undefined {
at(index: number): E | undefined {
if (index < 0 || index >= this.size) return undefined;

@@ -266,3 +279,3 @@ let current = this.head;

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -272,3 +285,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -293,3 +306,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -299,3 +312,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -323,3 +336,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -329,3 +342,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -364,8 +377,9 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
* where n is the number of elements in the linked list.
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -410,3 +424,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -416,3 +430,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -456,3 +470,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -487,3 +501,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -524,3 +538,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(1)
* Space Complexity: O(1)

@@ -538,3 +552,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(1)
* Space Complexity: O(1)

@@ -553,3 +567,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -559,31 +573,5 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback: (value: E) => boolean): E | undefined {
let current = this.head;
while (current) {
if (callback(current.value)) {
return current.value;
}
current = current.next;
}
return undefined;
}
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Space Complexity: O(1)
*
* The function returns the index of the first occurrence of a given value in a linked list.

@@ -609,3 +597,3 @@ * @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -615,3 +603,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -638,3 +626,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -644,3 +632,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -667,3 +655,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -685,3 +673,3 @@ *

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -691,3 +679,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(n)

@@ -709,2 +697,20 @@ *

/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
* as the original list.
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
* is a copy of the original list.
*/
clone(): DoublyLinkedList<E> {
return new DoublyLinkedList(this.values());
}
/**
* Time Complexity: O(1)

@@ -810,3 +816,3 @@ * Space Complexity: O(1)

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -828,3 +834,3 @@ */

/**
* Time Complexity: O(n), where n is the number of elements in the linked list.
* Time Complexity: O(n)
* Space Complexity: O(1)

@@ -831,0 +837,0 @@ */

@@ -28,3 +28,6 @@ /**

/**
* The constructor initializes the linked list with an empty head, tail, and length.
* The constructor initializes a new instance of a class with an optional iterable of elements.
* @param elements - The `elements` parameter is an optional iterable object that contains the
* initial elements to be added to the instance of the class. If no `elements` are provided, an empty
* array will be used as the default value.
*/

@@ -40,2 +43,6 @@ constructor(elements: Iterable<E> = []) {

/**
* The `head` function returns the first node of a singly linked list.
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
*/
get head(): SinglyLinkedListNode<E> | undefined {

@@ -47,2 +54,6 @@ return this._head;

/**
* The `tail` function returns the last node of a singly linked list.
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
*/
get tail(): SinglyLinkedListNode<E> | undefined {

@@ -54,2 +65,6 @@ return this._tail;

/**
* The function returns the size of an object.
* @returns The size of the object, which is a number.
*/
get size(): number {

@@ -60,9 +75,11 @@ return this._size;

/**
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
* Time Complexity: O(n)
* Space Complexity: O(n)
* Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Linear space, as it creates a new node for each element in the array.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -83,9 +100,11 @@ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given

/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
* Constant time, as it involves basic pointer adjustments.
* Constant space, as it only creates a new node.
*/
/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -110,9 +129,9 @@ * The `push` function adds a new node with the given value to the end of a singly linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
* Space Complexity: O(1) - Constant space, as it only creates a new node.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -128,9 +147,10 @@ * The `push` function adds a new node with the given value to the end of a singly linked list.

/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
* Linear time in the worst case, as it may need to traverse the list to find the last element.
*/
/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -164,9 +184,9 @@ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail

/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -183,9 +203,9 @@ * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -204,9 +224,9 @@ * The `shift()` function removes and returns the value of the first node in a linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -221,9 +241,9 @@ * The `pollFirst()` function removes and returns the value of the first node in a linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -248,9 +268,9 @@ * The unshift function adds a new node with the given value to the beginning of a singly linked list.

/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -266,17 +286,18 @@ * The addFirst function adds a new node with the given value to the beginning of a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
* Linear time, where n is the index, as it may need to traverse the list to find the desired node.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
* The function `at` returns the value at a specified index in a linked list, or undefined if the index is out of range.
* @param {number} index - The index parameter is a number that represents the position of the element we want to
* retrieve from the list.
* @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
* @returns The method `at(index: number): E | undefined` returns the value at the specified index in the linked list, or
* `undefined` if the index is out of bounds.
*/
getAt(index: number): E | undefined {
at(index: number): E | undefined {
if (index < 0 || index >= this.size) return undefined;

@@ -291,9 +312,9 @@ let current = this.head;

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -315,9 +336,9 @@ * The function `getNodeAt` returns the node at a given index in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -349,9 +370,9 @@ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -399,9 +420,9 @@ * The delete function removes a node with a specific value from a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -454,9 +475,11 @@ * The `addAt` function inserts a value at a specified index in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
* Time Complexity: O(n)
* Space Complexity: O(n)
* Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Linear space, as it creates an array with the same length as the list.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -477,9 +500,9 @@ * The `toArray` function converts a linked list into an array.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -508,36 +531,10 @@ * The `reverse` function reverses the order of the nodes in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback: (value: E) => boolean): E | undefined {
let current = this.head;
while (current) {
if (callback(current.value)) {
return current.value;
}
current = current.next;
}
return undefined;
}
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
*
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.

@@ -564,9 +561,9 @@ * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -593,9 +590,9 @@ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -639,9 +636,9 @@ * The `addBefore` function inserts a new value before an existing value in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -679,9 +676,9 @@ * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.

/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
* Space Complexity: O(1) - Constant space.
* Time Complexity: O(n)
* Space Complexity: O(1)
*

@@ -715,2 +712,20 @@ * The function counts the number of occurrences of a given value in a linked list.

*
* The `clone` function returns a new instance of the `SinglyLinkedList` class with the same values
* as the original list.
* @returns The `clone()` method is returning a new instance of the `SinglyLinkedList` class, which
* is a clone of the original list.
*/
clone(): SinglyLinkedList<E> {
return new SinglyLinkedList<E>(this.values());
}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function creates a new SinglyLinkedList by iterating over the elements of the current

@@ -770,2 +785,5 @@ * list and applying a callback function to each element to determine if it should be included in the

/**
* The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
*/
protected* _getIterator(): IterableIterator<E> {

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

@@ -23,2 +23,10 @@ /**

export class SkipList<K, V> {
/**
* The constructor function initializes a SkipLinkedList object with optional options and elements.
* @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
* is used to initialize the SkipLinkedList with the given key-value pairs. If no elements are
* provided, the SkipLinkedList will be empty.
* @param {SkipLinkedListOptions} [options] - The `options` parameter is an optional object that can
* contain two properties:
*/
constructor(elements: Iterable<[K, V]> = [], options?: SkipLinkedListOptions) {

@@ -38,2 +46,6 @@ if (options) {

/**
* The function returns the head node of a SkipList.
* @returns The method is returning a SkipListNode object with generic key type K and value type V.
*/
get head(): SkipListNode<K, V> {

@@ -45,2 +57,6 @@ return this._head;

/**
* The function returns the value of the private variable _level.
* @returns The level property of the object.
*/
get level(): number {

@@ -52,2 +68,6 @@ return this._level;

/**
* The function returns the maximum level.
* @returns The value of the variable `_maxLevel` is being returned.
*/
get maxLevel(): number {

@@ -59,2 +79,6 @@ return this._maxLevel;

/**
* The function returns the probability value.
* @returns The probability value stored in the private variable `_probability` is being returned.
*/
get probability(): number {

@@ -65,9 +89,9 @@ return this._probability;

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(1)
* Space Complexity: O(1)
*

@@ -83,9 +107,9 @@ * Get the value of the first element (the smallest element) in the Skip List.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -106,9 +130,9 @@ * Get the value of the last element (the largest element) in the Skip List.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -143,9 +167,9 @@ * The add function adds a new node with a given key and value to a Skip List data structure.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -175,11 +199,12 @@ * The function `get` retrieves the value associated with a given key from a skip list data structure.

/**
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* The function checks if a key exists in a data structure.
* @param {K} key - The parameter "key" is of type K, which represents the type of the key being
* checked.
* @returns a boolean value.
*/
has(key: K): boolean {

@@ -190,9 +215,9 @@ return this.get(key) !== undefined;

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -234,9 +259,9 @@ * The `delete` function removes a node with a specific key from a Skip List data structure.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -259,9 +284,9 @@ * Get the value of the first element in the Skip List that is greater than the given key.

/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
* Time Complexity: O(log n)
* Space Complexity: O(1)
*

@@ -289,9 +314,10 @@ * Get the value of the last element in the Skip List that is less than the given key.

/**
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
* Space Complexity: O(1) - constant space.
* Time Complexity: O(maxLevel)
* Space Complexity: O(1)
* where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
*/
/**
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
* Space Complexity: O(1) - constant space.
* Time Complexity: O(maxLevel)
* Space Complexity: O(1)
*

@@ -298,0 +324,0 @@ * The function "_randomLevel" generates a random level based on a given probability and maximum level.

@@ -45,2 +45,6 @@ /**

/**
* The function returns the number of rows.
* @returns The number of rows.
*/
get rows(): number {

@@ -52,2 +56,6 @@ return this._rows;

/**
* The function returns the value of the private variable _cols.
* @returns The number of columns.
*/
get cols(): number {

@@ -59,2 +67,6 @@ return this._cols;

/**
* The function returns a two-dimensional array of numbers.
* @returns The data property, which is a two-dimensional array of numbers.
*/
get data(): number[][] {

@@ -64,2 +76,6 @@ return this._data;

/**
* The above function returns the value of the _addFn property.
* @returns The value of the property `_addFn` is being returned.
*/
get addFn() {

@@ -69,2 +85,6 @@ return this._addFn;

/**
* The function returns the value of the _subtractFn property.
* @returns The `_subtractFn` property is being returned.
*/
get subtractFn() {

@@ -74,2 +94,6 @@ return this._subtractFn;

/**
* The function returns the value of the _multiplyFn property.
* @returns The `_multiplyFn` property is being returned.
*/
get multiplyFn() {

@@ -382,2 +406,30 @@ return this._multiplyFn;

/**
* The function checks if a given row and column index is valid within a specified range.
* @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
* matrix. It is a number that indicates the specific row in the matrix.
* @param {number} col - The "col" parameter represents the column index in a two-dimensional array
* or grid. It is used to check if the given column index is valid within the bounds of the grid.
* @returns A boolean value is being returned.
*/
isValidIndex(row: number, col: number): boolean {
return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
}
/**
* The `clone` function returns a new instance of the Matrix class with the same data and properties
* as the original instance.
* @returns The `clone()` method is returning a new instance of the `Matrix` class with the same data
* and properties as the current instance.
*/
clone(): Matrix {
return new Matrix(this.data, {
rows: this.rows,
cols: this.cols,
addFn: this.addFn,
subtractFn: this.subtractFn,
multiplyFn: this.multiplyFn
});
}
protected _addFn(a: number | undefined, b: number): number | undefined {

@@ -397,14 +449,2 @@ if (a === undefined) return b;

/**
* The function checks if a given row and column index is valid within a specified range.
* @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
* matrix. It is a number that indicates the specific row in the matrix.
* @param {number} col - The "col" parameter represents the column index in a two-dimensional array
* or grid. It is used to check if the given column index is valid within the bounds of the grid.
* @returns A boolean value is being returned.
*/
protected isValidIndex(row: number, col: number): boolean {
return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
}
/**
* The function `_swapRows` swaps the positions of two rows in an array.

@@ -411,0 +451,0 @@ * @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.

@@ -27,2 +27,13 @@ /**

/**
* The constructor initializes a Deque object with an optional iterable of elements and options.
* @param elements - An iterable object (such as an array or a Set) that contains the initial
* elements to be added to the deque. It can also be an object with a `length` or `size` property
* that represents the number of elements in the iterable object. If no elements are provided, an
* empty deque
* @param {DequeOptions} [options] - The `options` parameter is an optional object that can contain
* configuration options for the deque. In this code, it is used to set the `bucketSize` option,
* which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
* or is not a number
*/
constructor(elements: IterableWithSizeOrLength<E> = [], options?: DequeOptions) {

@@ -58,4 +69,18 @@ super();

/**
* The bucketSize function returns the size of the bucket.
*
* @return The size of the bucket
*/
get bucketSize() {
return this._bucketSize;
}
protected _buckets: E[][] = [];
/**
* The buckets function returns the buckets property of the object.
*
* @return The buckets property
*/
get buckets() {

@@ -67,2 +92,6 @@ return this._buckets;

/**
* The size function returns the number of items in the stack.
* @return The number of values in the set
*/
get size() {

@@ -82,2 +111,6 @@ return this._size;

/**
* The last function returns the last element in the queue.
* @return The last element in the array
*/
get last(): E | undefined {

@@ -242,3 +275,3 @@ if (this.size === 0) return;

while (index < this.size) {
yield this.getAt(index);
yield this.at(index);
index++;

@@ -255,3 +288,3 @@ }

while (index >= 0) {
yield this.getAt(index);
yield this.at(index);
index--;

@@ -270,3 +303,3 @@ }

*
* The `getAt` function retrieves an element at a specified position in an array-like data structure.
* The `at` function retrieves an element at a specified position in an array-like data structure.
* @param {number} pos - The `pos` parameter represents the position of the element that you want to

@@ -277,3 +310,3 @@ * retrieve from the data structure. It is of type `number` and should be a valid index within the

*/
getAt(pos: number): E {
at(pos: number): E {
rangeCheck(pos, 0, this.size - 1);

@@ -336,5 +369,5 @@ const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);

for (let i = pos; i < this.size; ++i) {
arr.push(this.getAt(i));
arr.push(this.at(i));
}
this.cut(pos - 1);
this.cut(pos - 1, true);
for (let i = 0; i < num; ++i) this.push(element);

@@ -359,16 +392,49 @@ for (let i = 0; i < arr.length; ++i) this.push(arr[i]);

* cut. It is a number that indicates the index of the character where the cut should be made.
* @param {boolean} isCutSelf - If true, the original deque will not be cut, and return a new deque
* @returns The method is returning the updated size of the data structure.
*/
cut(pos: number): number {
if (pos < 0) {
this.clear();
return 0;
cut(pos: number, isCutSelf = false): Deque<E> {
if (isCutSelf) {
if (pos < 0) {
this.clear();
return this;
}
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
this._bucketLast = bucketIndex;
this._lastInBucket = indexInBucket;
this._size = pos + 1;
return this;
} else {
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
for (let i = 0; i <= pos; i++) {
newDeque.push(this.at(i));
}
return newDeque;
}
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
this._bucketLast = bucketIndex;
this._lastInBucket = indexInBucket;
this._size = pos + 1;
return this.size;
}
cutRest(pos: number, isCutSelf = false): Deque<E> {
if (isCutSelf) {
if (pos < 0) {
this.clear();
return this;
}
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
this._bucketFirst = bucketIndex;
this._firstInBucket = indexInBucket;
this._size = this._size - pos;
return this;
} else {
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
for (let i = pos; i < this.size; i++) {
newDeque.push(this.at(i));
}
return newDeque;
}
}
/**

@@ -429,3 +495,3 @@ * Time Complexity: O(n)

while (i < size) {
const oldElement = this.getAt(i);
const oldElement = this.at(i);
if (oldElement !== element) {

@@ -437,3 +503,3 @@ this.setAt(index, oldElement!);

}
this.cut(index - 1);
this.cut(index - 1, true);
return true;

@@ -486,5 +552,5 @@ }

let index = 1;
let prev = this.getAt(0);
let prev = this.at(0);
for (let i = 1; i < this.size; ++i) {
const cur = this.getAt(i);
const cur = this.at(i);
if (cur !== prev) {

@@ -495,3 +561,3 @@ prev = cur;

}
this.cut(index - 1);
this.cut(index - 1, true);
return this;

@@ -518,3 +584,3 @@ }

for (let i = 0; i < this.size; ++i) {
arr.push(this.getAt(i));
arr.push(this.at(i));
}

@@ -572,28 +638,2 @@ arr.sort(comparator);

*
* The `find` function iterates over the elements in a deque and returns the first element for which
* the callback function returns true, or undefined if no such element is found.
* @param callback - A function that takes three parameters: element, index, and deque. It should
* return a boolean value indicating whether the element satisfies a certain condition.
* @returns The method `find` returns the first element in the deque that satisfies the condition
* specified by the callback function. If no element satisfies the condition, it returns `undefined`.
*/
find(callback: (element: E, index: number, deque: Deque<E>) => boolean): E | undefined {
for (let i = 0; i < this.size; ++i) {
const element = this.getAt(i);
if (callback(element, i, this)) {
return element;
}
}
return;
}
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*
* The function "indexOf" returns the index of the first occurrence of a given element in an array,

@@ -608,3 +648,3 @@ * or -1 if the element is not found.

for (let i = 0; i < this.size; ++i) {
if (this.getAt(i) === element) {
if (this.at(i) === element) {
return i;

@@ -636,2 +676,3 @@ }

*/
/**

@@ -641,2 +682,20 @@ * Time Complexity: O(n)

*
* The `clone()` function returns a new instance of the `Deque` class with the same elements and
* bucket size as the original instance.
* @returns The `clone()` method is returning a new instance of the `Deque` class with the same
* elements as the original deque (`this`) and the same bucket size.
*/
clone(): Deque<E> {
return new Deque<E>([...this], { bucketSize: this.bucketSize });
}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function creates a new deque containing elements from the original deque that satisfy

@@ -759,3 +818,3 @@ * a given predicate function.

for (let i = 0; i < this.size; ++i) {
yield this.getAt(i);
yield this.at(i);
}

@@ -762,0 +821,0 @@ }

@@ -35,2 +35,6 @@ /**

/**
* The elements function returns the elements of this set.
* @return An array of the elements in the stack
*/
get elements(): E[] {

@@ -42,2 +46,6 @@ return this._elements;

/**
* The offset function returns the offset of the current page.
* @return The value of the private variable _offset
*/
get offset(): number {

@@ -148,2 +156,22 @@ return this._offset;

/**
* The delete function removes an element from the list.
* @param element: E Specify the element to be deleted
* @return A boolean value indicating whether the element was successfully deleted or not
*/
delete(element: E): boolean {
const index = this.elements.indexOf(element);
return this.deleteAt(index);
}
/**
* The deleteAt function deletes the element at a given index.
* @param index: number Determine the index of the element to be deleted
* @return A boolean value
*/
deleteAt(index: number): boolean {
const spliced = this.elements.splice(index, 1);
return spliced.length === 1;
}
/**
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.

@@ -225,3 +253,3 @@ * Space Complexity: O(1) - no additional space is used.

*/
getAt(index: number): E | undefined {
at(index: number): E | undefined {
return this.elements[index];

@@ -271,9 +299,10 @@ }

/**
* Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
* Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
* Time Complexity: O(n)
* Space Complexity: O(n)
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
*/
/**
* Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
* Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
* Time Complexity: O(n)
* Space Complexity: O(n)
*

@@ -398,2 +427,19 @@ * The `clone()` function returns a new Queue object with the same elements as the original Queue.

}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
* The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
* the current instance.
* @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
* values as the original `LinkedListQueue`.
*/
clone(): LinkedListQueue<E> {
return new LinkedListQueue<E>(this.values());
}
}

@@ -35,2 +35,6 @@ /**

/**
* The elements function returns the elements of this set.
* @return An array of elements
*/
get elements(): E[] {

@@ -130,2 +134,22 @@ return this._elements;

/**
* The delete function removes an element from the stack.
* @param element: E Specify the element to be deleted
* @return A boolean value indicating whether the element was successfully deleted or not
*/
delete(element: E): boolean {
const index = this.elements.indexOf(element);
return this.deleteAt(index);
}
/**
* The deleteAt function deletes the element at a given index.
* @param index: number Determine the index of the element to be deleted
* @return A boolean value
*/
deleteAt(index: number): boolean {
const spliced = this.elements.splice(index, 1);
return spliced.length === 1;
}
/**
* Time Complexity: O(n)

@@ -132,0 +156,0 @@ * Space Complexity: O(n)

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

*/
export class Trie extends IterableElementBase<string> {
export class Trie extends IterableElementBase<string, Trie> {
/**
* The constructor function for the Trie class.
* @param words: Iterable string Initialize the trie with a set of words
* @param options?: TrieOptions Allow the user to pass in options for the trie
* @return This
*/
constructor(words: Iterable<string> = [], options?: TrieOptions) {

@@ -55,2 +61,6 @@ super();

/**
* The size function returns the size of the stack.
* @return The number of elements in the list
*/
get size(): number {

@@ -62,2 +72,7 @@ return this._size;

/**
* The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
*
* @return The value of the _casesensitive private variable
*/
get caseSensitive(): boolean {

@@ -69,2 +84,6 @@ return this._caseSensitive;

/**
* The root function returns the root node of the tree.
* @return The root node
*/
get root() {

@@ -132,2 +151,10 @@ return this._root;

/**
* The isEmpty function checks if the size of the queue is 0.
* @return True if the size of the queue is 0
*/
isEmpty(): boolean {
return this.size === 0;
}
/**
* Time Complexity: O(M), where M is the length of the word being deleted.

@@ -368,2 +395,19 @@ * Space Complexity: O(M) - Due to the recursive DFS approach.

*
* The `clone` function returns a new instance of the Trie class with the same values and case
* sensitivity as the original Trie.
* @returns A new instance of the Trie class is being returned.
*/
clone(): Trie {
return new Trie(this.values(), { caseSensitive: this.caseSensitive });
}
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*/
/**
* Time Complexity: O(n)
* Space Complexity: O(n)
*
* The `filter` function takes a predicate function and returns a new array containing all the

@@ -370,0 +414,0 @@ * elements for which the predicate function returns true.

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

export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@@ -9,0 +9,0 @@ export type BinaryTreeOptions<K> = {

@@ -8,12 +8,13 @@ export type HashMapLinkedNode<K, V> = {

export type LinkedHashMapOptions<K> = {
export type LinkedHashMapOptions<K, V, R> = {
hashFn?: (key: K) => string;
objHashFn?: (key: K) => object;
toEntryFn?: (rawElement: R) => [K, V];
};
export type HashMapOptions<K, V, T> = {
export type HashMapOptions<K, V, R> = {
hashFn?: (key: K) => string;
toEntryFn?: (rawElement: T) => [K, V];
toEntryFn?: (rawElement: R) => [K, V];
};
export type HashMapStoreItem<K, V> = { key: K; value: V };

@@ -7,1 +7,3 @@ export type ToThunkFn = () => ReturnType<TrlFn>;

export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export type Any = string | number | boolean | object | null | undefined | symbol;

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

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

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