Method: PathUtil.path_arrays
- Defined in:
- lib/util/path_util.rb
.path_arrays(predecessors, start) ⇒ Object
Returns hash mapping each vertex to the shortest path from the start to that vertex
5 6 7 8 9 10 11 12 13 |
# File 'lib/util/path_util.rb', line 5 def self.path_arrays(predecessors, start) paths = Hash.new { [] } start_has_outgoing_edges = false predecessors.each do |v, pred| start_has_outgoing_edges = true if pred == start paths[v] = path_to_vertex(paths, predecessors, start, v) end start_has_outgoing_edges ? paths : {} end |