Class: Wads::GraphReverseIterator

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#outputObject

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