Table of Contents

Interface IReadOnlyGraph<TVertex, TEdge>

Namespace
Graph1x
Assembly
Graph1x.dll

Read-only view over a graph: vertex/edge enumeration and structural queries. All graph implementations, directed or undirected, sparse or dense, expose this contract.

public interface IReadOnlyGraph<TVertex, TEdge> where TVertex : notnull where TEdge : IEdge<TVertex>

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

Extension Methods

Properties

AllowsParallelEdges

Gets a value indicating whether the graph admits parallel edges between the same endpoints.

bool AllowsParallelEdges { get; }

Property Value

bool

EdgeCount

Gets the number of edges in the graph.

int EdgeCount { get; }

Property Value

int

Edges

Gets the edges of the graph.

IEnumerable<TEdge> Edges { get; }

Property Value

IEnumerable<TEdge>

IsDirected

Gets a value indicating whether edges are directed.

bool IsDirected { get; }

Property Value

bool

VertexComparer

Gets the comparer used to identify vertices.

IEqualityComparer<TVertex> VertexComparer { get; }

Property Value

IEqualityComparer<TVertex>

VertexCount

Gets the number of vertices in the graph.

int VertexCount { get; }

Property Value

int

Vertices

Gets the vertices of the graph.

IEnumerable<TVertex> Vertices { get; }

Property Value

IEnumerable<TVertex>

Methods

AdjacentEdges(TVertex)

Gets the edges incident to vertex. On directed graphs this includes both incoming and outgoing edges.

IEnumerable<TEdge> AdjacentEdges(TVertex vertex)

Parameters

vertex TVertex

The vertex whose incident edges to enumerate.

Returns

IEnumerable<TEdge>

The incident edges.

Exceptions

ArgumentException

The vertex is not in the graph.

ContainsEdge(TVertex, TVertex)

Determines whether the graph contains an edge between source and target. On undirected graphs the endpoint order is irrelevant.

bool ContainsEdge(TVertex source, TVertex target)

Parameters

source TVertex

The first endpoint.

target TVertex

The second endpoint.

Returns

bool

true if such an edge is present.

ContainsVertex(TVertex)

Determines whether the graph contains vertex.

bool ContainsVertex(TVertex vertex)

Parameters

vertex TVertex

The vertex to look up.

Returns

bool

true if the vertex is present.

Degree(TVertex)

Gets the degree of vertex. Self-loops count twice on undirected graphs; on directed graphs the degree is in-degree plus out-degree.

int Degree(TVertex vertex)

Parameters

vertex TVertex

The vertex to measure.

Returns

int

The number of edge endpoints incident to the vertex.

Exceptions

ArgumentException

The vertex is not in the graph.