Skip to content

Commit 9c04abd

Browse files
committed
Document grapht::SCCs
The security product was relying on the SCC ordering this function produces, so we thought we ought to document our expectation that SCCs were topologically ordered.
1 parent 0b17511 commit 9c04abd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/util/graph.h

+12
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,18 @@ void grapht<N>::tarjan(tarjant &t, node_indext v) const
601601
}
602602
}
603603

604+
/// Computes strongly-connected components of a graph and yields a vector
605+
/// expressing a mapping from nodes to components indices. For example, if nodes
606+
/// 1 and 3 are in SCC 0, and nodes 0, 2 and 4 are in SCC 1, this will leave
607+
/// `subgraph_nr` holding `{ 1, 0, 1, 0, 1 }`, and the function will return 2
608+
/// (the number of distinct SCCs).
609+
/// Lower-numbered SCCs are closer to the leaves, so in the particular case
610+
/// of a DAG, sorting by SCC number gives a topological sort, and for a cyclic
611+
/// graph the SCCs are topologically sorted but arbitrarily ordered internally.
612+
/// \param subgraph_nr [in, out]: should be pre-allocated with enough storage
613+
/// for one entry per graph node. Will be populated with the SCC indices of
614+
/// each node.
615+
/// \return the number of distinct SCCs.
604616
template<class N>
605617
std::size_t grapht<N>::SCCs(std::vector<node_indext> &subgraph_nr) const
606618
{

0 commit comments

Comments
 (0)