The highest parent of this node that has the same value or this node if there is no such node.
The previous node in sequence.
The next node in sequence.
Finds the largest child of this node not including equal nodes.
Finds the largest child that is larger than this node not including equal nodes.
The root of the BST.
Finds the smallest child of this node not including equal nodes.
Finds the smallest child that is smaller than this node not including equal nodes.
Called by the BST only. DO NOT use. This is only public because JS has
no concept of C++ friend
classes and I need to use this function in unit
tests. Call the add
function on the BST object instead.
The node to add
A function that will be called if the BST root needs to be updated. A TypeError will be thrown if one is not provided.
Applies an offset to the node's starting position. This will offset all nodes after this one efficiently. There's just one catch: This may not change the order of the BST. No errors will be thrown (or can, efficiently at least), so just make sure your code doesn't change the order. This will not mutate the BST unless the position of a node becomes equal to that of another node. In that case, the BST will be re-arranged so that the equal nodes form a linked list under the left side of the root equal node as required.
The offset to apply to this node's start. This may be positive to add space before or negative to remove space before.
A function that will be called if the BST root needs to be updated. A TypeError will be thrown if one is not provided.
Searches the DBST based on the values of preferential_cmp
only. Useful
for searching for a node when its value is not known.
The range to search
Order nodes that have the same value
may be ordered differently using
this function. This function must follow these rules:
value
in your implementation. Basically, if you ever have zero
length nodes or nodes with the same position, you have to use this for
things to not break.Removes this node from the BST. The node's absolute_value
will be
preserved, so it can be directly re-added to the BST.
This function is called if the bst_root
of the BST
must be updated. Normally, it should be given the value of
(node) => (bst.bst_root = node)
. If no value is provided, an error will
be thrown if an update is attempted. For this reason, if you expect that
no root update will be required for whatever reason, do not provide a
value. This will ensure that an error is thrown and a potential bug is
caught.
THIS IS NOT INTENDED FOR OUTSIDE USE! It is not protected for the unit tests that rely on it.
Replaces this node with another node. This is used internally by the
remove
function. If the node provided has a parent, it will be removed
from the parent. WARNING: If the provided node's current children
conflict with the children of the destination node, the destination node's
children have priority.
New node
A function that will be called if the BST root needs to be updated. A TypeError will be thrown if one is not provided.
The value to use for the new node. It defaults to the node's
absolute_value
.
Searches the DBST based on node value.
The range to search
Creates a virtual tree showing right, left, and equal nodes. Very useful when debugging BST issues.
Generated using TypeDoc
The actual value of this node. The
value
member only stores the value relative to the parent node.