class RowOfNodes
Public Class Methods
new(tree)
click to toggle source
# File lib/generic/row_of_nodes.rb, line 9 def initialize(tree) @tree = tree @array = Array.new(tree.values.size, [0,0]) end
Public Instance Methods
row_of_nodes()
click to toggle source
# File lib/generic/row_of_nodes.rb, line 14 def row_of_nodes n = @tree.root_id set_row_of_nodes(n) @array.map { |xx| xx[0] } end
Private Instance Methods
set_row_of_nodes(id)
click to toggle source
# File lib/generic/row_of_nodes.rb, line 22 def set_row_of_nodes(id) if @tree.leaf? id @array[id][1] = 1 return end children_id = @tree.children(id) for i in 0...children_id.size child_id = children_id[i] a = @array[id][0] + @array[id][1] # @array[child_id][0] = @array[id][0] + @array[id][1] @array[child_id] = [a, @array[child_id][1]] set_row_of_nodes(child_id) # @array[id][1] += @array[child_id][1] b = @array[id][1] + @array[child_id][1] @array[id] = [@array[id][0], b] end end