Class: Grandprix::Graph::SuccessorTable
- Inherits:
-
Object
- Object
- Grandprix::Graph::SuccessorTable
- Defined in:
- lib/grandprix/graph.rb
Instance Method Summary collapse
-
#initialize(edges) ⇒ SuccessorTable
constructor
A new instance of SuccessorTable.
- #of(origin) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(edges) ⇒ SuccessorTable
Returns a new instance of SuccessorTable.
84 85 86 87 88 89 90 91 92 |
# File 'lib/grandprix/graph.rb', line 84 def initialize(edges) @successors = {} edges.each do |j, k| @successors[j] ||= [] @successors[k] ||= [] @successors[j].push k end end |
Instance Method Details
#of(origin) ⇒ Object
94 95 96 |
# File 'lib/grandprix/graph.rb', line 94 def of(origin) @successors[origin] end |
#to_s ⇒ Object
98 99 100 101 102 |
# File 'lib/grandprix/graph.rb', line 98 def to_s ks = @successors.keys.map{|k| k.to_s.rjust 6}.join(" ") vs = @successors.values.map{|v| v.inspect.rjust 6}.join(" ") "Successors :\n#{ks}\n#{vs}\n" end |