Class Edges
- Namespace
- Graphity
- Assembly
- Graphity.Core.dll
A list of edges of a graph, each with its source, target and edge index. Algorithms such as Of(Graph) and Bridges return it.
public sealed class Edges
- Inheritance
-
Edges
- Inherited Members
Examples
Here, the back edges of the calls between the methods of a program are its recursive calls.
names holds the names of the methods, and siteCount holds the number of call sites
of each call, by edge index:
Edges recursive = BackEdges.Of(calls);
for (int p = 0; p < recursive.Count; p++)
{
int caller = recursive.SourceNodes[p];
int callee = recursive.TargetNodes[p];
int edge = recursive.EdgeIndices[p];
output.WriteLine($"{names[caller]} -> {names[callee]}: {siteCount[edge]}");
}
// parse -> parse: 2
// format -> format: 1
Remarks
The edge at position p, in 0..Count-1, is SourceNodes[p] -> TargetNodes[p],
and EdgeIndices[p] is its edge index in the graph the algorithm ran on. The edge index
finds the data of the edge in the caller's arrays indexed by edge index, without a search. Each
method that returns Edges says in which order the edges come.
AddEdges(Edges) adds them to a graph under construction.
Each of the three lists is an ImmutableArray<T>. Instances are immutable and safe to share between threads.
Memory: 12 bytes per edge.
Properties
Count
Gets the number of edges.
public int Count { get; }
Property Value
Remarks
Time: O(1).
EdgeIndices
Gets the edge index of each edge in the graph the algorithm ran on, by position.
public ImmutableArray<int> EdgeIndices { get; }
Property Value
Remarks
Time: O(1).
IsEmpty
Gets whether there are no edges. Equivalent to Count == 0.
public bool IsEmpty { get; }
Property Value
Remarks
Time: O(1).
SourceNodes
Gets the source of each edge, by position.
public ImmutableArray<int> SourceNodes { get; }
Property Value
Remarks
Time: O(1).
TargetNodes
Gets the target of each edge, by position.
public ImmutableArray<int> TargetNodes { get; }
Property Value
Remarks
Time: O(1).
Methods
Of(EdgeTypes, EdgeType)
Returns the edges of one type from an edge classification, in edge index order.
public static Edges Of(EdgeTypes edgeTypes, EdgeType type)
Parameters
edgeTypesEdgeTypesThe classification of the edges of a graph.
typeEdgeTypeThe edge type to collect.
Returns
- Edges
The edges of type
type.
Remarks
Each call goes through every edge, however few have the type: call it once per type and keep the result.
Time: O(NodeCount + EdgeCount).
Memory: 12 bytes per edge of the result.
Exceptions
- ArgumentOutOfRangeException
typeis not a defined EdgeType.