AVL operations relative to a side #
Rotations and rebalancing come in mirror-image pairs. The definitions here name a child by its
side instead, so that a statement about "the child on side right" covers both: nodeSide,
mkNodeAt, rotateAt and balanceAt are AVLTree.node, mkNode, the rotation that promotes
that child, and balance, with the distinguished child placed on the selected side.
Main results #
rotateAt_nodeSide: a rotation, as twomkNodeAt.balanceAt_heavy:balanceat a node whose child on a side is too tall is a single or a double rotation of that child.insert_nodeSide: insertion on a side, as an insertion into the child and abalanceAt.
Promoting a child, whose own children are outer on the same side and inner on the other,
puts outer on that side and the old root, with inner and the sibling, on the other.
mkNodeAt is a node with the height of mkNode.
The children of a height-consistent node are height-consistent.
mkNodeAt preserves height consistency.
At a node whose child on a side is at least two taller than its sibling, balance promotes
that child, after first promoting its inner child when that one is the taller.
At a node whose children differ in height by at most one, balance only recomputes the
height.