lib/splay_tree.rb
#
# Possible side-effect on @root tree
#
Possible side-effect on @root tree
Possible side - effect on @root tree
def _rotate_hlp(x, y, dir=:left)
      puts("[1] ==> rotate: #{dir} - #{inspect(y)} - dir is #{dir.inspect}") if $VERBOSE
      p = y.pnode  
      puts("[1.1] ====> parent: #{p.inspect} // y is #{y.val} // x is: #{x.val}") if $VERBOSE
      if p.nil?
        @root = x
        @changed = true
      else
        y.val >= p.val ? p.rnode = x : p.lnode = x
        puts("== == ==> p rnode = #{p.rnode.val}") if $VERBOSE
      end
      if dir == :right
        x.rnode.pnode = y unless x.rnode.nil? 
        y.lnode = x.rnode 
        x.rnode = y
      elsif dir == :left
        x.lnode.pnode = y unless x.lnode.nil? 
        y.rnode = x.lnode                     
        x.lnode = y
      else
        raise ArgumentError,
              "expected dir to be :left or :right, got #{dir}"
      end
      x.pnode = p
      y.pnode = x
      puts("[2] ==> #{inspect(x)}") if $VERBOSE
    end
def _rotate_hlp ( x , y , dir = :left ) puts ( "[1] ==> rotate: #{dir} - #{inspect(y)} - dir is #{dir.inspect}" ) if $VERBOSE p = y . pnode puts ( "[1.1] ====> parent: #{p.inspect} // y is #{y.val} // x is: #{x.val}" ) if $VERBOSE if p . nil? @root = x @changed = true else y . val >= p . val ? p . rnode = x : p . lnode = x puts ( "== == ==> p rnode = #{p.rnode.val}" ) if $VERBOSE end if dir == :right x . rnode . pnode = y unless x . rnode . nil? y . lnode = x . rnode x . rnode = y elsif dir == :left x . lnode . pnode = y unless x . lnode . nil? y . rnode = x . lnode x . lnode = y else raise ArgumentError , "expected dir to be :left or :right, got #{dir}" end x . pnode = p y . pnode = x puts ( "[2] ==> #{inspect(x)}" ) if $VERBOSE end
Possible side-effect on @root tree
Possible side - effect on @root tree
# if it exists # is Y a left or right node of P? # set parent of B subtree # B subtree # set parent of B subtree # B subtree
x
<not_specific>
y
<not_specific>
dir
<not_specific>