instance method
TSort#each_strongly_connected_component
() { (::Array[Node]) -> void } -> void
() -> ::Enumerator[::Array[Node], void]
each_strongly_connected_component() { |nodes| ... }
lib/tsort.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/tsort.rb, line 318
def each_strongly_connected_component(&block) # :yields: nodes
each_node = method(:tsort_each_node)
each_child = method(:tsort_each_child)
TSort.each_strongly_connected_component(each_node, each_child, &block)
end
The iterator version of the strongly_connected_components method. <em>obj</em>.each_strongly_connected_component is similar to <em>obj</em>.strongly_connected_components.each, but modification of obj during the iteration may lead to unexpected results.
each_strongly_connected_component returns nil.
Example
class G include TSort def initialize(g) @g = g end def tsort_each_child(n, &b) @g[n].each(&b) end def tsort_each_node(&b) @g.each_key(&b) end end graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}) graph.each_strongly_connected_component {|scc| p scc } #=> [4] # [2] # [3] # [1] graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}) graph.each_strongly_connected_component {|scc| p scc } #=> [4] # [2, 3] # [1]
See also
.each_strongly_connected_component
.tsort_each
#each_strongly_connected_component_from
.tsort
also in
3.4 · 3.3 · 3.2 · 3.1 · 3.0