Creates an instance of AVL. Can set a converter from here.
Returns the current height of the tree
Sums up how many nodes there are in the Tree
Iterate through the values in ascending order
Return true if any of the key is contained
Tries to convert the value. If its a convertable it will use it's inner converter. If not, it tries to use the supplied converter in the ops. Or optionally you can supply a converter method, but this wont be saved into the Tree If you want a permament converter use the opts or just set the converter field of the Tree TODO: bigint option if supported
Returns the first node.
Returns the first value it founds on key or after that
Returns the first node it founds on key or after that
Calls a function on each element of the Tree, in order. There is an optional index
Calls a function on each element of the Tree, in order. There is an optional index
Returns with the value on the supplied key. undefined if there is no value on that key
Returns with the node on the supplied key. undefined if there is no node on that key
Return true if every key is contained
Please don't use this for the love of god
Returns the last node.
Returns the last element.
Returns the first element.
This method will move the node object found at the key to the correct position in the tree. This does not reconstruct the object.
If you try to move the node to an key thats already exists the method will do nothing
Debugging
The push method tries to convert the value into a number to use it as a Key if it has a convertTo method (suggested, but not necessarily by the Convertable interface) it will use that. If not, but you've set a converter
Sets multiple values to multiple keys
Iterate through the values in descending order
sets a key to a value
Because it's marked with @ToJSon we can sumply use JSON.stringify. I'm putting this method here for brevity
! WARNING: Limited capabilities! ! The converted tree must use Objects (Not Numbers, not Strings, Objects) ! on both the key and value to be working ! (Workaround: use wrapper objects) ! It also can't restore the explicit converter and comparator functions ! as JavaScript can't parse functions (reliably) ! (Workaround: use implicit converters and comparables)
Bit tricky to use. You have to supply the constructor of the key and the value. If it's a primitive you can just leave it undefined example:
const tree = Tree.parse<number, Basic>(treeAsString, undefined, Basic);
If those subtypes are also generic (and annotated by TypedJSON) you can add extra knownTypes after the initial two too.
Generated using TypeDoc
AVL Tree