Class Puppet::SimpleGraph::VertexWrapper
In: lib/puppet/simple_graph.rb
Parent: Object

An internal class for handling a vertex‘s edges.

Methods

add_edge   adjacent   clear   edges   has_edge?   new   other_vertex   remove_edge   to_s  

Attributes

in  [RW] 
out  [RW] 
vertex  [RW] 

Public Class methods

[Source]

    # 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

Public Instance methods

Add an edge to our list.

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # File lib/puppet/simple_graph.rb, line 14
14:         def clear
15:             @adjacencies[:in].clear
16:             @adjacencies[:out].clear
17:             @vertex = nil
18:         end

Return all known edges.

[Source]

    # File lib/puppet/simple_graph.rb, line 42
42:         def edges
43:             [:in, :out].collect { |dir| @adjacencies[dir].values }.flatten
44:         end

Test whether we share an edge with a given vertex.

[Source]

    # 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.

[Source]

    # 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

Remove an edge from our list. Assumes that we‘ve already checked that the edge is valid.

[Source]

    # File lib/puppet/simple_graph.rb, line 76
76:         def remove_edge(direction, edge)
77:             @adjacencies[direction][other_vertex(direction, edge)].delete(edge)
78:         end

[Source]

    # File lib/puppet/simple_graph.rb, line 80
80:         def to_s
81:             vertex.to_s
82:         end

[Validate]