The last chapter saw us implementing a library for one particular type
of balanced trees. Red-black trees were invented by R. Bayer and
studied at length by L. J. Guibas and R. Sedgewick. This
chapter will implement a library for another kind of balanced tree,
called a red-black tree (see red-black tree). For brevity, we'll often abbreviate
“red-black” to RB.

Insertion and deletion operations on red-black trees are more complex
to describe or to code than the same operations on AVL trees.
Red-black trees also have a higher maximum height than AVL trees for a
given number of nodes. The primary advantage of red-black trees is
that, in AVL trees, deleting one node from a tree containing n nodes
may require log2 (n) rotations, but deletion in a
red-black tree never requires more than three rotations.

The functions for RB trees in this chapter are analogous to those that
we developed for use with AVL trees in the previous chapter. Here's an
outline of the red-black code: