AvlBuilder

Builds AVL trees of a predetermined size by accepting nodes of increasing value. To use:

  1. Call reset to initialize the target size size.
  2. Call size times with increasing values.
  3. Call root to get the root of the balanced tree.

The returned tree will satisfy the AVL constraint: for every node N, the height of N.left and N.right is different by at most 1. It accomplishes this by omitting deepest-level leaf nodes when building trees whose size isn't a power of 2 minus 1.

Unlike rebuilding a tree from scratch, this approach requires no value comparisons. Using this class to create a tree of size S is {@code O(S)} .

class AvlBuilder<K, V>

Functions

add
Link copied to clipboard
open fun add(node: LinkedHashTreeMap.Node<K, V>)
reset
Link copied to clipboard
open fun reset(targetSize: Int)
root
Link copied to clipboard
open fun root(): LinkedHashTreeMap.Node<K, V>