class RFlare::Results
Public Class Methods
new(edges, nodes, ss, root)
click to toggle source
# File lib/rflare.rb, line 135 def initialize edges, nodes, ss, root @ss, @root = ss, root @edges_byfrom = Hash.new {|h,k| h[k] = [] } edges.each {|edge| @edges_byfrom[edge.from] << edge } @nodes_byid = Hash.new nodes.each {|node| @nodes_byid[node.id] = node} end
Public Instance Methods
each() { |match| ... }
click to toggle source
start at root, looking for trees
# File lib/rflare.rb, line 146 def each @root.valid.each {|row, col| matches(row, col, @root).each { |match| yield match } } end
Private Instance Methods
matches(row, col, node)
click to toggle source
# File lib/rflare.rb, line 154 def matches row, col, node return [] if !node.matches(@ss, row, col) me = {node.id => @ss[row,col]} edges = @edges_byfrom[node.id] return [me] if edges.empty? # get array with dims: # (1) each edge from this # -- we flatten the square-for-each-edge dim # (2) each match (a Hash) from edge edge_matches = edges.map do |edge| to = @nodes_byid[edge.to] sq = edge.get_square(row, col, @ss.row_bounds, @ss.col_bounds) paths = sq.flat_map do |sq_row, sq_col| matches sq_row, sq_col, to end paths.select {|a| !a.empty?} end [me].product(*edge_matches).map do |assignments_arr| assignments_arr.inject Hash.new, :merge end end