# File rbtree.rb, line 32 def add object x = insert object # insert the object, sorted, into the tree x.color = RED rot = proc { |x, y, left, right| y = x.parent.parent.send(right) if !y.nil? and y.color == RED x.parent.color = BLACK y.color = BLACK x.parent.parent.color = RED x = x.parent.parent else if x == x.parent.send(right) x = x.parent self.send("#{left}_rotate", x) end x.parent.color = BLACK x.parent.parent.color = RED self.send("#{right}_rotate", x.parent.parent) end } while x != @root and x.parent.color == RED if x.parent == x.parent.parent.left y = x.parent.parent.right rot.call(x,y,"left", "right") else y = x.parent.parent.left rot.call(x,y,"right", "left") end end @root.color = BLACK end