End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
TSort#each_strongly_connected_component_from
each_strongly_connected_component_from(node, id_map={}, stack=[]) { |nodes| ... }
lib/tsort.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/tsort.rb, line 383
def each_strongly_connected_component_from(node, id_map={}, stack=[], &block) # :yields: nodes
TSort.each_strongly_connected_component_from(node, method(:tsort_each_child), id_map, stack, &block)
end
Iterates over strongly connected component in the subgraph reachable from node.
Return value is unspecified.
each_strongly_connected_component_from doesn’t call tsort_each_node.
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_from(2) {|scc| p scc } #=> [4] # [2] graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}) graph.each_strongly_connected_component_from(2) {|scc| p scc } #=> [4] # [2, 3]
See also
.each_strongly_connected_component_from
#each_strongly_connected_component
#strongly_connected_components
.tsort_each
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1