Skip to content

Commit

Permalink
Proper variable name for explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshi Nakamura committed Mar 27, 2012
1 parent 0437c2a commit 27166a6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rbtree_map.rb
Expand Up @@ -24,18 +24,18 @@ def black?

# returns new_root
def insert(key, value)
ret = self
case key <=> @key
when -1
@left = @left.insert(key, value)
ret = rebalance_for_left_insert
new_node = rebalance_for_left_insert
when 0
@value = value
new_node = self
when 1
@right = @right.insert(key, value)
ret = rebalance_for_right_insert
new_node = rebalance_for_right_insert
end
ret.pullup_red
new_node.pullup_red
end

# returns value
Expand Down Expand Up @@ -158,6 +158,7 @@ def rebalance_for_left_insert
# trying to rebalance when the right sub-tree is 1 level higher than the left
def rebalance_for_right_insert
if black? and @right.need_rebalance?
# move 1 black from the right to the left by single/double rotation
if @right.left.red?
@right = @right.rotate_right
end
Expand Down

0 comments on commit 27166a6

Please sign in to comment.