Skip to content
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| ... }

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]