module Bundler::TSort
def each_strongly_connected_component(&block) # :yields: nodes
# [1]
# [2, 3]
#=> [4]
graph.each_strongly_connected_component {|scc| p scc }
graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
# [1]
# [3]
# [2]
#=> [4]
graph.each_strongly_connected_component {|scc| p scc }
graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
end
def tsort_each_node(&b) @g.each_key(&b) end
def tsort_each_child(n, &b) @g[n].each(&b) end
end
@g = g
def initialize(g)
include Bundler::TSort
class G
#each_strongly_connected_component returns +nil+.
modification of _obj_ during the iteration may lead to unexpected results.
obj.strongly_connected_components.each, but
obj.each_strongly_connected_component is similar to
The iterator version of the #strongly_connected_components method.
def each_strongly_connected_component(&block) # :yields: nodes each_node = method(:tsort_each_node) each_child = method(:tsort_each_child) Bundler::TSort.each_strongly_connected_component(each_node, each_child, &block) end