summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-28 14:58:52 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:42 -0600
commite8be6dcad2150769b51bf81e95c57491921e68c1 (patch)
tree999505f419e9f3474a94b0c14cee6de06db1ae5b /lib/puppet
parent6bb804fb840b3d08f759fb7b7b08633bc3f94a64 (diff)
downloadpuppet-e8be6dcad2150769b51bf81e95c57491921e68c1.tar.gz
Removing the Hash default proc from SimpleGraph.
Again, necessary so that the class can be dumped in Marshal or YAML. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/simple_graph.rb26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index c6afa4b68..b9ea0f394 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -19,8 +19,7 @@ class Puppet::SimpleGraph
def initialize(vertex)
@vertex = vertex
- @adjacencies = {:in => Hash.new { |h,k| h[k] = [] }, :out => Hash.new { |h,k| h[k] = [] }}
- #@adjacencies = {:in => [], :out => []}
+ @adjacencies = {:in => {}, :out => {}}
end
# Find adjacent vertices or edges.
@@ -35,7 +34,7 @@ class Puppet::SimpleGraph
# Add an edge to our list.
def add_edge(direction, edge)
- @adjacencies[direction][other_vertex(direction, edge)] << edge
+ opposite_adjacencies(direction, edge) << edge
end
# Return all known edges.
@@ -45,7 +44,7 @@ class Puppet::SimpleGraph
# Test whether we share an edge with a given vertex.
def has_edge?(direction, vertex)
- return true if @adjacencies[direction][vertex].length > 0
+ return true if vertex_adjacencies(direction, vertex).length > 0
return false
end
@@ -74,12 +73,29 @@ class Puppet::SimpleGraph
# Remove an edge from our list. Assumes that we've already checked
# that the edge is valid.
def remove_edge(direction, edge)
- @adjacencies[direction][other_vertex(direction, edge)].delete(edge)
+ opposite_adjacencies(direction, edge).delete(edge)
end
def to_s
vertex.to_s
end
+
+ private
+
+ # These methods exist so we don't need a Hash with a default proc.
+
+ # Look up the adjacencies for a vertex at the other end of an
+ # edge.
+ def opposite_adjacencies(direction, edge)
+ opposite_vertex = other_vertex(direction, edge)
+ vertex_adjacencies(direction, opposite_vertex)
+ end
+
+ # Look up the adjacencies for a given vertex.
+ def vertex_adjacencies(direction, vertex)
+ @adjacencies[direction][vertex] ||= []
+ @adjacencies[direction][vertex]
+ end
end
def initialize