Skip to content

Commit

Permalink
Cosmetic comment update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshi Nakamura committed Feb 5, 2012
1 parent be39f03 commit 1ebaed2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/red_black_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,15 @@ def rotate_right
private

# trying to rebalance when the left sub-tree is 1 level higher than the right
# precondition: self is black and @left is red
def rebalance_for_left_insert
ret = self
if @right.red?
# pull-up red nodes and let the parent rebalance (see precondition)
@color = :RED
@left.color = @right.color = :BLACK
else
# move 1 black from the left to the right by single/double rotation
if @left.right.red?
@left = @left.rotate_left
end
Expand All @@ -322,6 +325,7 @@ def rebalance_for_left_insert
end

# trying to rebalance when the right sub-tree is 1 level higher than the left
# See rebalance_for_left_insert.
def rebalance_for_right_insert
ret = self
if @left.red?
Expand Down

0 comments on commit 1ebaed2

Please sign in to comment.