| Class | Puppet::SimpleGraph::VertexWrapper |
| In: |
lib/puppet/simple_graph.rb
|
| Parent: | Object |
An internal class for handling a vertex‘s edges.
| in | [RW] | |
| out | [RW] | |
| vertex | [RW] |
# File lib/puppet/simple_graph.rb, line 20
20: def initialize(vertex)
21: @vertex = vertex
22: @adjacencies = {:in => Hash.new { |h,k| h[k] = [] }, :out => Hash.new { |h,k| h[k] = [] }}
23: #@adjacencies = {:in => [], :out => []}
24: end
Add an edge to our list.
# File lib/puppet/simple_graph.rb, line 37
37: def add_edge(direction, edge)
38: @adjacencies[direction][other_vertex(direction, edge)] << edge
39: end
Find adjacent vertices or edges.
# File lib/puppet/simple_graph.rb, line 27
27: def adjacent(options)
28: direction = options[:direction] || :out
29: options[:type] ||= :vertices
30:
31: return @adjacencies[direction].values.flatten if options[:type] == :edges
32:
33: return @adjacencies[direction].keys
34: end
Remove all references to everything.
# File lib/puppet/simple_graph.rb, line 14
14: def clear
15: @adjacencies[:in].clear
16: @adjacencies[:out].clear
17: @vertex = nil
18: end
Test whether we share an edge with a given vertex.
# File lib/puppet/simple_graph.rb, line 47
47: def has_edge?(direction, vertex)
48: return true if @adjacencies[direction][vertex].length > 0
49: return false
50: end
The other vertex in the edge.
# File lib/puppet/simple_graph.rb, line 66
66: def other_vertex(direction, edge)
67: case direction
68: when :in: edge.source
69: else
70: edge.target
71: end
72: end