Class: Wads::GraphReverseIterator
- Inherits:
-
Object
- Object
- Wads::GraphReverseIterator
- Defined in:
- lib/wads/data_structures.rb
Overview
An internally used data structure that facilitates walking from the leaf nodes up to the top of the graph, such that a node is only visited once all of its descendants have been visited.
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(graph) ⇒ GraphReverseIterator
constructor
A new instance of GraphReverseIterator.
- #process_node(node) ⇒ Object
Constructor Details
#initialize(graph) ⇒ GraphReverseIterator
Returns a new instance of GraphReverseIterator.
727 728 729 730 731 732 733 |
# File 'lib/wads/data_structures.rb', line 727 def initialize(graph) @output = [] graph.root_nodes.each do |root| partial_list = process_node(root) @output.push(*partial_list) end end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
726 727 728 |
# File 'lib/wads/data_structures.rb', line 726 def output @output end |
Instance Method Details
#process_node(node) ⇒ Object
735 736 737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/wads/data_structures.rb', line 735 def process_node(node) list = [] node.outputs.each do |child_node| if child_node.is_a? Edge child_node = child_node.destination end child_list = process_node(child_node) list.push(*child_list) end list << node list end |