Table of Contents

Interface IReadOnlyDirectedGraph<TKey, TNodeValue, TEdgeValue>

Namespace
LfrlAnvil.Collections
Assembly
LfrlAnvil.Collections.dll

Represents a generic read-only directed graph data structure.

public interface IReadOnlyDirectedGraph<TKey, TNodeValue, TEdgeValue> where TKey : notnull

Type Parameters

TKey

Key type.

TNodeValue

Node's value type.

TEdgeValue

Node's edge type.

Properties

Edges

Specifies the current collection of IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instances that belong to this graph.

IEnumerable<IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>> Edges { get; }

Property Value

IEnumerable<IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>>

KeyComparer

Key equality comparer.

IEqualityComparer<TKey> KeyComparer { get; }

Property Value

IEqualityComparer<TKey>

Nodes

Specifies the current collection of IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instances that belong to this graph.

IReadOnlyCollection<IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>> Nodes { get; }

Property Value

IReadOnlyCollection<IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>>

Methods

Contains(IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)

Checks whether or not the provided edge exists in this graph.

[Pure]
bool Contains(IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> edge)

Parameters

edge IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>

Edge to check.

Returns

bool

true when edge exists, otherwise false.

Contains(IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>)

Checks whether or not the provided node exists in this graph.

[Pure]
bool Contains(IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> node)

Parameters

node IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>

Node to check.

Returns

bool

true when node exists, otherwise false.

ContainsEdge(TKey, TKey)

Checks whether or not an edge that connects nodes associated with the firstKey and secondKey exists in this graph.

[Pure]
bool ContainsEdge(TKey firstKey, TKey secondKey)

Parameters

firstKey TKey

Key of the first node to check.

secondKey TKey

Key of the second node to check.

Returns

bool

true when edge exists, otherwise false.

ContainsNode(TKey)

Checks whether or not a node with the specified key exists in this graph.

[Pure]
bool ContainsNode(TKey key)

Parameters

key TKey

Key to check.

Returns

bool

true when node exists, otherwise false.

GetEdge(TKey, TKey)

Returns the edge that connects nodes associated with the specified firstKey and secondKey.

[Pure]
IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> GetEdge(TKey firstKey, TKey secondKey)

Parameters

firstKey TKey

First node's key.

secondKey TKey

Second node's key.

Returns

IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>

IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance that connects nodes associated with firstKey and secondKey.

Exceptions

KeyNotFoundException

When firstKey does not exist in this graph or when an edge from the first node to the node associated with the specified secondKey does not exist.

GetNode(TKey)

Returns the node associated with the specified key.

[Pure]
IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> GetNode(TKey key)

Parameters

key TKey

Node's key.

Returns

IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>

IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance associated with the provided key.

Exceptions

KeyNotFoundException

When key does not exist in this graph.

TryGetEdge(TKey, TKey, out IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)

Returns the edge that connects nodes associated with the specified firstKey and secondKey.

[Pure]
bool TryGetEdge(TKey firstKey, TKey secondKey, out IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> result)

Parameters

firstKey TKey

First node's key.

secondKey TKey

Second node's key.

result IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>

out parameter that returns an IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance that connects nodes associated with firstKey and secondKey.

Returns

bool

true when the edge exists, otherwise false.

TryGetNode(TKey, out IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>)

Attempts to return the node associated with the specified key.

bool TryGetNode(TKey key, out IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> result)

Parameters

key TKey

Node's key.

result IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>

out parameter that returns an IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance associated with the provided key.

Returns

bool

true when the node exists, otherwise false.