RB-UPDATE-BH(z) if z.color == BLACK z.black-height = z.left.black-height + 1 else z.black-height = z.left.black-height
RB-INSERT-FIXUP-BH(T, z) while z.p.color == RED if z.p == z.p.p.left y = z.p.p.right if y.color == RED z.p.color = BLACK y.color = BLACK z.p.p.color = RED z = z.p.p RB-UPDATE-BH(z.left) RB-UPDATE-BH(z.right) RB-UPDATE-BH(z) else if z == z.p.right z = z.p LEFT-ROTATE(T, z) z.p.color = BLACK z.p.p.color = RED RIGHT-ROTATE(T, z.p.p) RB-UPDATE-BH(z.p.right) RB-UPDATE-BH(z.p) else y = z.p.p.left if y.color == RED z.p.color = BLACK y.color = BLACK z.p.p.color = RED z = z.p.p RB-UPDATE-BH(z.left) RB-UPDATE-BH(z.right) RB-UPDATE-BH(z) else if z == z.p.right z = z.p RIGHT-ROTATE(T, z) z.p.color = BLACK z.p.p.color = RED RIGHT-ROTATE(T, z.p.p) RB-UPDATE-BH(z.p.left) RB-UPDATE-BH(z.p) T.root.color = BLACK
RB-DELETE-FIXUP-BH(T, x) while x != T.root and x.color == BLACK if x == x.p.left w = x.p.right if w.color == RED w.color = BLACK x.p.color = RED LEFT-ROTATE(T, x.p) w = x.p.right RB-UPDATE-BH(x.p) RB-UPDATE-BH(x.p.p) if w.left.color == BLACK and w.right.color == BLACK w.color = RED x = x.p RB-UPDATE-BH(x.right) RB-UPDATE-BH(x) else if w.right.color == BLACK w.left.color = BLACK w.color = RED RIGHT-ROTATE(T, w) w = x.p.right RB-UPDATE-BH(w.right) RB-UPDATE-BH(w) w.color = x.p.color x.p.color = BLACK w.right.color = BLACK LEFT-ROTATE(T, x.p) RB-UPDATE-BH(x) RB-UPDATE-BH(w.right) RB-UPDATE-BH(w) x = T.root else w = x.p.left if w.color == RED w.color = BLACK x.p.color = RED RIGHT-ROTATE(T, x.p) w = x.p.left RB-UPDATE-BH(x.p) RB-UPDATE-BH(x.p.p) if w.left.color == BLACK and w.right.color == BLACK w.color = RED x = x.p RB-UPDATE-BH(x.left) RB-UPDATE-BH(x) else if w.left.color == BLACK w.right.color = BLACK w.color = RED LEFT-ROTATE(T, w) w = x.p.left RB-UPDATE-BH(w.left) RB-UPDATE-BH(w) w.color = x.p.color x.p.color = BLACK w.left.color = BLACK RIGHT-ROTATE(T, x.p) RB-UPDATE-BH(x) RB-UPDATE-BH(w.right) RB-UPDATE-BH(w) x = T.root x.color = BLACK
OS-LEFT-ROTATE-UPDATE-F(T, x) y = x.right x.right = y.left if y.left != T.nill y.left.p = x y.p = x.p if x.p == T.nil T.root = y else if x == x.p.left x.p.left = y else x.p.right = y y.left = x x.p = y y.f = x.f x.f = x.left.f ⊗ x.a ⊗ x.right.f
OS-RIGHT-ROTATE-UPDATE-F(T, y) x = y.left y.left = x.right if x.right != T.nil x.right.p = y x.p = y.p if y.p == T.nil T.root = x else if y == y.p.left y.p.left = x else y.p.right = x x.right = y y.p = x x.f = y.f y.f = y.left.f ⊗ y.a ⊗ y.right.f