Method: Puppet::Graph::SimpleGraph#walk
- Defined in:
- lib/puppet/graph/simple_graph.rb
#walk(source, direction) ⇒ Object
Just walk the tree and pass each edge.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/puppet/graph/simple_graph.rb', line 357 def walk(source, direction) # Use an iterative, breadth-first traversal of the graph. One could do # this recursively, but Ruby's slow function calls and even slower # recursion make the shorter, recursive algorithm cost-prohibitive. stack = [source] seen = Set.new until stack.empty? node = stack.shift next if seen.member? node connected = adjacent(node, :direction => direction) connected.each do |target| yield node, target end stack.concat(connected) seen << node end end |