Table of Contents

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

TVertex

The vertex type.

TEdge

The 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

vertexComparer IEqualityComparer<TVertex>

The comparer used to identify vertices.

Exceptions

ArgumentNullException

vertexComparer is null.

Methods

AddEdge(TEdge)

Adds edge to the graph, adding missing endpoint vertices automatically.

public override bool AddEdge(TEdge edge)

Parameters

edge TEdge

The edge to add.

Returns

bool

true if added; false if the graph forbids the edge (e.g. a parallel edge on a simple graph).

Remarks

Also returns false when the edge would create a cycle, i.e. when its source is already reachable from its target.