The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to merge duplicated values.
Optional
options: Omit<AVLTreeOptions, "isMergeDuplicatedNodeById">An optional object that contains additional configuration options for the TreeMultiset.
Protected
_comparatorPrivate
_countPerforms a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on their 'id' property.
An array of binary tree node IDs.
Performs a breadth-first search (BFS) on a binary tree, accumulating properties of each node based on the specified property name.
The name of the property to accumulate.
An array of values corresponding to the specified property.
Performs a breadth-first search (BFS) on a binary tree, accumulating the 'val' property of each node.
The name of the property to accumulate.
An array of 'val' properties from each node.
Performs a breadth-first search (BFS) on a binary tree, accumulating nodes themselves.
The name of the property to accumulate.
An array of binary tree nodes.
Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'id' property.
An array of binary tree node IDs.
Performs a depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on the specified property name.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "id"The name of the property to accumulate.
An array of values corresponding to the specified property.
Performs a depth-first search (DFS) traversal on a binary tree and accumulates the 'val' property of each node.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "val"The name of the property to accumulate.
An array of 'val' properties from each node.
Performs a depth-first search (DFS) traversal on a binary tree and accumulates nodes themselves.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "node"The name of the property to accumulate.
An array of binary tree nodes.
The DFSCount function returns an array of counts for each node in a depth-first search traversal.
Optional
pattern: DFSOrderPatternThe pattern parameter is an optional parameter that specifies the order in which the Depth-First Search (DFS) algorithm should traverse the nodes. It can have one of the following values:
The DFSCount function returns an array of numbers, specifically the count property of each node in the DFS traversal.
Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on their 'id' property.
An array of binary tree node IDs.
Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates properties of each node based on the specified property name.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "id"The name of the property to accumulate.
An array of values corresponding to the specified property.
Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates the 'val' property of each node.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "val"The name of the property to accumulate.
An array of 'val' properties from each node.
Performs an iterative depth-first search (DFS) traversal on a binary tree and accumulates nodes themselves.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "node"The name of the property to accumulate.
An array of binary tree nodes.
The function DFSIterativeCount performs an iterative depth-first search and returns an array of node counts based on the specified traversal pattern.
Optional
pattern: "in" | "pre" | "post"The pattern parameter is a string that specifies the traversal order for the Depth-First Search (DFS) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
The DFSIterativeCount function returns an array of numbers, which represents the count property of each node in the DFS traversal.
Protected
_accumulatedThe function _accumulatedByPropertyName
accumulates values from a given node based on the specified property name.
The node
parameter is of type N
, which represents a node in a data structure.
Optional
nodeOrPropertyName: NodeOrPropertyNameThe nodeOrPropertyName
parameter is an optional parameter that
can be either a string representing a property name or a reference to a Node
object. If it is a string, it
specifies the property name to be used for accumulating values. If it is a Node
object, it specifies
The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent node.
The newNode
parameter represents the node that needs to be added to the tree. It can
be either a node object (N
) or null
.
The parent
parameter represents the parent node to which the new node will be added as a
child.
The method returns either the parent.left
, parent.right
, or undefined
.
Protected
_balanceThe 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.
The parameter "node" is of type N, which represents a node in an AVL tree.
The balance factor of the given AVL tree node.
Protected
_balanceLLProtected
_balanceLRProtected
_balanceThe _balancePath
function balances the AVL tree by performing appropriate rotations based on the balance factor of
each node in the path from the given node to the root.
The node
parameter is an AVLTreeNode object, which represents a node in an AVL tree.
Protected
_balanceRLProtected
_balanceRRProtected
_clearProtected
_compareThe function compares two binary tree node IDs using a comparator function and returns whether the first ID is greater than, less than, or equal to the second ID.
a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
The parameter "b" in the above code refers to a BinaryTreeNodeId.
a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less than), or CP.eq (equal).
Protected
_getThe function _getResultByPropertyName
returns the corresponding property value based on the given node or property
name.
Optional
nodeOrPropertyName: NodeOrPropertyNameThe parameter nodeOrPropertyName
is an optional parameter that
can accept either a NodeOrPropertyName
type or be undefined.
The method _getResultByPropertyName
returns an instance of AbstractBinaryTreeNodeProperties<N>
.
Protected
_pushThe function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to a result array.
The current node being processed.
An array that stores the matching nodes.
The nodeProperty
parameter is either a BinaryTreeNodeId
or a N
type. It represents the property value that we are comparing against in the switch statement.
Optional
propertyName: BinaryTreeNodePropertyNameThe propertyName
parameter is an optional parameter that
specifies the property name to compare against when pushing nodes into the result
array. It can be either 'id'
or 'val'
. If it is not provided or is not equal to 'id'
or 'val'
, the
Optional
onlyOne: booleanThe onlyOne
parameter is an optional boolean parameter that determines whether to
stop after finding the first matching node or continue searching for all matching nodes. If onlyOne
is set to
true
, the function will stop after finding the first matching node and return true
. If `onlyOne
a boolean value indicating whether only one matching node should be pushed into the result array.
Protected
_setProtected
_setThe function sets the loop type for a protected variable.
The value parameter is of type LoopType.
Protected
_setProtected
_setProtected
_setProtected
_setProtected
_setProtected
_updateThe add
function adds a new node to a binary search tree, maintaining the tree's properties and balancing if
necessary.
The idOrNode
parameter can be either a BinaryTreeNodeId
or a N
(which
represents a BinaryTreeNode
).
Optional
val: N["val"]The val
parameter represents the value to be added to the binary tree node.
Optional
count: numberThe count
parameter is an optional parameter that specifies the number of times the
value should be added to the binary tree. If the count
parameter is not provided, it defaults to 1.
The method add
returns either the inserted node (N
), null
, or undefined
.
The addMany
function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
the inserted nodes.
An array of BinaryTreeNodeId or BinaryTreeNode objects, or null values.
Optional
data: N["val"][]The data
parameter is an optional array of values (N['val'][]
) that corresponds to
the nodes being added. It is used when adding nodes using the idOrNode
and data
arguments in the this.add()
method. If provided, the data
array should
The function addMany
returns an array of N
, null
, or undefined
values.
The allGreaterNodesAdd
function adds a delta value to the specified property of all nodes in a binary tree that
have a greater value than a given node.
The node
parameter can be either of type N
(a generic type),
BinaryTreeNodeId
, or null
. It represents the node in the binary tree to which the delta value will be added.
The delta
parameter is a number that represents the amount by which the property value of
each greater node should be increased.
Optional
propertyName: BinaryTreeNodePropertyNameThe propertyName
parameter is an optional parameter that
specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
'id'.
a boolean value.
The function allGreaterNodesAddCount
updates the count property of all nodes in a binary tree that have an ID
greater than a given ID by a specified delta value.
The node
parameter can be one of the following:
The delta
parameter is a number that represents the amount by which the count
property
of each node should be increased.
a boolean value.
The function creates a new BSTNode with the given id, value, and count.
The id parameter is the unique identifier for the binary tree node. It is used to distinguish one node from another in the tree.
Optional
val: N["val"]The val
parameter represents the value that will be stored in the binary search tree node.
Optional
count: numberThe "count" parameter is an optional parameter of type number. It represents the number of occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
A new instance of the BSTNode class with the specified id, value, and count (if provided).
The fill
function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
The idsOrNodes
parameter is an array that can contain either
BinaryTreeNodeId
or N
values.
Optional
data: N["val"][] | N[]The data
parameter is an optional array of values that will be assigned to
the nodes being added. If provided, the length of the data
array should be equal to the length of the idsOrNodes
array. Each value in the data
array will be assigned to the
The method is returning a boolean value.
The function returns the first node in a binary tree that matches the given property name and value.
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.
Optional
propertyName: BinaryTreeNodePropertyNameThe propertyName
parameter is an optional parameter that
specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to 'id'
.
The method is returning either a BinaryTreeNodeId or N (generic type) or null.
The getHeight
function calculates the maximum height of a binary tree, either recursively or iteratively.
Optional
beginRoot: null | number | NThe beginRoot
parameter is optional and can be of type N
(a
generic type representing a node in a binary tree), BinaryTreeNodeId
(a type representing the ID of a binary tree
node), or null
.
the height of the binary tree.
The function getLeftMost
returns the leftmost node in a binary tree, starting from a specified node or the root if
no node is specified.
generic type representing a node in a binary tree), BinaryTreeNodeId
(a type representing the ID of a binary tree
node), or null
.
The function getLeftMost
returns the leftmost node in a binary tree. If the beginRoot
parameter is
provided, it starts the traversal from that node. If beginRoot
is not provided or is null
, it starts the traversal
from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
node is found (
The function getLeftMost
returns the leftmost node in a binary tree, starting from a specified node or the root if
no node is specified.
Optional
node: NThe beginRoot
parameter is optional and can be of type N
(a
generic type representing a node in a binary tree), BinaryTreeNodeId
(a type representing the ID of a binary tree
node).
The function getLeftMost
returns the leftmost node in a binary tree. If the beginRoot
parameter is
provided, it starts the traversal from that node. If beginRoot
is not provided or is null
, it starts the traversal
from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
node is found (
The getMinHeight
function calculates the minimum height of a binary tree using either a recursive or iterative
approach.
Optional
beginRoot: null | NThe beginRoot
parameter is an optional parameter of type N
or null
. It
represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
for beginRoot
, the this.root
property is used as the default value.
The function getMinHeight
returns the minimum height of the binary tree.
The function getNodes
returns an array of nodes in a binary tree that match a given property value.
The nodeProperty
parameter can be either a BinaryTreeNodeId
or an
N
type. It represents the property of the binary tree node that you want to compare with.
Optional
propertyName: BinaryTreeNodePropertyName = 'id'The propertyName
parameter is an optional parameter that
specifies the property name to use for comparison. If not provided, it defaults to 'id'
.
Optional
onlyOne: booleanThe onlyOne
parameter is an optional boolean parameter that determines whether to
return only one node that matches the given nodeProperty
or all nodes that match the nodeProperty
. If onlyOne
is set to true
, the function will return an array with only one node (if
an array of nodes (type N).
The function getNodesByCount
returns an array of nodes that have a specific count property, either recursively or
using a queue.
The nodeProperty
parameter can be either a BinaryTreeNodeId
or a
N
. It represents the property of the nodes that you want to search for.
Optional
onlyOne: booleanThe onlyOne
parameter is an optional boolean parameter that determines whether to
return only one node that matches the nodeProperty
or all nodes that match the nodeProperty
. If onlyOne
is set
to true
, the function will return only one node. If onlyOne
an array of nodes that match the given nodeProperty.
The function getPathToRoot
returns an array of nodes representing the path from a given node to the root node, with
an option to reverse the order of the nodes.
The node
parameter represents a node in a tree structure. It is of type N
, which could be any
type that represents a node in your specific implementation.
Optional
isReverse: boolean = trueThe isReverse
parameter is a boolean flag that determines whether the resulting
path should be reversed or not. If isReverse
is set to true
, the path will be reversed before returning it. If
isReverse
is set to false
or not provided, the path will
The function getPathToRoot
returns an array of nodes (N[]
).
The getRightMost
function returns the rightmost node in a binary tree, either recursively or iteratively using tail
recursion optimization.
The getRightMost
function returns the rightmost node in a binary tree. It returns the
rightmost node starting from the root of the binary tree.
The getRightMost
function returns the rightmost node in a binary tree, either recursively or iteratively using tail
recursion optimization.
Optional
node: NThe node
parameter is an optional parameter of type N
or null
. It represents the
starting node from which we want to find the rightmost node. If no node is provided, the function will default to
using the root node of the data structure.
The getRightMost
function returns the rightmost node in a binary tree. It returns the rightmost node
starting from that node.
The function getSubTreeCount
calculates the number of nodes and the sum of their counts in a subtree, using either
recursive or iterative traversal.
The subTreeRoot
parameter represents the root node of a subtree in a
binary tree.
The function getSubTreeCount
returns an array [number, number]
.
The function calculates the size of a subtree by traversing it either recursively or iteratively.
The subTreeRoot
parameter represents the root node of a subtree in a
binary tree.
the size of the subtree rooted at subTreeRoot
.
The function checks if a binary tree node has a specific property.
The nodeProperty
parameter can be either a BinaryTreeNodeId
or N
.
It represents the property of the binary tree node that you want to check.
Optional
propertyName: BinaryTreeNodePropertyNameThe propertyName
parameter is an optional parameter that
specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
a boolean value.
The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the tree.
Optional
beginRoot: null | NThe parameter beginRoot
is of type N
or null
. It represents the root node of a
tree or null if the tree is empty.
The method is returning a boolean value.
The function returns the id of the rightmost node if the comparison between two values is less than, the id of the leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
The method lastKey()
returns the id of the rightmost node in the binary tree if the comparison between
the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
The lesserSum
function calculates the sum of property values in a binary tree for nodes that have a property value
less than a given node.
The beginNode
parameter can be one of the following:
Optional
propertyName: BinaryTreeNodePropertyNameThe propertyName
parameter is an optional parameter that
specifies the property name to use for calculating the sum. If not provided, it defaults to 'id'
.
The function lesserSum
returns a number, which represents the sum of the values of the nodes in the
binary tree that have a lesser value than the specified beginNode
based on the propertyName
.
The lesserSumCount
function calculates the sum of the counts of all nodes in a binary tree that have a lesser
value than a given node.
The beginNode
parameter can be one of the following:
the sum of the counts of nodes in the binary tree that have a lesser value than the given beginNode.
Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'id' property.
The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
An array of binary tree node IDs.
Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.
The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
Optional
nodeOrPropertyName: "id"The name of the property to accumulate.
An array of values corresponding to the specified property.
Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
Optional
nodeOrPropertyName: "val"The name of the property to accumulate.
An array of 'val' properties from each node.
Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
Optional
nodeOrPropertyName: "node"The name of the property to accumulate.
An array of binary tree nodes.
Collects nodes from a binary tree by a specified property and organizes them into levels.
The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
A 2D array of AbstractBinaryTreeNodeProperty
Collects nodes from a binary tree by a specified property and organizes them into levels.
The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
Optional
nodeOrPropertyName: "id"Collects nodes from a binary tree by a specified property and organizes them into levels.
The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
Optional
nodeOrPropertyName: "val"The property of the BinaryTreeNode object to collect at each level.
A 2D array of 'val' properties from each node.
Collects nodes from a binary tree by a specified property and organizes them into levels.
The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
Optional
nodeOrPropertyName: "node"The property of the BinaryTreeNode object to collect at each level.
A 2D array of binary tree nodes.
The function "listLevelsCount" takes a node and returns an array of arrays, where each inner array contains the count property of each node at that level.
The parameter node
is of type N | null
. This means that it can either be an instance of
the class N
or null
.
a 2D array of numbers. Each inner array represents a level in the binary tree, and each number in the inner array represents the count property of a node in that level.
Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
An array of binary tree node IDs.
Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "id"The name of the property to accumulate.
An array of values corresponding to the specified property.
Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "val"The property of the BinaryTreeNode object to collect at each level.
An array of 'val' properties from each node.
Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates nodes themselves.
Optional
pattern: DFSOrderPatternThe traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
Optional
nodeOrPropertyName: "node"The property of the BinaryTreeNode object to collect at each level.
An array of binary tree nodes.
The morrisCount
function returns an array of counts for each node in a binary tree, based on a specified traversal
pattern.
Optional
pattern: "in" | "pre" | "post"The pattern
parameter is an optional parameter that specifies the
traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
The function morrisCount
returns an array of numbers.
The remove
function removes a node from a binary search tree and returns the deleted node along with the parent
node that needs to be balanced.
The nodeOrId
parameter can be one of the following:
Optional
ignoreCount: booleanThe ignoreCount
parameter is an optional boolean parameter that determines
whether to ignore the count of the node being removed. If ignoreCount
is set to true
, the count of the node will
not be taken into account when removing it. If ignoreCount
is set to false @returns The function
removereturns an array of
BinaryTreeDeletedResult
The function subTreeAdd
adds a delta value to a specified property of each node in a subtree.
The subTreeRoot
parameter represents the root node of a binary
tree or the ID of a node in the binary tree. It can also be null
if there is no subtree to add to.
The delta
parameter is a number that represents the amount by which the property value of
each node in the subtree should be incremented.
Optional
propertyName: BinaryTreeNodePropertyNameThe propertyName
parameter is an optional parameter that
specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
a boolean value.
The function subTreeAddCount
recursively or iteratively traverses a binary tree and adds a given delta value to
the count
property of each node.
The subTreeRoot
parameter represents the root node of a subtree
in a binary tree. It can be either a BinaryTreeNodeId
(a unique identifier for a node in the binary tree), a
BinaryTreeNode
object, or null
if the subtree is empty.
The delta parameter is a number that represents the amount by which the count of each node in the subtree should be increased or decreased.
a boolean value.
The function subTreeSum
calculates the sum of a specified property in a binary tree or subtree.
The subTreeRoot
parameter represents the root node of a binary
tree or the ID of a binary tree node. It can also be null
if there is no subtree.
Optional
propertyName: BinaryTreeNodePropertyNamepropertyName is an optional parameter that specifies the property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is not provided, it defaults to 'id'.
a number, which is the sum of the values of the specified property in the subtree rooted at subTreeRoot
.
The function subTreeSumCount
calculates the sum of the count
property of each node in a subtree, either
recursively or iteratively.
The subTreeRoot
parameter represents the root node of a subtree
in a binary tree. It can be either a BinaryTreeNodeId
(a unique identifier for a node in the binary tree) or
null
if the subtree is empty.
the sum of the count values of all nodes in the subtree rooted at subTreeRoot
.
The function swaps the location of two nodes in a tree data structure.
The source node that we want to swap with the destination node.
The destNode
parameter represents the destination node where the values from srcNode
will
be swapped with.
the destNode
after swapping its values with the srcNode
.
Generated using TypeDoc
The only distinction between a TreeMultiset and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.