lib/treemap/tree_map.rb
def remove_internal(node)
    left = node.left
    right = node.right
    original_parent = node.parent

    if left && right
      # To remove a node with both left and right subtrees, move an adjacent node from one of those subtrees into this node's place.
      # Removing the adjacent node may change this node's subtrees. This node may no longer have two subtrees once the adjacent node is gone!

      adjacent = left.height > right.height ? left.last : right.first
      remove_internal(adjacent)   # takes care of rebalance and size--

      left_height = 0
      left = node.left
      if left
        left_height = left.height
        adjacent.left = left
        left.parent = adjacent
        node.left = nil
      end
      right_height = 0
      right = node.right
      if right
        right_height = right.height
        adjacent.right = right
        right.parent = adjacent
        node.right = nil
      end
      adjacent.height = [left_height, right_height].max + 1
      replace_in_parent(node, adjacent)
      return
    elsif left
      replace_in_parent(node, left)
      node.left = nil
    elsif right
      replace_in_parent(node, right)
      node.right = nil
    else
      replace_in_parent(node, nil)
    end

    rebalance(original_parent, false)
    @size -= 1
    @mod_count -= 1
  end
# Removes {@code node} from this tree, rearranging the tree's structure as necessary.
# return value not meaningful
Removes  node from this tree, rearranging the tree's structure as necessary.
return value not meaningful
Removes node from this tree rearranging the tree ' s structure as necessary . return value not meaningful
def remove_internal(node)
    left = node.left
    right = node.right
    original_parent = node.parent
    if left && right
      adjacent = left.height > right.height ? left.last : right.first
      remove_internal(adjacent)   
      left_height = 0
      left = node.left
      if left
        left_height = left.height
        adjacent.left = left
        left.parent = adjacent
        node.left = nil
      end
      right_height = 0
      right = node.right
      if right
        right_height = right.height
        adjacent.right = right
        right.parent = adjacent
        node.right = nil
      end
      adjacent.height = [left_height, right_height].max + 1
      replace_in_parent(node, adjacent)
      return
    elsif left
      replace_in_parent(node, left)
      node.left = nil
    elsif right
      replace_in_parent(node, right)
      node.right = nil
    else
      replace_in_parent(node, nil)
    end
    rebalance(original_parent, false)
    @size -= 1
    @mod_count -= 1
  end
def remove_internal ( node ) left = node . left right = node . right original_parent = node . parent if left && right adjacent = left . height > right . height ? left . last : right . first remove_internal ( adjacent ) left_height = 0 left = node . left if left left_height = left . height adjacent . left = left left . parent = adjacent node . left = nil end right_height = 0 right = node . right if right right_height = right . height adjacent . right = right right . parent = adjacent node . right = nil end adjacent . height = [ left_height , right_height ] . max + 1 replace_in_parent ( node , adjacent ) return elsif left replace_in_parent ( node , left ) node . left = nil elsif right replace_in_parent ( node , right ) node . right = nil else replace_in_parent ( node , nil ) end rebalance ( original_parent , false ) @size -= 1 @mod_count -= 1 end
Removes {@code node} from this tree, rearranging the tree's structure as necessary.
Removes { @code node } from this tree rearranging the tree ' s structure as necessary .
# To remove a node with both left and right subtrees, move an adjacent node from one of those subtrees into this node's place. # Removing the adjacent node may change this node's subtrees. This node may no longer have two subtrees once the adjacent node is gone! # takes care of rebalance and size--
node