instance method
TSort#each_strongly_connected_component_from
(Node, ?untyped id_map, ?untyped stack) { (::Array[Node]) -> void } -> void
(Node, ?untyped id_map, ?untyped stack) -> ::Enumerator[::Array[Node], void]
each_strongly_connected_component_from(node, id_map={}, stack=[]) { |nodes| ... }
lib/tsort.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/tsort.rb, line 388
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
3.4 · 3.3 · 3.2 · 3.1 · 3.0