Constructor takes an optional parameter compareFunction
to replace
the default comparison function.
The function used to compare two values.
The function used to compare two elements. It is determinant for the tree structure. By default, it compares numbers so it must be replaced with a custom function when storing another data type.
The traverse method used when unspecified in the concerned methods.
It can be changed via setDefaultTraverseMethod
method.
Possible values:
TraverseMethod.BFS
/ 0
(Breadth First Search)TraverseMethod.DFSPreOrder
/ 1
(Depth First Search Pre Order)TraverseMethod.DFSInOrder
/ 2
(Depth First Search In Order)TraverseMethod.DFSPostOrder
/ 3
(Depth First Search Post Order)Resets the tree, removing its elements.
Creates a new tree with the filtered values of the current one,
using the input filterFunction
. Current tree is unaltered.
The FilterFunction
to use.
The TraverseMethod
to use.
The resulting tree.
Inserts a new value to the tree. Note: the structure does not accept duplicates.
The value to insert
true
if succeeded, false
otherwise
Traverses the tree, applying a transformation to every value according
to the given MapFunction
. A new tree is returned, the current one is
unaltered.
The function describing the transformation to apply on each value.
The TraverseMethod
to use.
The compare function of the new tree. Default is set to the compare function of the current tree. It is necessary if the map function changes the values data type.
The resulting tree.
Computes and return a single value from the values of the tree,
using the input ReduceFunction
.
The ReduceFunction
to use.
The initial value of the accumulator
The TraverseMethod
to use.
The accumulated value at the end of traversal.
Returns the root node.
The root node
Replaces the current compare function with the provided
CompareFunction
. A compare function has the signature:
CompareFunction<T>(a: T, b: T) => -1 | 0 | 1
.
To keep its integrity, the tree is fully rebuilt.
The function to use to compare two values.
The tree instance.
Sets a default traverse method that will be used when not specified in methods that require traversal. Possible values:
TraverseMethod.BFS
/ 0
(Breadth First Search)TraverseMethod.DFSPreOrder
/ 1
(Depth First Search Pre Order)TraverseMethod.DFSInOrder
/ 2
(Depth First Search In Order)TraverseMethod.DFSPostOrder
/ 3
(Depth First Search Post Order)The default traverse method to use.
Returns an array of the stored values. The order depends on the
TraverseMethod
used.
The TraverseMethod
to use.
Traverses the tree using Breadth First Search method, starting from the given root. The given callback is executed on each value.
The traversal starting point
A callback to execute on each value.
Traverses the tree recursively using Depth First Search method,
and executes a callback on each value.
This method gathers all DFS order methods into one, applying the callback
at the right moment depending on order
parameter.
The TraverseMethod
to use, TraverseMethod.BFS
excluded.
The element being traversed.
The callback to execute on each value.
Traverses the tree using DFS InOrder method and applies a callback on each value.
The starting point of the traversal.
The callback to execute on each value.
Traverses the tree using DFS PostOrder method and applies a callback on each value.
The starting point of the traversal.
The callback to execute on each value.
Traverses the tree using DFS PreOrder method and applies a callback on each value.
The starting point of the traversal.
The callback to execute on each value.
Generated using TypeDoc
A Binary Search Tree implementation that accepts any kind of data, including arrays or plain objects. To do so, it must be provided a custom
compareFunction
that will be used to determine the position of the elements instead of the default comparison operators.