Socket
Socket
Sign inDemoInstall

data-structure-typed

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-structure-typed - npm Package Compare versions

Comparing version 1.18.0 to 1.18.5

backup/recursive-type/src/assets/complexities-diff.jpg

44

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

@@ -9,14 +9,8 @@ /**

import { BST, BSTNode } from './bst';
import type { AVLTreeDeleted, BinaryTreeNodeId } from '../types';
export declare class AVLTreeNode<T> extends BSTNode<T> {
/**
* The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
* id, value, and count.
* @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
* the current instance.
*/
clone(): AVLTreeNode<T>;
import type { AVLTreeDeleted, BinaryTreeNodeId, RecursiveAVLTreeNode } from '../types';
import { IBinaryTreeNode } from '../interfaces';
export declare class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
}
export declare class AVLTree<T> extends BST<T> {
createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> {
_createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
/**

@@ -27,10 +21,10 @@ * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then

* update in the AVL tree.
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
* `id`. It can be of type `T` (the generic type) or `null`.
* @param {N | null} val - The `val` parameter represents the value that you want to assign to the node with the given
* `id`. It can be of type `N` (the generic type) or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
* of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
* to `1`, indicating that the value should be inserted once.
* @returns The method is returning either an AVLTreeNode<T> object or null.
* @returns The method is returning either an N object or null.
*/
add(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
/**

@@ -44,12 +38,12 @@ * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and

* `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
* @returns The method is returning an array of `AVLTreeDeleted<T>` objects.
* @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
*/
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<T>[];
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<N>[];
/**
* The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
* height of its right subtree.
* @param node - The parameter "node" is of type AVLTreeNode<T>, which represents a node in an AVL tree.
* @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
* @returns The balance factor of the given AVL tree node.
*/
balanceFactor(node: AVLTreeNode<T>): number;
balanceFactor(node: N): number;
/**

@@ -59,3 +53,3 @@ * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.

*/
updateHeight(node: AVLTreeNode<T>): void;
updateHeight(node: N): void;
/**

@@ -66,3 +60,3 @@ * The `balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of

*/
balancePath(node: AVLTreeNode<T>): void;
balancePath(node: N): void;
/**

@@ -72,3 +66,3 @@ * The `balanceLL` function performs a left-left rotation on an AVL tree to balance it.

*/
balanceLL(A: AVLTreeNode<T>): void;
balanceLL(A: N): void;
/**

@@ -78,3 +72,3 @@ * The `balanceLR` function performs a left-right rotation to balance an AVL tree.

*/
balanceLR(A: AVLTreeNode<T>): void;
balanceLR(A: N): void;
/**

@@ -84,3 +78,3 @@ * The `balanceRR` function performs a right-right rotation on an AVL tree to balance it.

*/
balanceRR(A: AVLTreeNode<T>): void;
balanceRR(A: N): void;
/**

@@ -90,3 +84,3 @@ * The `balanceRL` function performs a right-left rotation to balance an AVL tree.

*/
balanceRL(A: AVLTreeNode<T>): void;
balanceRL(A: N): void;
}

@@ -43,11 +43,2 @@ "use strict";

}
/**
* The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
* id, value, and count.
* @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
* the current instance.
*/
AVLTreeNode.prototype.clone = function () {
return new AVLTreeNode(this.id, this.val, this.count);
};
return AVLTreeNode;

@@ -61,4 +52,5 @@ }(bst_1.BSTNode));

}
AVLTree.prototype.createNode = function (id, val, count) {
return new AVLTreeNode(id, val, count);
AVLTree.prototype._createNode = function (id, val, count) {
var node = new AVLTreeNode(id, val, count);
return node;
};

@@ -70,8 +62,8 @@ /**

* update in the AVL tree.
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
* `id`. It can be of type `T` (the generic type) or `null`.
* @param {N | null} val - The `val` parameter represents the value that you want to assign to the node with the given
* `id`. It can be of type `N` (the generic type) or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
* of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
* to `1`, indicating that the value should be inserted once.
* @returns The method is returning either an AVLTreeNode<T> object or null.
* @returns The method is returning either an N object or null.
*/

@@ -92,3 +84,3 @@ AVLTree.prototype.add = function (id, val, count) {

* `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
* @returns The method is returning an array of `AVLTreeDeleted<T>` objects.
* @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
*/

@@ -118,3 +110,3 @@ AVLTree.prototype.remove = function (id, isUpdateAllLeftSum) {

* height of its right subtree.
* @param node - The parameter "node" is of type AVLTreeNode<T>, which represents a node in an AVL tree.
* @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
* @returns The balance factor of the given AVL tree node.

@@ -121,0 +113,0 @@ */

@@ -8,3 +8,4 @@ /**

*/
import type { BinaryTreeDeleted, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName, ResultsByProperty } from '../types';
import type { BinaryTreeDeleted, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName, RecursiveBinaryTreeNode, ResultsByProperty } from '../types';
import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
export declare enum FamilyPosition {

@@ -25,3 +26,3 @@ root = 0,

}
export declare class BinaryTreeNode<T> {
export declare class BinaryTreeNode<T, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> implements IBinaryTreeNode<T, FAMILY> {
constructor(id: BinaryTreeNodeId, val: T, count?: number);

@@ -35,10 +36,10 @@ private _id;

private _left?;
get left(): BinaryTreeNode<T> | null | undefined;
set left(v: BinaryTreeNode<T> | null | undefined);
get left(): FAMILY | null | undefined;
set left(v: FAMILY | null | undefined);
private _right?;
get right(): BinaryTreeNode<T> | null | undefined;
set right(v: BinaryTreeNode<T> | null | undefined);
get right(): FAMILY | null | undefined;
set right(v: FAMILY | null | undefined);
private _parent;
get parent(): BinaryTreeNode<T> | null | undefined;
set parent(v: BinaryTreeNode<T> | null | undefined);
get parent(): FAMILY | null | undefined;
set parent(v: FAMILY | null | undefined);
private _familyPosition;

@@ -53,6 +54,7 @@ get familyPosition(): FamilyPosition;

set height(v: number);
swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
clone(): BinaryTreeNode<T>;
_createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
swapLocation(swapNode: FAMILY): FAMILY;
clone(): FAMILY | null;
}
export declare class BinaryTree<T> {
export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode<number>> implements IBinaryTree<N> {
/**

@@ -73,5 +75,5 @@ * The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and

private _visitedVal;
get visitedVal(): Array<T>;
get visitedVal(): Array<N['val']>;
private _visitedNode;
get visitedNode(): BinaryTreeNode<T>[];
get visitedNode(): N[];
private _visitedCount;

@@ -88,3 +90,3 @@ get visitedCount(): number[];

private _root;
get root(): BinaryTreeNode<T> | null;
get root(): N | null;
private _size;

@@ -95,14 +97,13 @@ get size(): number;

/**
* The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
* null.
* The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
* it returns null.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`, which could be a string or a number, depending on how you want to identify your nodes.
* @param {T | null} val - The `val` parameter represents the value to be stored in the binary tree node. It can be of
* any type `T` or `null`.
* @param {number} [count] - The count parameter is an optional parameter that represents the number of occurrences of
* the value in the binary tree node. It is of type number.
* @returns The function `createNode` returns a `BinaryTreeNode<T>` object if the `val` parameter is not null.
* Otherwise, it returns null.
* `BinaryTreeNodeId`.
* @param {N | null} val - The `val` parameter represents the value of the node. It can be of type `N` (generic type)
* or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
* of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
* @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
*/
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null;
_createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
/**

@@ -122,12 +123,12 @@ * The clear function resets the state of an object by setting its properties to their initial values.

* identify each node in the binary tree.
* @param {T} val - The value to be inserted into the binary tree.
* @param {N} val - The value to be inserted into the binary tree.
* @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
* value should be inserted into the binary tree. If not provided, it defaults to 1.
* @returns The function `add` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
* @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
* is inserted, or `undefined` if the insertion fails.
*/
add(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
add(id: BinaryTreeNodeId, val: N['val'], count?: number): N | null | undefined;
/**
* The function inserts a new node into a binary tree as the left or right child of a given parent node.
* @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
* @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
* `null`. It represents the node that needs to be inserted into the binary tree.

@@ -138,19 +139,19 @@ * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node

*/
addTo(newNode: BinaryTreeNode<T> | null, parent: BinaryTreeNode<T>): BinaryTreeNode<T> | null | undefined;
addTo(newNode: N | null, parent: N): N | null | undefined;
/**
* The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
* null/undefined values.
* @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
* array of `BinaryTreeNode<T>` objects.
* @returns The function `addMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
* array of `N` objects.
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
*/
addMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
/**
* The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
* was successful.
* @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
* array of `BinaryTreeNode<T>` objects.
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
* array of `N` objects.
* @returns The method is returning a boolean value.
*/
fill(data: T[] | BinaryTreeNode<T>[]): boolean;
fill(data: N[] | Array<N['val']>): boolean;
/**

@@ -167,40 +168,40 @@ * The function removes a node from a binary tree and returns information about the deleted node.

*/
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<T>[];
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<N>[];
/**
* The function calculates the depth of a binary tree node by traversing its parent nodes.
* @param node - BinaryTreeNode<T> - This is the node for which we want to calculate the depth. It is a generic type,
* @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
* meaning it can represent any type of data that we want to store in the node.
* @returns The depth of the given binary tree node.
*/
getDepth(node: BinaryTreeNode<T>): number;
getDepth(node: N): number;
/**
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
* approach.
* @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `BinaryTreeNode<T> | null`. It represents the starting node from which to calculate the height of the binary tree.
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `N | null`. It represents the starting node from which to calculate the height of the binary tree.
* If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
* @returns the height of the binary tree.
*/
getHeight(beginRoot?: BinaryTreeNode<T> | null): number;
getHeight(beginRoot?: N | null): number;
/**
* The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
* approach.
* @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `BinaryTreeNode<T> | null`. It represents the starting node from which to calculate the minimum height of the binary
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `N | null`. It represents the starting node from which to calculate the minimum height of the binary
* tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
*/
getMinHeight(beginRoot?: BinaryTreeNode<T> | null): number;
getMinHeight(beginRoot?: N | null): number;
/**
* The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
* @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
* of type `BinaryTreeNode<T> | null`, which means it can either be a `BinaryTreeNode` object or `null`.
* @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
* of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
* @returns The method is returning a boolean value.
*/
isBalanced(beginRoot?: BinaryTreeNode<T> | null): boolean;
isBalanced(beginRoot?: N | null): boolean;
/**
* The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
* searching recursively or iteratively.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -211,10 +212,10 @@ * specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.

* function will stop traversing the tree and return the first matching node. If `
* @returns The function `getNodes` returns an array of `BinaryTreeNode<T> | null | undefined` objects.
* @returns The function `getNodes` returns an array of `N | null | undefined` objects.
*/
getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (BinaryTreeNode<T> | null | undefined)[];
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (N | null | undefined)[];
/**
* The function checks if a binary tree node has a specific property or if any node in the tree has a specific
* property.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property of a binary tree node that you want to check.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property of a binary tree node that you want to check.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -224,8 +225,8 @@ * specifies the name of the property to check for in the nodes.

*/
has(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): boolean;
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
/**
* The function returns the first binary tree node that matches the given property name and value, or null if no match
* is found.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -235,3 +236,3 @@ * specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.

*/
get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BinaryTreeNode<T> | null;
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
/**

@@ -241,13 +242,13 @@ * The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the

* @param node - The `node` parameter is a BinaryTreeNode object.
* @returns The function `getPathToRoot` returns an array of `BinaryTreeNode<T>` objects, representing the path from
* @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
* the given `node` to the root of the binary tree.
*/
getPathToRoot(node: BinaryTreeNode<T>): BinaryTreeNode<T>[];
getLeftMost(): BinaryTreeNode<T> | null;
getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
getRightMost(): BinaryTreeNode<T> | null;
getRightMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
getPathToRoot(node: N): N[];
getLeftMost(): N | null;
getLeftMost(node: N): N;
getRightMost(): N | null;
getRightMost(node: N): N;
/**
* The `isBST` function checks if a binary tree is a binary search tree.
* @param {BinaryTreeNode<T> | null} [node] - The `node` parameter is an optional parameter of type `BinaryTreeNode<T>
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
* | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node

@@ -258,7 +259,7 @@ * is provided, the function will default to using the root node of the BST instance that

*/
isBST(node?: BinaryTreeNode<T> | null): boolean;
isBST(node?: N | null): boolean;
/**
* The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
* traversal.
* @param {BinaryTreeNode<T> | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
* tree.

@@ -268,3 +269,3 @@ * @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array

*/
getSubTreeSizeAndCount(subTreeRoot: BinaryTreeNode<T> | null | undefined): [number, number];
getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
/**

@@ -280,3 +281,3 @@ * The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or

*/
subTreeSum(subTreeRoot: BinaryTreeNode<T>, propertyName?: BinaryTreeNodePropertyName): number;
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
/**

@@ -291,28 +292,28 @@ * The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.

*/
subTreeAdd(subTreeRoot: BinaryTreeNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
BFS(): BinaryTreeNodeId[];
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
BFS(nodeOrPropertyName: 'val'): T[];
BFS(nodeOrPropertyName: 'node'): BinaryTreeNode<T>[];
BFS(nodeOrPropertyName: 'val'): N['val'][];
BFS(nodeOrPropertyName: 'node'): N[];
BFS(nodeOrPropertyName: 'count'): number[];
DFS(): BinaryTreeNodeId[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
DFSIterative(): BinaryTreeNodeId[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
levelIterative(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[];
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[];
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[];
listLevels(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[][];
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[][];
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[][];
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[][];
levelIterative(node: N | null): BinaryTreeNodeId[];
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
listLevels(node: N | null): BinaryTreeNodeId[][];
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
/**

@@ -323,12 +324,12 @@ * The function returns the predecessor of a given node in a binary tree.

*/
getPredecessor(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
getPredecessor(node: N): N;
morris(): BinaryTreeNodeId[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
protected _setLoopType(value: LoopType): void;
protected _setVisitedId(value: BinaryTreeNodeId[]): void;
protected _setVisitedVal(value: Array<T>): void;
protected _setVisitedNode(value: BinaryTreeNode<T>[]): void;
protected _setVisitedVal(value: Array<N>): void;
protected _setVisitedNode(value: N[]): void;
protected setVisitedCount(value: number[]): void;

@@ -339,3 +340,3 @@ protected _setVisitedLeftSum(value: number[]): void;

protected _setIsDuplicatedVal(value: boolean): void;
protected _setRoot(v: BinaryTreeNode<T> | null): void;
protected _setRoot(v: N | null): void;
protected _setSize(v: number): void;

@@ -351,5 +352,5 @@ protected _setCount(v: number): void;

* @param cur - The current binary tree node that is being checked.
* @param {(BinaryTreeNode<T> | null | undefined)[]} result - An array that stores the matching nodes found during the
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
* traversal.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
* the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.

@@ -364,7 +365,7 @@ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

*/
protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
/**
* The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
* provided property name or a default property name.
* @param node - The `node` parameter is of type `BinaryTreeNode<T>`, which represents a node in a binary tree.
* @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that

@@ -374,3 +375,3 @@ * can be either a string representing a property name or a reference to a node object. If it is a string, it specifies

*/
protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
/**

@@ -383,3 +384,3 @@ * The function `_getResultByPropertyName` returns different results based on the provided property name or defaulting

*/
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<N>;
}

@@ -154,20 +154,25 @@ "use strict";

});
BinaryTreeNode.prototype._createNode = function (id, val, count) {
return val !== null ? new BinaryTreeNode(id, val, count) : null;
};
BinaryTreeNode.prototype.swapLocation = function (swapNode) {
var val = swapNode.val, count = swapNode.count, height = swapNode.height;
var tempNode = new BinaryTreeNode(swapNode.id, val);
tempNode.val = val;
tempNode.count = count;
tempNode.height = height;
swapNode.id = this.id;
swapNode.val = this.val;
swapNode.count = this.count;
swapNode.height = this.height;
this.id = tempNode.id;
this.val = tempNode.val;
this.count = tempNode.count;
this.height = tempNode.height;
var tempNode = this._createNode(swapNode.id, val);
if (tempNode instanceof BinaryTreeNode) {
tempNode.val = val;
tempNode.count = count;
tempNode.height = height;
swapNode.id = this.id;
swapNode.val = this.val;
swapNode.count = this.count;
swapNode.height = this.height;
this.id = tempNode.id;
this.val = tempNode.val;
this.count = tempNode.count;
this.height = tempNode.height;
}
return swapNode;
};
BinaryTreeNode.prototype.clone = function () {
return new BinaryTreeNode(this.id, this.val, this.count);
return this._createNode(this.id, this.val, this.count);
};

@@ -288,15 +293,15 @@ return BinaryTreeNode;

/**
* The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
* null.
* The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
* it returns null.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
* `BinaryTreeNodeId`, which could be a string or a number, depending on how you want to identify your nodes.
* @param {T | null} val - The `val` parameter represents the value to be stored in the binary tree node. It can be of
* any type `T` or `null`.
* @param {number} [count] - The count parameter is an optional parameter that represents the number of occurrences of
* the value in the binary tree node. It is of type number.
* @returns The function `createNode` returns a `BinaryTreeNode<T>` object if the `val` parameter is not null.
* Otherwise, it returns null.
* `BinaryTreeNodeId`.
* @param {N | null} val - The `val` parameter represents the value of the node. It can be of type `N` (generic type)
* or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
* of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
* @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
*/
BinaryTree.prototype.createNode = function (id, val, count) {
return val !== null ? new BinaryTreeNode(id, val, count) : null;
BinaryTree.prototype._createNode = function (id, val, count) {
var node = new BinaryTreeNode(id, val, count);
return node;
};

@@ -324,6 +329,6 @@ /**

* identify each node in the binary tree.
* @param {T} val - The value to be inserted into the binary tree.
* @param {N} val - The value to be inserted into the binary tree.
* @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
* value should be inserted into the binary tree. If not provided, it defaults to 1.
* @returns The function `add` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
* @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
* is inserted, or `undefined` if the insertion fails.

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

var inserted;
var needInsert = val !== null ? new BinaryTreeNode(id, val, count) : null;
var needInsert = val !== null ? this._createNode(id, val, count) : null;
var existNode = val !== null ? this.get(id, 'id') : null;

@@ -370,3 +375,3 @@ if (this.root) {

else {
this._setRoot(val !== null ? new BinaryTreeNode(id, val, count) : null);
this._setRoot(val !== null ? this._createNode(id, val, count) : null);
if (needInsert !== null) {

@@ -382,3 +387,3 @@ this._setSize(1);

* The function inserts a new node into a binary tree as the left or right child of a given parent node.
* @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
* @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
* `null`. It represents the node that needs to be inserted into the binary tree.

@@ -400,3 +405,3 @@ * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node

this._setSize(this.size + 1);
this._setCount((_a = this.count + (newNode === null || newNode === void 0 ? void 0 : newNode.count)) !== null && _a !== void 0 ? _a : 0);
this._setCount((_a = this.count + newNode.count) !== null && _a !== void 0 ? _a : 0);
}

@@ -413,3 +418,3 @@ return parent.left;

this._setSize(this.size + 1);
this._setCount((_b = this.count + (newNode === null || newNode === void 0 ? void 0 : newNode.count)) !== null && _b !== void 0 ? _b : 0);
this._setCount((_b = this.count + newNode.count) !== null && _b !== void 0 ? _b : 0);
}

@@ -429,5 +434,5 @@ return parent.right;

* null/undefined values.
* @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
* array of `BinaryTreeNode<T>` objects.
* @returns The function `addMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
* array of `N` objects.
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
*/

@@ -502,4 +507,4 @@ BinaryTree.prototype.addMany = function (data) {

* was successful.
* @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
* array of `BinaryTreeNode<T>` objects.
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
* array of `N` objects.
* @returns The method is returning a boolean value.

@@ -559,3 +564,3 @@ */

* The function calculates the depth of a binary tree node by traversing its parent nodes.
* @param node - BinaryTreeNode<T> - This is the node for which we want to calculate the depth. It is a generic type,
* @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
* meaning it can represent any type of data that we want to store in the node.

@@ -575,4 +580,4 @@ * @returns The depth of the given binary tree node.

* approach.
* @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `BinaryTreeNode<T> | null`. It represents the starting node from which to calculate the height of the binary tree.
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `N | null`. It represents the starting node from which to calculate the height of the binary tree.
* If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as

@@ -627,4 +632,4 @@ * @returns the height of the binary tree.

* approach.
* @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `BinaryTreeNode<T> | null`. It represents the starting node from which to calculate the minimum height of the binary
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
* `N | null`. It represents the starting node from which to calculate the minimum height of the binary
* tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.

@@ -680,4 +685,4 @@ * @returns The function `getMinHeight` returns the minimum height of the binary tree.

* The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
* @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
* of type `BinaryTreeNode<T> | null`, which means it can either be a `BinaryTreeNode` object or `null`.
* @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
* of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
* @returns The method is returning a boolean value.

@@ -691,4 +696,4 @@ */

* searching recursively or iteratively.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -699,3 +704,3 @@ * specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.

* function will stop traversing the tree and return the first matching node. If `
* @returns The function `getNodes` returns an array of `BinaryTreeNode<T> | null | undefined` objects.
* @returns The function `getNodes` returns an array of `N | null | undefined` objects.
*/

@@ -736,4 +741,4 @@ BinaryTree.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {

* property.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property of a binary tree node that you want to check.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property of a binary tree node that you want to check.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -749,4 +754,4 @@ * specifies the name of the property to check for in the nodes.

* is found.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property of the binary tree node that you want to search for.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -765,3 +770,3 @@ * specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.

* @param node - The `node` parameter is a BinaryTreeNode object.
* @returns The function `getPathToRoot` returns an array of `BinaryTreeNode<T>` objects, representing the path from
* @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
* the given `node` to the root of the binary tree.

@@ -781,3 +786,3 @@ */

* recursion optimization.
* @param {BinaryTreeNode<T> | null} [node] - The `node` parameter is an optional parameter of type `BinaryTreeNode<T>
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
* | null`. It represents the starting node from which to find the leftmost node in a binary tree. If no node is

@@ -812,3 +817,3 @@ * provided, the function will use the root node of the binary tree.

* tail recursion optimization.
* @param {BinaryTreeNode<T> | null} [node] - The `node` parameter is an optional parameter of type `BinaryTreeNode<T>
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
* | null`. It represents the starting node from which to find the rightmost node in a binary tree. If no node is

@@ -842,3 +847,3 @@ * provided, the function will use the root node of the binary tree.

* The `isBST` function checks if a binary tree is a binary search tree.
* @param {BinaryTreeNode<T> | null} [node] - The `node` parameter is an optional parameter of type `BinaryTreeNode<T>
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
* | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node

@@ -883,3 +888,3 @@ * is provided, the function will default to using the root node of the BST instance that

* traversal.
* @param {BinaryTreeNode<T> | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
* tree.

@@ -1022,3 +1027,3 @@ * @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array

* performed starting from the root node
* @returns an object of type `ResultsByProperty<T>`.
* @returns an object of type `ResultsByProperty<N>`.
*/

@@ -1051,3 +1056,3 @@ BinaryTree.prototype.BFS = function (nodeOrPropertyName) {

* no value
* @returns an object of type `ResultsByProperty<T>`.
* @returns an object of type `ResultsByProperty<N>`.
*/

@@ -1139,3 +1144,3 @@ BinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {

* in an array, based on a specified property name.
* @param {BinaryTreeNode<T> | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
* node for the level order traversal. It can be null if no specific node is provided, in which case the root node of

@@ -1147,3 +1152,3 @@ * the tree is used as the starting node.

* accumulating results
* @returns The function `levelIterative` returns an object of type `ResultsByProperty<T>`.
* @returns The function `levelIterative` returns an object of type `ResultsByProperty<N>`.
*/

@@ -1173,3 +1178,3 @@ BinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {

* The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
* @param {BinaryTreeNode<T> | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the
* root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.

@@ -1179,3 +1184,3 @@ * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that

* values:
* @returns The function `listLevels` returns a 2D array of `ResultByProperty<T>` objects.
* @returns The function `listLevels` returns a 2D array of `ResultByProperty<N>` objects.
*/

@@ -1264,3 +1269,3 @@ BinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {

* property. If not provided, it defaults to `'id'`.
* @returns The function `morris` returns an object of type `ResultsByProperty<T>`.
* @returns The function `morris` returns an object of type `ResultsByProperty<N>`.
*/

@@ -1408,5 +1413,5 @@ BinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {

* @param cur - The current binary tree node that is being checked.
* @param {(BinaryTreeNode<T> | null | undefined)[]} result - An array that stores the matching nodes found during the
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
* traversal.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
* the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.

@@ -1452,3 +1457,3 @@ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

* provided property name or a default property name.
* @param node - The `node` parameter is of type `BinaryTreeNode<T>`, which represents a node in a binary tree.
* @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that

@@ -1455,0 +1460,0 @@ * can be either a string representing a property name or a reference to a node object. If it is a string, it specifies

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

*/
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult } from '../types';
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult, RecursiveBSTNode } from '../types';
import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
export declare enum CP {

@@ -16,6 +17,5 @@ lt = -1,

}
export declare class BSTNode<T> extends BinaryTreeNode<T> {
clone(): BSTNode<T>;
export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
}
export declare class BST<T> extends BinaryTree<T> {
export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBinaryTree<N> {
/**

@@ -29,3 +29,3 @@ * The constructor function accepts an optional options object and sets the comparator property if provided.

});
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
_createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
/**

@@ -36,20 +36,20 @@ * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if

* determine the position of the node in the binary search tree.
* @param {T | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
* be of type `T` (the generic type) or `null`.
* @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
* be of type `N` (the generic type) or `null`.
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
* inserted once.
* @returns The method `add` returns a `BSTNode<T>` object or `null`.
* @returns The method `add` returns a `N` object or `null`.
*/
add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
/**
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
* `'id'`.
* @returns The method is returning a BSTNode<T> object or null.
* @returns The method is returning a N object or null.
*/
get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
/**

@@ -72,10 +72,10 @@ * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the

* set to false or not provided, the count of the node will be taken into account and the
* @returns an array of `BSTDeletedResult<T>` objects.
* @returns an array of `BSTDeletedResult<N>` objects.
*/
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<N>[];
/**
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
* option to specify the property name and whether to return only one node.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property value that you want to search for in the binary search tree.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -87,5 +87,5 @@ * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to

* to false or not provided, the function will return all nodes that match the given nodeProperty.
* @returns an array of BSTNode<T> objects.
* @returns an array of N objects.
*/
getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
/**

@@ -105,3 +105,3 @@ * The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in

* that have a greater value than a given node.
* @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
* @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
* contains properties such as `id` and `count`.

@@ -115,3 +115,3 @@ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

*/
allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
/**

@@ -118,0 +118,0 @@ * The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a

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

}
BSTNode.prototype.clone = function () {
return new BSTNode(this.id, this.val, this.count);
};
return BSTNode;

@@ -71,4 +68,5 @@ }(binary_tree_1.BinaryTreeNode));

}
BST.prototype.createNode = function (id, val, count) {
return val !== null ? new BSTNode(id, val, count) : null;
BST.prototype._createNode = function (id, val, count) {
var node = val !== null ? new BSTNode(id, val, count) : null;
return node;
};

@@ -80,8 +78,8 @@ /**

* determine the position of the node in the binary search tree.
* @param {T | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
* be of type `T` (the generic type) or `null`.
* @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
* be of type `N` (the generic type) or `null`.
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
* inserted once.
* @returns The method `add` returns a `BSTNode<T>` object or `null`.
* @returns The method `add` returns a `N` object or `null`.
*/

@@ -91,3 +89,3 @@ BST.prototype.add = function (id, val, count) {

var inserted = null;
var newNode = this.createNode(id, val, count);
var newNode = this._createNode(id, val, count);
if (this.root === null) {

@@ -164,8 +162,8 @@ this._setRoot(newNode);

* The `get` function returns the first node in a binary search tree that matches the given property value or name.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
* `'id'`.
* @returns The method is returning a BSTNode<T> object or null.
* @returns The method is returning a N object or null.
*/

@@ -202,3 +200,3 @@ BST.prototype.get = function (nodeProperty, propertyName) {

* set to false or not provided, the count of the node will be taken into account and the
* @returns an array of `BSTDeletedResult<T>` objects.
* @returns an array of `BSTDeletedResult<N>` objects.
*/

@@ -259,4 +257,4 @@ BST.prototype.remove = function (id, ignoreCount) {

* option to specify the property name and whether to return only one node.
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `T`. It represents the property value that you want to search for in the binary search tree.
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that

@@ -268,3 +266,3 @@ * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to

* to false or not provided, the function will return all nodes that match the given nodeProperty.
* @returns an array of BSTNode<T> objects.
* @returns an array of N objects.
*/

@@ -410,3 +408,3 @@ BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {

* that have a greater value than a given node.
* @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
* @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
* contains properties such as `id` and `count`.

@@ -413,0 +411,0 @@ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of

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

export declare class RBTree {
}
export {};
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.RBTree = void 0;
var RBTree = /** @class */ (function () {
function RBTree() {
var binary_tree_1 = require("./binary-tree");
var RBColor;
(function (RBColor) {
RBColor[RBColor["Red"] = 0] = "Red";
RBColor[RBColor["Black"] = 1] = "Black";
})(RBColor || (RBColor = {}));
var RBNode = /** @class */ (function (_super) {
__extends(RBNode, _super);
// override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
// return val !== null ? new RBNode<T>(id, val, count) : null;
// }
function RBNode(id, val, count) {
var _this = _super.call(this, id, val, count) || this;
_this._color = RBColor.Red;
return _this;
}
Object.defineProperty(RBNode.prototype, "color", {
get: function () {
return this._color;
},
set: function (value) {
this._color = value;
},
enumerable: false,
configurable: true
});
return RBNode;
}(binary_tree_1.BinaryTreeNode));
var RBTree = /** @class */ (function (_super) {
__extends(RBTree, _super);
function RBTree(options) {
return _super.call(this, options) || this;
}
// override _createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
// return val !== null ? new RBNode<N>(id, val, count) : null;
// }
// private override _root: BinaryTreeNode<N> | null = null;
//
// override get root(): BinaryTreeNode<N> | null {
// return this._root;
// }
RBTree.prototype.insert = function (id, val) {
};
RBTree.prototype.leftRotate = function (node) {
};
RBTree.prototype.rightRotate = function (node) {
};
RBTree.prototype.insertFixup = function (node) {
};
RBTree.prototype.deleteFixup = function (node) {
};
RBTree.prototype.transplant = function (u, v) {
};
return RBTree;
}());
exports.RBTree = RBTree;
}(binary_tree_1.BinaryTree));

@@ -10,3 +10,4 @@ /**

import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
export declare class TreeMultiSet<T> extends BST<T> {
import { IBinaryTree } from '../interfaces';
export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBinaryTree<N> {
/**

@@ -16,3 +17,3 @@ * The function creates a new BSTNode with the given id, value, and count.

* distinguish one node from another in the tree.
* @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
* @param {N} val - The `val` 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

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

*/
createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
_createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
/**
* The function overrides the add method of the BinarySearchTree class in TypeScript.
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
* @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
* can be of type `T` (the generic type) or `null`.
* @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
* can be of type `N` (the generic type) or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
* @returns The `add` method is returning a `BSTNode<T>` object or `null`.
* @returns The `add` method is returning a `BSTNode<N>` object or `null`.
*/
add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
add(id: BinaryTreeNodeId, val: N | null, count?: number): N | null;
/**

@@ -44,3 +45,3 @@ * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove

*/
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<N>[];
}

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

* distinguish one node from another in the tree.
* @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
* @param {N} val - The `val` 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

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

*/
TreeMultiSet.prototype.createNode = function (id, val, count) {
return new bst_1.BSTNode(id, val, count);
TreeMultiSet.prototype._createNode = function (id, val, count) {
var node = new bst_1.BSTNode(id, val, count);
return node;
};

@@ -49,7 +50,7 @@ /**

* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
* @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
* can be of type `T` (the generic type) or `null`.
* @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
* can be of type `N` (the generic type) or `null`.
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
* @returns The `add` method is returning a `BSTNode<T>` object or `null`.
* @returns The `add` method is returning a `BSTNode<N>` object or `null`.
*/

@@ -56,0 +57,0 @@ TreeMultiSet.prototype.add = function (id, val, count) {

@@ -1,16 +0,18 @@

import type { DijkstraResult, IGraph, VertexId } from '../types';
export declare class AbstractVertex {
constructor(id: VertexId);
protected _id: VertexId;
import type { DijkstraResult, VertexId } from '../types';
import { IGraph } from '../interfaces';
export declare abstract class AbstractVertex<T = number> {
protected constructor(id: VertexId, val?: T);
private _id;
get id(): VertexId;
set id(v: VertexId);
private _val;
get val(): T | undefined;
set val(value: T | undefined);
}
export declare abstract class AbstractEdge {
/**
* The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
* no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
*/
protected constructor(weight?: number);
protected _weight: number;
export declare abstract class AbstractEdge<T = number> {
protected constructor(weight?: number, val?: T);
private _val;
get val(): T | undefined;
set val(value: T | undefined);
private _weight;
get weight(): number;

@@ -22,22 +24,26 @@ set weight(v: number);

}
export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements IGraph<V, E> {
protected _vertices: Map<VertexId, V>;
abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
abstract removeEdge(edge: E): E | null;
export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IGraph<V, E> {
private _vertices;
get vertices(): Map<VertexId, V>;
/**
* The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
* does not exist.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
* If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param val
*/
getVertex(vertexOrId: VertexId | V): V | null;
abstract _createVertex(id: VertexId, val?: V): V;
/**
* The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
* a `VertexId`.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns the id of the vertex.
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param srcOrV1
* @param destOrV2
* @param weight
* @param val
*/
getVertexId(vertexOrId: V | VertexId): VertexId;
abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
abstract removeEdge(edge: E): E | null;
_getVertex(vertexOrId: VertexId | V): V | null;
getVertex(vertexId: VertexId): V | null;
_getVertexId(vertexOrId: V | VertexId): VertexId;
/**

@@ -50,14 +56,4 @@ * The function checks if a vertex exists in a graph.

hasVertex(vertexOrId: V | VertexId): boolean;
/**
* The function `vertexSet()` returns a map of vertices.
* @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
*/
vertexSet(): Map<VertexId, V>;
abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
/**
* The addVertex function adds a new vertex to a graph if it does not already exist.
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
* false. Otherwise, it will add the newVertex to the graph and return true.
*/
abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
createAddVertex(id: VertexId, val?: V['val']): boolean;
addVertex(newVertex: V): boolean;

@@ -92,2 +88,3 @@ /**

hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E['val']): boolean;
abstract addEdge(edge: E): boolean;

@@ -170,13 +167,4 @@ /**

/**
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
*/
/**
* Dijkstra algorithm time: O(logVE) space: O(V + E)
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
*/
/**
* Dijkstra algorithm time: O(logVE) space: O(V + E)
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
* The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an

@@ -198,10 +186,13 @@ * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.

dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
abstract getEndsOfEdge(edge: E): [V, V] | null;
/**
* BellmanFord time:O(VE) space:O(V)
* one to rest pairs
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
*/
/**
* Dijkstra algorithm time: O(logVE) space: O(V + E)
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
*/
abstract getEndsOfEdge(edge: E): [V, V] | null;
/**
* BellmanFord time:O(VE) space:O(V)

@@ -231,5 +222,6 @@ * one to rest pairs

/**
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
* all pairs
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
* BellmanFord time:O(VE) space:O(V)
* one to rest pairs
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
*/

@@ -251,4 +243,8 @@ /**

};
/**--- start find cycles --- */
/**
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
* all pairs
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
*/
/**
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.

@@ -282,2 +278,4 @@ * Tarjan can find cycles in directed or undirected graph

};
/**--- start find cycles --- */
protected _setVertices(value: Map<VertexId, V>): void;
}

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

var AbstractVertex = /** @class */ (function () {
function AbstractVertex(id) {
function AbstractVertex(id, val) {
this._id = id;
this._val = val;
}

@@ -64,2 +65,12 @@ Object.defineProperty(AbstractVertex.prototype, "id", {

});
Object.defineProperty(AbstractVertex.prototype, "val", {
get: function () {
return this._val;
},
set: function (value) {
this._val = value;
},
enumerable: false,
configurable: true
});
return AbstractVertex;

@@ -69,11 +80,17 @@ }());

var AbstractEdge = /** @class */ (function () {
/**
* The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
* no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
*/
function AbstractEdge(weight) {
function AbstractEdge(weight, val) {
this._weight = weight !== undefined ? weight : 1;
this._val = val;
this._hashCode = (0, utils_1.uuidV4)();
}
Object.defineProperty(AbstractEdge.prototype, "val", {
get: function () {
return this._val;
},
set: function (value) {
this._val = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AbstractEdge.prototype, "weight", {

@@ -96,2 +113,11 @@ get: function () {

});
// /**
// * 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.
// * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
// * @param srcOrV1
// * @param destOrV2
// * @param weight
// * @param val
// */
// abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
AbstractEdge.prototype._setHashCode = function (v) {

@@ -111,21 +137,17 @@ this._hashCode = v;

}
/**
* The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
* does not exist.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
* If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
*/
AbstractGraph.prototype.getVertex = function (vertexOrId) {
var vertexId = this.getVertexId(vertexOrId);
Object.defineProperty(AbstractGraph.prototype, "vertices", {
get: function () {
return this._vertices;
},
enumerable: false,
configurable: true
});
AbstractGraph.prototype._getVertex = function (vertexOrId) {
var vertexId = this._getVertexId(vertexOrId);
return this._vertices.get(vertexId) || null;
};
/**
* The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
* a `VertexId`.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns the id of the vertex.
*/
AbstractGraph.prototype.getVertexId = function (vertexOrId) {
AbstractGraph.prototype.getVertex = function (vertexId) {
return this._vertices.get(vertexId) || null;
};
AbstractGraph.prototype._getVertexId = function (vertexOrId) {
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;

@@ -140,20 +162,12 @@ };

AbstractGraph.prototype.hasVertex = function (vertexOrId) {
return this._vertices.has(this.getVertexId(vertexOrId));
return this._vertices.has(this._getVertexId(vertexOrId));
};
/**
* The function `vertexSet()` returns a map of vertices.
* @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
*/
AbstractGraph.prototype.vertexSet = function () {
return this._vertices;
AbstractGraph.prototype.createAddVertex = function (id, val) {
var newVertex = this._createVertex(id, val);
return this.addVertex(newVertex);
};
/**
* The addVertex function adds a new vertex to a graph if it does not already exist.
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
* false. Otherwise, it will add the newVertex to the graph and return true.
*/
AbstractGraph.prototype.addVertex = function (newVertex) {
if (this.hasVertex(newVertex)) {
return false;
// throw (new Error('Duplicated vertex id is not allowed'));
}

@@ -170,3 +184,3 @@ this._vertices.set(newVertex.id, newVertex);

AbstractGraph.prototype.removeVertex = function (vertexOrId) {
var vertexId = this.getVertexId(vertexOrId);
var vertexId = this._getVertexId(vertexOrId);
return this._vertices.delete(vertexId);

@@ -212,2 +226,10 @@ };

};
AbstractGraph.prototype.createAddEdge = function (src, dest, weight, val) {
if (src instanceof AbstractVertex)
src = src.id;
if (dest instanceof AbstractVertex)
dest = dest.id;
var newEdge = this._createEdge(src, dest, weight, val);
return this.addEdge(newEdge);
};
/**

@@ -246,4 +268,4 @@ * The function sets the weight of an edge between two vertices in a graph.

var paths = [];
var vertex1 = this.getVertex(v1);
var vertex2 = this.getVertex(v2);
var vertex1 = this._getVertex(v1);
var vertex2 = this._getVertex(v2);
if (!(vertex1 && vertex2)) {

@@ -335,4 +357,4 @@ return [];

// BFS
var vertex2 = this.getVertex(v2);
var vertex1 = this.getVertex(v1);
var vertex2 = this._getVertex(v2);
var vertex1 = this._getVertex(v1);
if (!(vertex1 && vertex2)) {

@@ -422,4 +444,4 @@ return null;

var minPath_1 = [];
var vertex1_1 = this.getVertex(v1);
var vertex2 = this.getVertex(v2);
var vertex1_1 = this._getVertex(v1);
var vertex2 = this._getVertex(v2);
if (!(vertex1_1 && vertex2)) {

@@ -495,4 +517,4 @@ return [];

var preMap = new Map(); // predecessor
var srcVertex = this.getVertex(src);
var destVertex = dest ? this.getVertex(dest) : null;
var srcVertex = this._getVertex(src);
var destVertex = dest ? this._getVertex(dest) : null;
if (!srcVertex) {

@@ -625,13 +647,4 @@ return null;

/**
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
*/
/**
* Dijkstra algorithm time: O(logVE) space: O(V + E)
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
*/
/**
* Dijkstra algorithm time: O(logVE) space: O(V + E)
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
* The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an

@@ -669,4 +682,4 @@ * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.

var preMap = new Map(); // predecessor
var srcVertex = this.getVertex(src);
var destVertex = dest ? this.getVertex(dest) : null;
var srcVertex = this._getVertex(src);
var destVertex = dest ? this._getVertex(dest) : null;
if (!srcVertex) {

@@ -788,8 +801,2 @@ return null;

* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
*/
/**
* BellmanFord time:O(VE) space:O(V)
* one to rest pairs
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.

@@ -812,3 +819,3 @@ * @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will

genPath = false;
var srcVertex = this.getVertex(src);
var srcVertex = this._getVertex(src);
var paths = [];

@@ -904,5 +911,6 @@ var distMap = new Map();

/**
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
* all pairs
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
* BellmanFord time:O(VE) space:O(V)
* one to rest pairs
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
*/

@@ -951,4 +959,8 @@ /**

};
/**--- start find cycles --- */
/**
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
* all pairs
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
*/
/**
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.

@@ -1080,4 +1092,8 @@ * Tarjan can find cycles in directed or undirected graph

};
/**--- start find cycles --- */
AbstractGraph.prototype._setVertices = function (value) {
this._vertices = value;
};
return AbstractGraph;
}());
exports.AbstractGraph = AbstractGraph;
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
import type { IDirectedGraph, VertexId } from '../types';
export declare class DirectedVertex extends AbstractVertex {
import type { VertexId } from '../types';
import { IDirectedGraph } from '../interfaces';
export declare class DirectedVertex<T = number> extends AbstractVertex<T> {
/**
* The constructor function initializes an object with a given id.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
* vertex within a graph or network.
* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
* typically a unique identifier for each vertex in a graph.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to specify the value
* associated with the vertex.
*/
constructor(id: VertexId);
constructor(id: VertexId, val?: T);
}
export declare class DirectedEdge extends AbstractEdge {
export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
/**
* The constructor function initializes the source and destination vertices of an edge, with an optional weight.
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
* and value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex. It represents the vertex
* to which an edge is directed.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
* between two vertices.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
* If the weight is not provided, it will default to `undefined`.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
* the edge.
*/
constructor(src: VertexId, dest: VertexId, weight?: number);
constructor(src: VertexId, dest: VertexId, weight?: number, val?: T);
private _src;

@@ -29,40 +35,61 @@ get src(): VertexId;

}
export declare class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
protected _outEdgeMap: Map<V, E[]>;
protected _inEdgeMap: Map<V, E[]>;
constructor();
export declare class DirectedGraph<V extends DirectedVertex<any>, E extends DirectedEdge<any>> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
private readonly _vertexConstructor;
private readonly _edgeConstructor;
constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
private _outEdgeMap;
get outEdgeMap(): Map<V, E[]>;
private _inEdgeMap;
get inEdgeMap(): Map<V, E[]>;
/**
* The function `getEdge` returns the first edge between two vertices, given their source and destination.
* @param {V | null | VertexId} srcOrId - The `srcOrId` parameter can be either a vertex object (`V`), a vertex ID
* (`VertexId`), or `null`. It represents the source vertex of the edge.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter is either a vertex object (`V`), a vertex ID
* (`VertexId`), or `null`. It represents the destination vertex of the edge.
* @returns an edge (E) or null.
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param val
*/
_createVertex(id: VertexId, val?: V['val']): V;
/**
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param src
* @param dest
* @param weight
* @param val
*/
_createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
/**
* The function `getEdge` returns the directed edge between two vertices, given their source and destination.
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
* DirectedVertex object or a VertexId.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
* ID. It can be either a `DirectedVertex` object or a `VertexId` value.
* @returns a E object or null.
*/
getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
/**
* The `addEdge` function adds an edge to a graph if the source and destination vertices exist.
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in the graph. It contains
* information about the source vertex (`src`) and the destination vertex (`dest`) of the edge.
* @returns The `addEdge` function returns a boolean value. It returns `true` if the edge was successfully added to the
* graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
* The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
* @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
* contains two properties:
* @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
* graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
*/
addEdge(edge: E): boolean;
/**
* The function removes an edge between two vertices in a directed graph and returns the removed edge.
* @param {V | VertexId} srcOrId - The source vertex or its ID.
* @param {V | VertexId} destOrId - The `destOrId` parameter in the `removeEdgeBetween` function represents the
* destination vertex of the edge that needs to be removed. It can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if the edge between the source and
* destination vertices is successfully removed. If either the source or destination vertex is not found, or if the
* edge does not exist, it returns `null`.
* The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
* edge, or null if the edge was not found.
* @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
* object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
* edge that you want to remove. It can be either a `V` object or a `VertexId` value.
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
* the edge does not exist.
*/
removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
/**
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
* found.
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
* and `dest`, which represent the source and destination vertices of the edge, respectively.
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
* The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
* not found.
* @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
* graph. It has two properties:
* @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
* if no edge is removed.
*/

@@ -72,32 +99,34 @@ removeEdge(edge: E): E | null;

* The function removeAllEdges removes all edges between two vertices.
* @param {VertexId | V} src - The `src` parameter represents the source vertex from which the edges will be removed.
* It can be either a `VertexId` or a `V` type, which represents the identifier or object of the vertex.
* @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It can be either a
* `VertexId` or a vertex object `V`.
* @returns An empty array is being returned.
* @param {VertexId | V} src - The `src` parameter can be either a `VertexId` or a `V`.
* @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It
* can be either a `VertexId` or a `V`.
* @returns An empty array of DirectedEdge objects is being returned.
*/
removeAllEdges(src: VertexId | V, dest: VertexId | V): E[];
/**
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
* The function returns an array of incoming edges of a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
* object or a `VertexId`.
* @returns The method `incomingEdgesOf` returns an array of `E` objects.
*/
incomingEdgesOf(vertexOrId: V | VertexId): E[];
/**
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns The method `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
* object or a `VertexId`.
* @returns The method `outgoingEdgesOf` returns an array of `E` objects.
*/
outgoingEdgesOf(vertexOrId: V | VertexId): E[];
/**
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns the sum of the out-degree and in-degree of the specified vertex or vertex ID.
* The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
* and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
*/
degreeOf(vertexOrId: VertexId | V): number;
/**
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns The number of incoming edges of the specified vertex or vertex ID.

@@ -107,4 +136,5 @@ */

/**
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns The number of outgoing edges from the specified vertex or vertex ID.

@@ -114,58 +144,59 @@ */

/**
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns The function `edgesOf` returns an array of edges.
* The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns an array of directed edges.
*/
edgesOf(vertexOrId: VertexId | V): E[];
/**
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
* @param {E} e - E - an edge object
* @returns the source vertex of the given edge, or null if the edge does not exist.
* The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
* @param e - A directed edge object of type E.
* @returns either a DirectedVertex object or null.
*/
getEdgeSrc(e: E): V | null;
/**
* The function "getEdgeDest" returns the vertex associated with the destination of an edge.
* @param {E} e - The parameter `e` is of type `E`, which represents an edge in a graph.
* @returns either a vertex object (of type V) or null.
* The function "getEdgeDest" returns the destination vertex of a directed edge.
* @param e - E - This is an object representing a directed edge in a graph. It contains information
* about the source vertex, destination vertex, and any associated data.
* @returns either a DirectedVertex object or null.
*/
getEdgeDest(e: E): V | null;
/**
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexId` (which is a unique identifier for a vertex), or
* `null` if we want to find destinations from all vertices.
* @returns an array of vertices (V[]).
* The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
* from a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
* @returns an array of DirectedVertex objects.
*/
getDestinations(vertex: V | VertexId | null): V[];
/**--- start find cycles --- */
/**
* when stored with adjacency list time: O(V+E)
* when stored with adjacency matrix time: O(V^2)
* The `topologicalSort` function performs a topological sort on a graph and returns the sorted vertices in reverse
* order, or null if the graph contains a cycle.
* @returns The function `topologicalSort()` returns an array of vertices in topological order if there is no cycle in
* the graph. If there is a cycle, it returns `null`.
* The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
* reverse order, or null if the graph contains a cycle.
* @returns The function `topologicalSort()` returns an array of `V` or `VertexId` objects in
* topological order, or `null` if there is a cycle in the graph.
*/
topologicalSort(): Array<V | VertexId> | null;
/**--- end find cycles --- */
/**
* The `edgeSet` function returns an array of all the edges in the graph.
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
* The `edgeSet` function returns an array of all directed edges in the graph.
* @returns The `edgeSet()` method returns an array of `E` objects.
*/
edgeSet(): E[];
/**--- start find cycles --- */
/**
* The function `getNeighbors` returns an array of neighboring vertices for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns an array of vertices (V[]).
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
* object or a `VertexId`.
* @returns an array of DirectedVertex objects.
*/
getNeighbors(vertexOrId: V | VertexId): V[];
/**--- end find cycles --- */
/**
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
* otherwise it returns null.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns an array containing two vertices [V, V] if the edge is found in the graph. If the edge is not found, it
* returns null.
* The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
* graph, otherwise it returns null.
* @param edge - A directed edge object with a generic type E.
* @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
* not exist in the graph.
*/
getEndsOfEdge(edge: E): [V, V] | null;
protected _setOutEdgeMap(value: Map<V, E[]>): void;
protected _setInEdgeMap(value: Map<V, E[]>): void;
}

@@ -67,8 +67,10 @@ "use strict";

/**
* The constructor function initializes an object with a given id.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
* vertex within a graph or network.
* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
* typically a unique identifier for each vertex in a graph.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to specify the value
* associated with the vertex.
*/
function DirectedVertex(id) {
return _super.call(this, id) || this;
function DirectedVertex(id, val) {
return _super.call(this, id, val) || this;
}

@@ -81,12 +83,15 @@ return DirectedVertex;

/**
* The constructor function initializes the source and destination vertices of an edge, with an optional weight.
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
* and value.
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
* a graph.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex. It represents the vertex
* to which an edge is directed.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
* between two vertices.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
* If the weight is not provided, it will default to `undefined`.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
* the edge.
*/
function DirectedEdge(src, dest, weight) {
var _this = _super.call(this, weight) || this;
function DirectedEdge(src, dest, weight, val) {
var _this = _super.call(this, weight, val) || this;
_this._src = src;

@@ -122,21 +127,59 @@ _this._dest = dest;

__extends(DirectedGraph, _super);
function DirectedGraph() {
function DirectedGraph(vertexConstructor, edgeConstructor) {
var _this = _super.call(this) || this;
_this._outEdgeMap = new Map();
_this._inEdgeMap = new Map();
_this._vertexConstructor = vertexConstructor;
_this._edgeConstructor = edgeConstructor;
return _this;
}
Object.defineProperty(DirectedGraph.prototype, "outEdgeMap", {
get: function () {
return this._outEdgeMap;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DirectedGraph.prototype, "inEdgeMap", {
get: function () {
return this._inEdgeMap;
},
enumerable: false,
configurable: true
});
/**
* The function `getEdge` returns the first edge between two vertices, given their source and destination.
* @param {V | null | VertexId} srcOrId - The `srcOrId` parameter can be either a vertex object (`V`), a vertex ID
* (`VertexId`), or `null`. It represents the source vertex of the edge.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter is either a vertex object (`V`), a vertex ID
* (`VertexId`), or `null`. It represents the destination vertex of the edge.
* @returns an edge (E) or null.
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param val
*/
DirectedGraph.prototype._createVertex = function (id, val) {
return new this._vertexConstructor(id, val);
};
/**
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param src
* @param dest
* @param weight
* @param val
*/
DirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
if (weight === undefined || weight === null)
weight = 1;
return new this._edgeConstructor(src, dest, weight, val);
};
/**
* The function `getEdge` returns the directed edge between two vertices, given their source and destination.
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
* DirectedVertex object or a VertexId.
* @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
* ID. It can be either a `DirectedVertex` object or a `VertexId` value.
* @returns a E object or null.
*/
DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
var edges = [];
if (srcOrId !== null && destOrId !== null) {
var src = this.getVertex(srcOrId);
var dest_1 = this.getVertex(destOrId);
var src = this._getVertex(srcOrId);
var dest_1 = this._getVertex(destOrId);
if (src && dest_1) {

@@ -152,7 +195,7 @@ var srcOutEdges = this._outEdgeMap.get(src);

/**
* The `addEdge` function adds an edge to a graph if the source and destination vertices exist.
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in the graph. It contains
* information about the source vertex (`src`) and the destination vertex (`dest`) of the edge.
* @returns The `addEdge` function returns a boolean value. It returns `true` if the edge was successfully added to the
* graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
* The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
* @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
* contains two properties:
* @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
* graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
*/

@@ -163,4 +206,4 @@ DirectedGraph.prototype.addEdge = function (edge) {

}
var srcVertex = this.getVertex(edge.src);
var destVertex = this.getVertex(edge.dest);
var srcVertex = this._getVertex(edge.src);
var destVertex = this._getVertex(edge.dest);
// TODO after no-non-null-assertion not ensure the logic

@@ -189,14 +232,14 @@ if (srcVertex && destVertex) {

/**
* The function removes an edge between two vertices in a directed graph and returns the removed edge.
* @param {V | VertexId} srcOrId - The source vertex or its ID.
* @param {V | VertexId} destOrId - The `destOrId` parameter in the `removeEdgeBetween` function represents the
* destination vertex of the edge that needs to be removed. It can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if the edge between the source and
* destination vertices is successfully removed. If either the source or destination vertex is not found, or if the
* edge does not exist, it returns `null`.
* The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
* edge, or null if the edge was not found.
* @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
* object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
* edge that you want to remove. It can be either a `V` object or a `VertexId` value.
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
* the edge does not exist.
*/
DirectedGraph.prototype.removeEdgeBetween = function (srcOrId, destOrId) {
var src = this.getVertex(srcOrId);
var dest = this.getVertex(destOrId);
var src = this._getVertex(srcOrId);
var dest = this._getVertex(destOrId);
var removed = null;

@@ -225,12 +268,13 @@ if (!src || !dest) {

/**
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
* found.
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
* and `dest`, which represent the source and destination vertices of the edge, respectively.
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
* The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
* not found.
* @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
* graph. It has two properties:
* @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
* if no edge is removed.
*/
DirectedGraph.prototype.removeEdge = function (edge) {
var removed = null;
var src = this.getVertex(edge.src);
var dest = this.getVertex(edge.dest);
var src = this._getVertex(edge.src);
var dest = this._getVertex(edge.dest);
if (src && dest) {

@@ -250,7 +294,6 @@ var srcOutEdges = this._outEdgeMap.get(src);

* The function removeAllEdges removes all edges between two vertices.
* @param {VertexId | V} src - The `src` parameter represents the source vertex from which the edges will be removed.
* It can be either a `VertexId` or a `V` type, which represents the identifier or object of the vertex.
* @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It can be either a
* `VertexId` or a vertex object `V`.
* @returns An empty array is being returned.
* @param {VertexId | V} src - The `src` parameter can be either a `VertexId` or a `V`.
* @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It
* can be either a `VertexId` or a `V`.
* @returns An empty array of DirectedEdge objects is being returned.
*/

@@ -261,11 +304,11 @@ DirectedGraph.prototype.removeAllEdges = function (src, dest) {

/**
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
* The function returns an array of incoming edges of a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
* object or a `VertexId`.
* @returns The method `incomingEdgesOf` returns an array of `E` objects.
*/
DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
var target = this.getVertex(vertexOrId);
var target = this._getVertex(vertexOrId);
if (target) {
return this._inEdgeMap.get(target) || [];
return this.inEdgeMap.get(target) || [];
}

@@ -275,9 +318,9 @@ return [];

/**
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns The method `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
* The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
* object or a `VertexId`.
* @returns The method `outgoingEdgesOf` returns an array of `E` objects.
*/
DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
var target = this.getVertex(vertexOrId);
var target = this._getVertex(vertexOrId);
if (target) {

@@ -289,5 +332,7 @@ return this._outEdgeMap.get(target) || [];

/**
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns the sum of the out-degree and in-degree of the specified vertex or vertex ID.
* The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
* and in-degree.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
*/

@@ -298,4 +343,5 @@ DirectedGraph.prototype.degreeOf = function (vertexOrId) {

/**
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns The number of incoming edges of the specified vertex or vertex ID.

@@ -307,4 +353,5 @@ */

/**
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns The number of outgoing edges from the specified vertex or vertex ID.

@@ -316,5 +363,6 @@ */

/**
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns The function `edgesOf` returns an array of edges.
* The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
* `V`.
* @returns an array of directed edges.
*/

@@ -325,23 +373,23 @@ DirectedGraph.prototype.edgesOf = function (vertexOrId) {

/**
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
* @param {E} e - E - an edge object
* @returns the source vertex of the given edge, or null if the edge does not exist.
* The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
* @param e - A directed edge object of type E.
* @returns either a DirectedVertex object or null.
*/
DirectedGraph.prototype.getEdgeSrc = function (e) {
return this.getVertex(e.src);
return this._getVertex(e.src);
};
/**
* The function "getEdgeDest" returns the vertex associated with the destination of an edge.
* @param {E} e - The parameter `e` is of type `E`, which represents an edge in a graph.
* @returns either a vertex object (of type V) or null.
* The function "getEdgeDest" returns the destination vertex of a directed edge.
* @param e - E - This is an object representing a directed edge in a graph. It contains information
* about the source vertex, destination vertex, and any associated data.
* @returns either a DirectedVertex object or null.
*/
DirectedGraph.prototype.getEdgeDest = function (e) {
return this.getVertex(e.dest);
return this._getVertex(e.dest);
};
/**
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
* find the destinations. It can be either a `V` object, a `VertexId` (which is a unique identifier for a vertex), or
* `null` if we want to find destinations from all vertices.
* @returns an array of vertices (V[]).
* The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
* from a given vertex.
* @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
* @returns an array of DirectedVertex objects.
*/

@@ -373,10 +421,7 @@ DirectedGraph.prototype.getDestinations = function (vertex) {

};
/**--- start find cycles --- */
/**
* when stored with adjacency list time: O(V+E)
* when stored with adjacency matrix time: O(V^2)
* The `topologicalSort` function performs a topological sort on a graph and returns the sorted vertices in reverse
* order, or null if the graph contains a cycle.
* @returns The function `topologicalSort()` returns an array of vertices in topological order if there is no cycle in
* the graph. If there is a cycle, it returns `null`.
* The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
* reverse order, or null if the graph contains a cycle.
* @returns The function `topologicalSort()` returns an array of `V` or `VertexId` objects in
* topological order, or `null` if there is a cycle in the graph.
*/

@@ -390,3 +435,3 @@ DirectedGraph.prototype.topologicalSort = function () {

try {
for (var _c = __values(this._vertices), _d = _c.next(); !_d.done; _d = _c.next()) {
for (var _c = __values(this.vertices), _d = _c.next(); !_d.done; _d = _c.next()) {
var entry = _d.value;

@@ -432,3 +477,3 @@ statusMap.set(entry[1], 0);

try {
for (var _e = __values(this._vertices), _f = _e.next(); !_f.done; _f = _e.next()) {
for (var _e = __values(this.vertices), _f = _e.next(); !_f.done; _f = _e.next()) {
var entry = _f.value;

@@ -451,6 +496,5 @@ if (statusMap.get(entry[1]) === 0) {

};
/**--- end find cycles --- */
/**
* The `edgeSet` function returns an array of all the edges in the graph.
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
* The `edgeSet` function returns an array of all directed edges in the graph.
* @returns The `edgeSet()` method returns an array of `E` objects.
*/

@@ -464,7 +508,8 @@ DirectedGraph.prototype.edgeSet = function () {

};
/**--- start find cycles --- */
/**
* The function `getNeighbors` returns an array of neighboring vertices for a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns an array of vertices (V[]).
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
* object or a `VertexId`.
* @returns an array of DirectedVertex objects.
*/

@@ -474,3 +519,3 @@ DirectedGraph.prototype.getNeighbors = function (vertexOrId) {

var neighbors = [];
var vertex = this.getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrId);
if (vertex) {

@@ -481,3 +526,3 @@ var outEdges = this.outgoingEdgesOf(vertex);

var outEdge = outEdges_1_1.value;
var neighbor = this.getVertex(outEdge.dest);
var neighbor = this._getVertex(outEdge.dest);
// TODO after no-non-null-assertion not ensure the logic

@@ -499,8 +544,9 @@ if (neighbor) {

};
/**--- end find cycles --- */
/**
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
* otherwise it returns null.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns an array containing two vertices [V, V] if the edge is found in the graph. If the edge is not found, it
* returns null.
* The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
* graph, otherwise it returns null.
* @param edge - A directed edge object with a generic type E.
* @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
* not exist in the graph.
*/

@@ -511,4 +557,4 @@ DirectedGraph.prototype.getEndsOfEdge = function (edge) {

}
var v1 = this.getVertex(edge.src);
var v2 = this.getVertex(edge.dest);
var v1 = this._getVertex(edge.src);
var v2 = this._getVertex(edge.dest);
if (v1 && v2) {

@@ -521,4 +567,10 @@ return [v1, v2];

};
DirectedGraph.prototype._setOutEdgeMap = function (value) {
this._outEdgeMap = value;
};
DirectedGraph.prototype._setInEdgeMap = function (value) {
this._inEdgeMap = value;
};
return DirectedGraph;
}(abstract_graph_1.AbstractGraph));
exports.DirectedGraph = DirectedGraph;
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
import type { VertexId } from '../types';
export declare class UndirectedVertex extends AbstractVertex {
export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
/**
* The constructor function initializes an object with a given id.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
* vertex within a graph or network.
* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
* typically a unique identifier for each vertex in a graph.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
* vertex. If no value is provided, the vertex will be initialized with a default value.
*/
constructor(id: VertexId);
constructor(id: VertexId, val?: T);
}
export declare class UndirectedEdge extends AbstractEdge {
export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
/**
* The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
* The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
* value.
* @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
* graph.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
* between two vertices.
* graph edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
* the edge.
*/
constructor(v1: VertexId, v2: VertexId, weight?: number);
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
private _vertices;
get vertices(): [VertexId, VertexId];
set vertices(v: [VertexId, VertexId]);
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
*/
getVertices(): [VertexId, VertexId];
}
export declare class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
constructor();
export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends UndirectedEdge<any>> extends AbstractGraph<V, E> {
private readonly _vertexConstructor;
private readonly _edgeConstructor;
constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
protected _edges: Map<V, E[]>;
get edges(): Map<V, E[]>;
/**
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID
* (`VertexId`). It can also be `null`.
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (vertex ID).
* @returns an edge (E) or null.
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param val
*/
_createVertex(id: VertexId, val?: V['val']): V;
/**
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param src
* @param dest
* @param weight
* @param val
*/
_createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
/**
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
* exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
* object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
* @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
* object or a `VertexId` (identifier) of an undirected vertex.
* @returns an instance of `E` or `null`.
*/
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
/**
* The function adds an edge to a graph by connecting two vertices.
* @param {E} edge - The `edge` parameter is an object of type `E`, which represents an edge in a graph.
* The function adds an undirected edge to a graph by updating the adjacency list.
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
* array of two vertices connected by the edge.
* @returns a boolean value.

@@ -49,57 +69,60 @@ */

/**
* The function removes an edge between two vertices in a graph and returns the removed edge, or null if either of the
* vertices does not exist.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId: The second vertex or vertex ID of the edge to be removed.
* @returns the removed edge (E) if it exists, or null if either of the vertices (v1 or v2) does not exist.
* The function removes an edge between two vertices in an undirected graph.
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
* a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
* @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
* `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
* removed.
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
* between them, the function returns `null`.
*/
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
/**
* The removeEdge function removes an edge between two vertices in a graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
* The removeEdge function removes an edge between two vertices in an undirected graph.
* @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
* containing the two vertices connected by the edge.
* @returns The method is returning an UndirectedEdge object or null.
*/
removeEdge(edge: E): E | null;
/**
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
* vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
* edges that are incident to that vertex.
* The function "degreeOf" returns the degree of a given vertex in an undirected graph.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
* `V`.
* @returns the degree of the vertex.
*/
degreeOf(vertexOrId: VertexId | V): number;
/**
* The function "edgesOf" returns an array of edges connected to a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns an array of edges connected to the specified vertex. If the vertex exists in the graph, the function
* returns the array of edges connected to that vertex. If the vertex does not exist in the graph, the function returns
* an empty array.
* The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
* `V`.
* @returns an array of UndirectedEdge objects.
*/
edgesOf(vertexOrId: VertexId | V): E[];
/**
* The function "edgeSet" returns an array of unique edges from a set of edges.
* @returns The method `edgeSet()` returns an array of type `E[]`.
* The function "edgeSet" returns an array of unique undirected edges from a set of edges.
* @returns The method `edgeSet()` returns an array of `E` objects.
*/
edgeSet(): E[];
/**
* The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns an array of edges (E[]) that are connected to the specified vertex or vertex ID.
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
* `V` object or a `VertexId`.
* @returns The function `getEdgesOf` returns an array of `E` objects.
*/
getEdgesOf(vertexOrId: V | VertexId): E[];
/**
* The function "getNeighbors" returns an array of neighboring vertices of a given vertex.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns an array of vertices (V[]).
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
* `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
* @returns an array of UndirectedVertex objects.
*/
getNeighbors(vertexOrId: V | VertexId): V[];
/**
* The function "getEndsOfEdge" returns the vertices at the ends of a given edge, or null if the edge does not exist in
* the graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
* graph and both vertices are found. If the edge does not exist or one or both vertices are not found, it returns
* `null`.
* The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
* edge does not exist in the graph.
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
* array containing two vertices that the edge connects.
* @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
* exists in the graph. If the edge does not exist, it returns `null`.
*/

@@ -106,0 +129,0 @@ getEndsOfEdge(edge: E): [V, V] | null;

@@ -67,8 +67,10 @@ "use strict";

/**
* The constructor function initializes an object with a given id.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
* vertex within a graph or network.
* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
* typically a unique identifier for each vertex in a graph.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
* vertex. If no value is provided, the vertex will be initialized with a default value.
*/
function UndirectedVertex(id) {
return _super.call(this, id) || this;
function UndirectedVertex(id, val) {
return _super.call(this, id, val) || this;
}

@@ -81,11 +83,13 @@ return UndirectedVertex;

/**
* The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
* The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
* value.
* @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
* graph.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
* between two vertices.
* graph edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
* the edge.
*/
function UndirectedEdge(v1, v2, weight) {
var _this = _super.call(this, weight) || this;
function UndirectedEdge(v1, v2, weight, val) {
var _this = _super.call(this, weight, val) || this;
_this._vertices = [v1, v2];

@@ -104,8 +108,2 @@ return _this;

});
/**
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
*/
UndirectedEdge.prototype.getVertices = function () {
return this._vertices;
};
return UndirectedEdge;

@@ -116,4 +114,6 @@ }(abstract_graph_1.AbstractEdge));

__extends(UndirectedGraph, _super);
function UndirectedGraph() {
function UndirectedGraph(vertexConstructor, edgeConstructor) {
var _this = _super.call(this) || this;
_this._vertexConstructor = vertexConstructor;
_this._edgeConstructor = edgeConstructor;
_this._edges = new Map();

@@ -130,9 +130,32 @@ return _this;

/**
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID
* (`VertexId`). It can also be `null`.
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
* object), `null`, or `VertexId` (vertex ID).
* @returns an edge (E) or null.
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param id
* @param val
*/
UndirectedGraph.prototype._createVertex = function (id, val) {
return new this._vertexConstructor(id, val);
};
/**
* 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.
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
* @param src
* @param dest
* @param weight
* @param val
*/
UndirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
if (weight === undefined || weight === null)
weight = 1;
return new this._edgeConstructor(src, dest, weight, val);
};
/**
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
* exists.
* @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
* object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
* @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
* object or a `VertexId` (identifier) of an undirected vertex.
* @returns an instance of `E` or `null`.
*/
UndirectedGraph.prototype.getEdge = function (v1, v2) {

@@ -142,4 +165,4 @@ var _a;

if (v1 !== null && v2 !== null) {
var vertex1 = this.getVertex(v1);
var vertex2_1 = this.getVertex(v2);
var vertex1 = this._getVertex(v1);
var vertex2_1 = this._getVertex(v2);
if (vertex1 && vertex2_1) {

@@ -152,4 +175,5 @@ edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.id); });

/**
* The function adds an edge to a graph by connecting two vertices.
* @param {E} edge - The `edge` parameter is an object of type `E`, which represents an edge in a graph.
* The function adds an undirected edge to a graph by updating the adjacency list.
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
* array of two vertices connected by the edge.
* @returns a boolean value.

@@ -162,3 +186,3 @@ */

var end = _c.value;
var endVertex = this.getVertex(end);
var endVertex = this._getVertex(end);
if (endVertex === null)

@@ -187,11 +211,15 @@ return false;

/**
* The function removes an edge between two vertices in a graph and returns the removed edge, or null if either of the
* vertices does not exist.
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
* @param {V | VertexId} v2 - V | VertexId: The second vertex or vertex ID of the edge to be removed.
* @returns the removed edge (E) if it exists, or null if either of the vertices (v1 or v2) does not exist.
* The function removes an edge between two vertices in an undirected graph.
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
* a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
* @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
* `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
* removed.
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
* between them, the function returns `null`.
*/
UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
var vertex1 = this.getVertex(v1);
var vertex2 = this.getVertex(v2);
var vertex1 = this._getVertex(v1);
var vertex2 = this._getVertex(v2);
if (!vertex1 || !vertex2) {

@@ -212,5 +240,6 @@ return null;

/**
* The removeEdge function removes an edge between two vertices in a graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
* The removeEdge function removes an edge between two vertices in an undirected graph.
* @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
* containing the two vertices connected by the edge.
* @returns The method is returning an UndirectedEdge object or null.
*/

@@ -221,11 +250,10 @@ UndirectedGraph.prototype.removeEdge = function (edge) {

/**
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
* vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
* edges that are incident to that vertex.
* The function "degreeOf" returns the degree of a given vertex in an undirected graph.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
* `V`.
* @returns the degree of the vertex.
*/
UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
var _a;
var vertex = this.getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrId);
if (vertex) {

@@ -239,10 +267,9 @@ return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;

/**
* The function "edgesOf" returns an array of edges connected to a given vertex.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
* @returns an array of edges connected to the specified vertex. If the vertex exists in the graph, the function
* returns the array of edges connected to that vertex. If the vertex does not exist in the graph, the function returns
* an empty array.
* The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
* `V`.
* @returns an array of UndirectedEdge objects.
*/
UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
var vertex = this.getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrId);
if (vertex) {

@@ -256,4 +283,4 @@ return this._edges.get(vertex) || [];

/**
* The function "edgeSet" returns an array of unique edges from a set of edges.
* @returns The method `edgeSet()` returns an array of type `E[]`.
* The function "edgeSet" returns an array of unique undirected edges from a set of edges.
* @returns The method `edgeSet()` returns an array of `E` objects.
*/

@@ -270,9 +297,9 @@ UndirectedGraph.prototype.edgeSet = function () {

/**
* The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns an array of edges (E[]) that are connected to the specified vertex or vertex ID.
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
* `V` object or a `VertexId`.
* @returns The function `getEdgesOf` returns an array of `E` objects.
*/
UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
var vertex = this.getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrId);
if (!vertex) {

@@ -284,6 +311,6 @@ return [];

/**
* The function "getNeighbors" returns an array of neighboring vertices of a given vertex.
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
* (`VertexId`).
* @returns an array of vertices (V[]).
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
* `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
* @returns an array of UndirectedVertex objects.
*/

@@ -293,3 +320,3 @@ UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {

var neighbors = [];
var vertex = this.getVertex(vertexOrId);
var vertex = this._getVertex(vertexOrId);
if (vertex) {

@@ -300,3 +327,3 @@ var neighborEdges = this.getEdgesOf(vertex);

var edge = neighborEdges_1_1.value;
var neighbor = this.getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
var neighbor = this._getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
if (neighbor) {

@@ -318,8 +345,8 @@ neighbors.push(neighbor);

/**
* The function "getEndsOfEdge" returns the vertices at the ends of a given edge, or null if the edge does not exist in
* the graph.
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
* graph and both vertices are found. If the edge does not exist or one or both vertices are not found, it returns
* `null`.
* The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
* edge does not exist in the graph.
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
* array containing two vertices that the edge connects.
* @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
* exists in the graph. If the edge does not exist, it returns `null`.
*/

@@ -330,4 +357,4 @@ UndirectedGraph.prototype.getEndsOfEdge = function (edge) {

}
var v1 = this.getVertex(edge.vertices[0]);
var v2 = this.getVertex(edge.vertices[1]);
var v1 = this._getVertex(edge.vertices[0]);
var v2 = this._getVertex(edge.vertices[1]);
if (v1 && v2) {

@@ -334,0 +361,0 @@ return [v1, v2];

@@ -8,3 +8,3 @@ /**

*/
export declare class CoordinateSet extends Set {
export declare class CoordinateSet extends Set<any> {
constructor(joint?: string);

@@ -11,0 +11,0 @@ protected _joint: string;

@@ -12,2 +12,3 @@ export * from './hash';

export * from './trie';
export * from './interfaces';
export * from './types';

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

__exportStar(require("./trie"), exports);
__exportStar(require("./interfaces"), exports);
__exportStar(require("./types"), exports);

@@ -25,3 +25,3 @@ /**

}
export declare class DoublyLinkedList<T> {
export declare class DoublyLinkedList<T = number> {
/**

@@ -28,0 +28,0 @@ * The constructor initializes the linked list with an empty head, tail, and length.

@@ -22,3 +22,3 @@ /**

}
export declare class SinglyLinkedList<T> {
export declare class SinglyLinkedList<T = number> {
/**

@@ -25,0 +25,0 @@ * The constructor initializes the linked list with an empty head, tail, and length.

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

get nodes(): T[];
protected set nodes(value: T[]);
get size(): number;

@@ -116,2 +115,3 @@ /**

DFS(dfsMode: PriorityQueueDFSOrderPattern): (T | null)[];
protected _setNodes(value: T[]): void;
protected readonly _comparator: PriorityQueueComparator<T>;

@@ -118,0 +118,0 @@ /**

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

},
set: function (value) {
this._nodes = value;
},
enumerable: false,

@@ -171,3 +168,3 @@ configurable: true

PriorityQueue.prototype.clear = function () {
this.nodes = [];
this._setNodes([]);
};

@@ -261,2 +258,5 @@ /**

};
PriorityQueue.prototype._setNodes = function (value) {
this._nodes = value;
};
/**

@@ -263,0 +263,0 @@ * The function compares two numbers using a custom comparator function.

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

}
export declare class ObjectDeque<T> {
export declare class ObjectDeque<T = number> {
constructor(capacity?: number);

@@ -18,5 +18,2 @@ private _nodes;

};
protected set nodes(value: {
[p: number]: T;
});
private _capacity;

@@ -33,3 +30,2 @@ get capacity(): number;

get size(): number;
protected set size(value: number);
addFirst(value: T): void;

@@ -43,2 +39,6 @@ addLast(value: T): void;

isEmpty(): boolean;
protected _seNodes(value: {
[p: number]: T;
}): void;
protected _setSize(value: number): void;
}

@@ -45,0 +45,0 @@ export declare class ArrayDeque<T> {

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

},
set: function (value) {
this._nodes = value;
},
enumerable: false,

@@ -95,5 +92,2 @@ configurable: true

},
set: function (value) {
this._size = value;
},
enumerable: false,

@@ -158,2 +152,8 @@ configurable: true

};
ObjectDeque.prototype._seNodes = function (value) {
this._nodes = value;
};
ObjectDeque.prototype._setSize = function (value) {
this._size = value;
};
return ObjectDeque;

@@ -160,0 +160,0 @@ }());

@@ -6,3 +6,3 @@ /**

*/
export declare class Queue<T> {
export declare class Queue<T = number> {
protected _nodes: T[];

@@ -9,0 +9,0 @@ protected _offset: number;

@@ -6,3 +6,3 @@ /**

*/
export declare class Stack<T> {
export declare class Stack<T = number> {
protected _elements: T[];

@@ -9,0 +9,0 @@ /**

export type VertexId = string | number;
export type EdgeId = string;
export type DijkstraResult<V> = {

@@ -10,21 +11,1 @@ distMap: Map<V, number>;

} | null;
export interface IGraph<V, E> {
hasVertex(vertexOrId: V | VertexId): boolean;
getVertex(vertexOrId: VertexId | V): V | null;
getVertexId(vertexOrId: V | VertexId): VertexId;
vertexSet(): Map<VertexId, V>;
addVertex(v: V): boolean;
removeVertex(vertexOrId: V | VertexId): boolean;
removeAllVertices(vertices: V[] | VertexId[]): boolean;
degreeOf(vertexOrId: V | VertexId): number;
edgesOf(vertexOrId: V | VertexId): E[];
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
edgeSet(): E[];
addEdge(edge: E): boolean;
removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
removeEdge(edge: E): E | null;
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
getNeighbors(vertexOrId: V | VertexId): V[];
}
import { AVLTreeNode } from '../binary-tree';
export interface AVLTreeDeleted<T> {
deleted: AVLTreeNode<T> | null;
needBalanced: AVLTreeNode<T> | null;
}
export type AVLTreeDeleted<N> = {
deleted: N | null;
needBalanced: N | null;
};
export type RecursiveAVLTreeNode<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;

@@ -6,7 +6,8 @@ import { BinaryTreeNode } from '../binary-tree';

export type BinaryTreeNodeId = number;
export type BinaryTreeDeleted<T> = {
deleted: BinaryTreeNode<T> | null | undefined;
needBalanced: BinaryTreeNode<T> | null;
export type BinaryTreeDeleted<N> = {
deleted: N | null | undefined;
needBalanced: N | null;
};
export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
export type ResultsByProperty<T> = ResultByProperty<T>[];
export type ResultByProperty<N extends BinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
export type ResultsByProperty<N extends BinaryTreeNode<N['val'], N>> = ResultByProperty<N>[];
export type RecursiveBinaryTreeNode<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
import { BSTNode } from '../binary-tree';
import type { BinaryTreeNodeId } from './binary-tree';
export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
export type BSTDeletedResult<T> = {
deleted: BSTNode<T> | null;
needBalanced: BSTNode<T> | null;
export type BSTDeletedResult<N extends BSTNode<N['val'], N>> = {
deleted: N | null;
needBalanced: N | null;
};
export type RecursiveBSTNode<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;

@@ -1,10 +0,6 @@

import { VertexId } from './abstract-graph';
export interface IDirectedGraph<V, E> {
incomingEdgesOf(vertex: V): E[];
outgoingEdgesOf(vertex: V): E[];
inDegreeOf(vertexOrId: V | VertexId): number;
outDegreeOf(vertexOrId: V | VertexId): number;
getEdgeSrc(e: E): V | null;
getEdgeDest(e: E): V | null;
export type TopologicalStatus = 0 | 1 | 2;
export declare enum TopologicalProperty {
VAL = "VAL",
NODE = "NODE",
ID = "ID"
}
export type TopologicalStatus = 0 | 1 | 2;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TopologicalProperty = void 0;
var TopologicalProperty;
(function (TopologicalProperty) {
TopologicalProperty["VAL"] = "VAL";
TopologicalProperty["NODE"] = "NODE";
TopologicalProperty["ID"] = "ID";
})(TopologicalProperty || (exports.TopologicalProperty = TopologicalProperty = {}));

@@ -1,3 +0,3 @@

export interface HeapOptions<T> {
export type HeapOptions<T> = {
priority?: (element: T) => number;
}
};

@@ -13,2 +13,1 @@ export * from './binary-tree';

export * from './navigator';
export * from '../../utils/types/utils';

@@ -29,2 +29,1 @@ "use strict";

__exportStar(require("./navigator"), exports);
__exportStar(require("../../utils/types/utils"), exports);

@@ -5,3 +5,3 @@ export type Direction = 'up' | 'right' | 'down' | 'left';

};
export interface NavigatorParams<T> {
export type NavigatorParams<T> = {
matrix: T[][];

@@ -15,2 +15,2 @@ turning: Turning;

};
}
};
export type PriorityQueueComparator<T> = (a: T, b: T) => number;
export interface PriorityQueueOptions<T> {
export type PriorityQueueOptions<T> = {
nodes?: T[];
isFix?: boolean;
comparator: PriorityQueueComparator<T>;
}
};
export type PriorityQueueDFSOrderPattern = 'pre' | 'in' | 'post';

@@ -1,5 +0,4 @@

import { BSTNode } from '../binary-tree';
export type TreeMultiSetDeletedResult<T> = {
deleted: BSTNode<T> | null;
needBalanced: BSTNode<T> | null;
export type TreeMultiSetDeletedResult<N> = {
deleted: N | null;
needBalanced: N | null;
};

@@ -27,2 +27,9 @@ <table>

Before TypeScript v5.0, protected-modified member variables cannot be accessed within instances. However, starting from TypeScript v5.0, they can be accessed.
Prior to TypeScript v5.0, member variables' accessors (getters and setters) could have different access levels, but as of v5.0, only a uniform access level can be set for them.
Prior to TypeScript v5.0, member variables' accessors (getters and setters) could have different access levels, but as of v5.0, only a uniform access level can be set for them.
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.
type RecursiveBinaryTreeNode<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T,BinaryTreeNode<T,BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
type RecursiveBSTNode<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T,BSTNode<T,BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
type RecursiveAVLTreeNode<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T,AVLTreeNode<T,AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"name": "data-structure-typed",
"version": "1.18.0",
"version": "1.18.5",
"description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",

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

"Min Priority Queue",
"Trie"
"Trie",
"DFS",
"DFSIterative",
"BFS",
"morris",
"Bellman-Ford ",
"Dijkstra's Algorithm",
"Floyd-Warshall Algorithm",
"Tarjan's Algorithm"
],

@@ -44,0 +52,0 @@ "author": "Tyler Zeng zrwusa@gmail.com",

@@ -11,7 +11,197 @@ # What

Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed
Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack,
Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
<table>
<thead>
<tr>
<th>Data Structure</th>
<th>Unit Test</th>
<th>Performance Test</th>
<th>API Documentation</th>
<th>Implemented</th>
</tr>
</thead>
<tbody>
<tr>
<td>Binary Tree</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
</img></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
</img></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary Tree</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Binary Search Tree (BST)</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>AVL Tree</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Tree Multiset</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>TreeMultiSet</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Segment Tree</td>
<td></td>
<td></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>SegmentTree</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Binary Indexed Tree</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>BinaryIndexedTree</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Graph</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>AbstractGraph</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Directed Graph</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>DirectedGraph</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Undirected Graph</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>UndirectedGraph</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Linked List</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Singly Linked List</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Doubly Linked List</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>DoublyLinkedList</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Queue</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Object Deque</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>ObjectDeque</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Array Deque</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>ArrayDeque</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Stack</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
[//]: # (<tr>)
[//]: # (<td>Hash</td>)
[//]: # (<td></td>)
[//]: # (<td></td>)
[//]: # (<td><a href="https://data-structure-typed-docs.vercel.app/classes/HashTable.html"><span>HashTable</span></a></td>)
[//]: # (<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>)
[//]: # (</tr>)
<tr>
<td>Coordinate Set</td>
<td></td>
<td></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>CoordinateSet</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Coordinate Map</td>
<td></td>
<td></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>CoordinateMap</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Heap</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Priority Queue</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>PriorityQueue</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Max Priority Queue</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>MaxPriorityQueue</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Min Priority Queue</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>MinPriorityQueue</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
<tr>
<td>Trie</td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
<td></td>
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></td>
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
</tr>
</tbody>
</table>
## Algorithms list only a few out, you can discover more in API docs
DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
# How

@@ -413,66 +603,3 @@

[//]: # ([api docs]&#40;https://data-structure-typed-docs.vercel.app/&#41;)
<nav class="tsd-navigation"><a href="https://data-structure-typed-docs.vercel.app/modules.html" class="current"><span>data-<wbr/>structure-<wbr/>typed</span></a>
<ul class="tsd-small-nested-navigation">
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/CP.html"><span>CP</span></a></li>)
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/FamilyPosition.html"><span>Family<wbr/>Position</span></a></li>)
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/LoopType.html"><span>Loop<wbr/>Type</span></a></li>)
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTreeNode.html"><span>AVLTree<wbr/>Node</span></a></li>
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AaTree.html"><span>Aa<wbr/>Tree</span></a></li>)
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractEdge.html"><span>Abstract<wbr/>Edge</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>Abstract<wbr/>Graph</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractVertex.html"><span>Abstract<wbr/>Vertex</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>Array<wbr/>Deque</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BSTNode.html"><span>BSTNode</span></a></li>
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BTree.html"><span>BTree</span></a></li>)
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>Binary<wbr/>Indexed<wbr/>Tree</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary<wbr/>Tree</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTreeNode.html"><span>Binary<wbr/>Tree<wbr/>Node</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Character.html"><span>Character</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>Coordinate<wbr/>Map</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>Coordinate<wbr/>Set</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Deque.html"><span>Deque</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedEdge.html"><span>Directed<wbr/>Edge</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>Directed<wbr/>Graph</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedVertex.html"><span>Directed<wbr/>Vertex</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>Doubly<wbr/>Linked<wbr/>List</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedListNode.html"><span>Doubly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Matrix2D.html"><span>Matrix2D</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MatrixNTI2D.html"><span>MatrixNTI2D</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxHeap.html"><span>Max<wbr/>Heap</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>Max<wbr/>Priority<wbr/>Queue</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MinHeap.html"><span>Min<wbr/>Heap</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>Min<wbr/>Priority<wbr/>Queue</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Navigator.html"><span>Navigator</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>Object<wbr/>Deque</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>Priority<wbr/>Queue</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></li>
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/RBTree.html"><span>RBTree</span></a></li>)
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>Segment<wbr/>Tree</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTreeNode.html"><span>Segment<wbr/>Tree<wbr/>Node</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>Singly<wbr/>Linked<wbr/>List</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedListNode.html"><span>Singly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SplayTree.html"><span>Splay<wbr/>Tree</span></a></li>)
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>Tree<wbr/>Multi<wbr/>Set</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TrieNode.html"><span>Trie<wbr/>Node</span></a></li>
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/TwoThreeTree.html"><span>Two<wbr/>Three<wbr/>Tree</span></a></li>)
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedEdge.html"><span>Undirected<wbr/>Edge</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>Undirected<wbr/>Graph</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedVertex.html"><span>Undirected<wbr/>Vertex</span></a></li>
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Vector2D.html"><span>Vector2D</span></a></li></ul></nav>
[//]: # ([Examples Repository]&#40;https://github.com/zrwusa/data-structure-typed-examples&#41;)

@@ -479,0 +606,0 @@

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc