Skip to content

BidirectionalMatrixGraph

Alexandre Rabérin edited this page May 11, 2020 · 1 revision

BidirectionalMatrixGraph

The BidirectionalMatrixGraph<TEdge> provides an efficient data structure to access the out-edges and the in-edges of a vertex of dense directed graphs with known number of vertices.

This class is mutable, serializable, cloneable and can be constructed in many different ways. Internally, the data structure keeps a 2D fixed size array of edges. Note that multi-edges are not supported in this graph structure.

int vertexCount = ...; // Must be known a-priori
var graph = new BidirectionalMatrixGraph<Edge<int>>(vertexCount);

foreach(int vertex in graph.Vertices)
{
    foreach(Edge<int> edge in graph.InEdges(vertex))
    {
        Console.WriteLine(edge);
    }
}

For sparse graphs, consider using AdjacencyGraph or BidirectionalGraph.

Clone this wiki locally