lib/treemap/tree_map.rb
# Rotates the subtree so that its root's right child is the new root
Rotates the subtree so that its root's right child is the new root
Rotates the subtree so that its root ' s right child is the new root
def rotate_left(root)
    left = root.left
    pivot = root.right
    pivot_left = pivot.left
    pivot_right = pivot.right
    root.right = pivot_left
    if pivot_left
      pivot_left.parent = root
    end
    replace_in_parent(root, pivot)
    pivot.left = root
    root.parent = pivot
    root.height = [left ? left.height : 0, pivot_left ? pivot_left.height : 0].max + 1
    pivot.height = [root.height, pivot_right ? pivot_right.height : 0].max + 1
  end
def rotate_left ( root ) left = root . left pivot = root . right pivot_left = pivot . left pivot_right = pivot . right root . right = pivot_left if pivot_left pivot_left . parent = root end replace_in_parent ( root , pivot ) pivot . left = root root . parent = pivot root . height = [ left ? left . height : 0 , pivot_left ? pivot_left . height : 0 ] . max + 1 pivot . height = [ root . height , pivot_right ? pivot_right . height : 0 ] . max + 1 end
Rotates the subtree so that its root's right child is the new root
Rotates the subtree so that its root ' s right child is the new root
# move the pivot's left child to the root's right # move the root to the pivot's left # fix heights
root