Method: BiDimensionalTree#balance_horiz

Defined in:
lib/bi-dimensional-access.rb

#balance_horiz(node = @root) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/bi-dimensional-access.rb', line 185

def balance_horiz(node = @root)
  return if balanced_horiz?

  nodes = get_nodes_horiz([], node)

  @root = nodes[nodes.length / 2]
  @root.west = nil
  @root.east = nil

  @root.west = new_balance_nodes_horiz(nodes[0..(nodes.length / 2) - 1])
  @root.east = new_balance_nodes_horiz(nodes[(nodes.length / 2) + 1..-1])
end