Class Sccs
- Namespace
- Graphity
- Assembly
- Graphity.Core.dll
The SCCs (strongly connected components) of a graph, as SccsOf(Graph) returns them.
public sealed class Sccs : NodePartition
- Inheritance
-
Sccs
- Inherited Members
Examples
Here, dependencies are the dependencies between the packages of a program, and names
holds the names of the packages. The example groups the packages by SCC, in the order of the SCC
IDs. In this order, each package comes after the packages it uses, and the packages that use each
other come together:
// The SCCs in reverse topological order, each as the names of its packages.
Sccs sccs = Components.SccsOf(dependencies);
List<List<string>> buildOrder = [];
for (int scc = 0; scc < sccs.SccCount; scc++)
{
buildOrder.Add([.. sccs.NodesOf(scc).Select(node => names[node])]);
}
// buildOrder: [[util], [cli], [json], [model, storage], [service], [ui], [app]]
Remarks
It is a NodePartition whose groups are the SCCs, numbered by SCC ID
0..SccCount-1. SccOf(int) returns the SCC of a node and
NodesOf(int) the nodes of an SCC. ContainsCycle(int) distinguishes
the SCCs with a cycle from those of a single node without one.
Condense() returns the DAG (directed acyclic graph) of the SCCs.
Every node is in exactly one SCC; a node that lies on no cycle is an SCC of its own. SCC IDs are in reverse topological order: every edge between two SCCs goes from the higher SCC ID to the lower one, so SCC 0 has no edges to other SCCs. The nodes of each SCC are in ascending order.
Instances are immutable and safe to share between threads.
Memory: 4 x (2 x NodeCount + SccCount) bytes; the graph is shared, not copied.
Properties
IsStronglyConnected
Gets whether the graph is strongly connected: whether it has at most one SCC. Equivalent to
SccCount <= 1.
public bool IsStronglyConnected { get; }
Property Value
Remarks
A graph without nodes counts as strongly connected.
Time: O(1).
SccCount
Gets the number of SCCs. Equivalent to GroupCount.
public int SccCount { get; }
Property Value
Remarks
Time: O(1).
Methods
ContainsCycle(int)
Returns whether SCC sccId contains a cycle: whether it has more than one
node, or a single node with a self-loop.
public bool ContainsCycle(int sccId)
Parameters
sccIdintSCC ID in
0..SccCount-1.
Returns
Remarks
Time: O(1) for an SCC of more than one node, O(log OutDegree(v)) for an SCC of a
single node v.
Exceptions
- ArgumentOutOfRangeException
sccIdis out of range.
SccOf(int)
Returns the SCC ID of node. Equivalent to Get(node).
public int SccOf(int node)
Parameters
nodeintNode ID in
0..NodeCount-1.
Returns
- int
The SCC ID.
Remarks
Time: O(1).
Exceptions
- ArgumentOutOfRangeException
nodeis out of range.