The weak connected components of a digraph are the usual connected components of its associated undirected graph, i.e. the graph obtained by replacing each arc by an edge.
var g = new HashDigraph[Int]
g.add_arc(1, 2)
g.add_arc(2, 3)
g.add_arc(4, 5)
assert g.weakly_connected_components.number_of_subsets == 2
# Returns the weak connected components of this digraph.
#
# The weak connected components of a digraph are the usual
# connected components of its associated undirected graph,
# i.e. the graph obtained by replacing each arc by an edge.
#
# ~~~
# var g = new HashDigraph[Int]
# g.add_arc(1, 2)
# g.add_arc(2, 3)
# g.add_arc(4, 5)
# assert g.weakly_connected_components.number_of_subsets == 2
# ~~~
fun weakly_connected_components: DisjointSet[V]
do
var components = new DisjointSet[V]
components.add_all(vertices)
for arc in arcs_iterator do
components.union(arc[0], arc[1])
end
return components
end
lib/graph/digraph.nit:567,2--588,4