Class EdgeTypes
- Namespace
- Graphity
- Assembly
- Graphity.Core.dll
The type of every edge of a graph in a depth-first search: tree, back, forward or cross edge, as EdgeType defines them.
public sealed class EdgeTypes
- Inheritance
-
EdgeTypes
- Inherited Members
Examples
Here, cfg is the control flow of a method with a loop and a branch: the edge
next -> header closes the loop, and body -> next skips then:
EdgeTypes types = EdgeTypes.Of(cfg);
EdgeType loopEdge = types.TypeOf(cfg.EdgeIndexOf(next, header));
Edges forwardEdges = Edges.Of(types, EdgeType.Forward);
// loopEdge: Back
// forwardEdges: body -> next
Remarks
The types depend on the search. Uses a depth-first search, without recursion. The search starts at the nodes in ascending order and takes the out-nodes of each node in ascending order, as Run() does. TypeOf(int) returns the type of one edge, and Of(EdgeTypes, EdgeType) collects the edges of one type.
A graph is a DAG (directed acyclic graph) exactly if it has no back edge. For the back edges alone, Of(Graph) saves the classification of the other edges.
Instances are immutable and safe to share between threads.
Memory: 1 byte per edge; an instance also keeps a reference to its graph.
Methods
Of(Graph)
Returns the type of every edge of graph, from one depth-first search.
public static EdgeTypes Of(Graph graph)
Parameters
graphGraphThe graph to classify.
Returns
- EdgeTypes
The edge types.
Remarks
Time: O(NodeCount + EdgeCount).
Memory: EdgeCount bytes for the result; while it runs, 4 bytes and 2 bits per node, and
up to 8 x NodeCount bytes for the stack, which grows with the deepest path.
Exceptions
- ArgumentException
A depth-first path is longer than 2^30 - 29 nodes.
TypeOf(int)
Returns the type of edge edgeIndex.
public EdgeType TypeOf(int edgeIndex)
Parameters
edgeIndexintEdge index in
0..EdgeCount-1.
Returns
- EdgeType
The edge type.
Remarks
Time: O(1).
Exceptions
- ArgumentOutOfRangeException
edgeIndexis out of range.