def balance(self):
<EOL>if self.right.red:<EOL><INDENT>self = self.rotate_left()<EOL><DEDENT>if self.left.red and self.left.left.red:<EOL><INDENT>self = self.rotate_right()<EOL><DEDENT>if self.left.red and self.right.red:<EOL><INDENT>self = self.flip()<EOL><DEDENT>return self<EOL>
Balance a node.

The balance is inductive and relies on all subtrees being balanced
recursively or by construction. If the subtrees are not balanced, then
this will not fix them.