Class DirectedAcyclicGraph<TVertex, TEdge>
- Namespace
- Graph1x
- Assembly
- Graph1x.dll
A directed graph that maintains acyclicity as an invariant: adding an edge that would create a cycle (including a self-loop) is rejected with false, mirroring how duplicates are rejected.
public class DirectedAcyclicGraph<TVertex, TEdge> : DirectedGraph<TVertex, TEdge>, IDirectedGraph<TVertex, TEdge>, IMutableGraph<TVertex, TEdge>, IReadOnlyGraph<TVertex, TEdge> where TVertex : notnull where TEdge : IEdge<TVertex>
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
- Inheritance
-
DirectedGraph<TVertex, TEdge>DirectedAcyclicGraph<TVertex, TEdge>
- Implements
-
IDirectedGraph<TVertex, TEdge>IMutableGraph<TVertex, TEdge>IReadOnlyGraph<TVertex, TEdge>
- Inherited Members
- Extension Methods
Constructors
DirectedAcyclicGraph()
Initializes an empty DAG using the default vertex comparer.
public DirectedAcyclicGraph()
DirectedAcyclicGraph(IEqualityComparer<TVertex>)
Initializes an empty DAG using vertexComparer to identify vertices.
public DirectedAcyclicGraph(IEqualityComparer<TVertex> vertexComparer)
Parameters
vertexComparerIEqualityComparer<TVertex>The comparer used to identify vertices.
Exceptions
- ArgumentNullException
vertexCompareris null.
Methods
AddEdge(TEdge)
Adds edge to the graph, adding missing endpoint
vertices automatically.
public override bool AddEdge(TEdge edge)
Parameters
edgeTEdgeThe edge to add.
Returns
Remarks
Also returns false when the edge would create a cycle, i.e. when its source is already reachable from its target.