Interface IDirectedGraph<TKey, TNodeValue, TEdgeValue>
- Namespace
- LfrlAnvil.Collections
- Assembly
- LfrlAnvil.Collections.dll
Represents a generic directed graph data structure.
public interface IDirectedGraph<TKey, TNodeValue, TEdgeValue> : IReadOnlyDirectedGraph<TKey, TNodeValue, TEdgeValue> where TKey : notnull
Type Parameters
TKey
Key type.
TNodeValue
Node's value type.
TEdgeValue
Node's edge type.
- Inherited Members
Methods
AddEdge(TKey, TKey, TEdgeValue, GraphDirection)
Adds a new edge to this graph.
IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> AddEdge(TKey firstKey, TKey secondKey, TEdgeValue value, GraphDirection direction = GraphDirection.Out)
Parameters
firstKey
TKeySource node's key.
secondKey
TKeyTarget node's key.
value
TEdgeValueEdge's value.
direction
GraphDirectionEdge's direction. Equal to Out by default.
Returns
- IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>
Created IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance.
Remarks
When source and target nodes are the same, then the direction
will be equal to Both.
Exceptions
- KeyNotFoundException
When source or target node's key does not exist in this graph.
- ArgumentException
When
direction
is equal to None or when the edge already exists.
AddNode(TKey, TNodeValue)
Adds a new node to this graph.
IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> AddNode(TKey key, TNodeValue value)
Parameters
key
TKeyNode's key.
value
TNodeValueNode's value.
Returns
- IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>
Created IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance.
Exceptions
- ArgumentException
When the provided
key
already exists in this graph.
Clear()
Removes all nodes and edges from this graph.
void Clear()
GetOrAddNode(TKey, TNodeValue)
Gets an existing node or adds a new node to this graph if it does not exist.
IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> GetOrAddNode(TKey key, TNodeValue value)
Parameters
key
TKeyNode's key.
value
TNodeValueNode's value.
Returns
- IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>
An existing IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> with unchanged Value or a created IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance if it did not exist.
Remove(IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)
Attempts to remove the provided edge
.
bool Remove(IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> edge)
Parameters
edge
IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>Edge to remove.
Returns
- bool
true when edge was removed, otherwise false.
Remove(IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>)
Attempts to remove the provided node
.
bool Remove(IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> node)
Parameters
node
IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>Node to remove.
Returns
- bool
true when node was removed, otherwise false.
Remarks
Removes all connected edges as well.
RemoveEdge(TKey, TKey)
Attempts to remove an edge that connects nodes associated
with the specified firstKey
and secondKey
.
bool RemoveEdge(TKey firstKey, TKey secondKey)
Parameters
firstKey
TKeyKey of the first node.
secondKey
TKeyKey of the second node.
Returns
- bool
true when edge was removed, otherwise false.
RemoveEdge(TKey, TKey, out TEdgeValue)
Attempts to remove an edge that connects nodes associated
with the specified firstKey
and secondKey
.
bool RemoveEdge(TKey firstKey, TKey secondKey, out TEdgeValue removed)
Parameters
firstKey
TKeyKey of the first node.
secondKey
TKeyKey of the second node.
removed
TEdgeValueout parameter that returns the removed edge's value.
Returns
- bool
true when edge was removed, otherwise false.
RemoveNode(TKey)
Attempts to remove a node associated with the specified key
.
bool RemoveNode(TKey key)
Parameters
key
TKeyKey to remove.
Returns
- bool
true when node was removed, otherwise false.
Remarks
Removes all connected edges as well.
RemoveNode(TKey, out TNodeValue)
Attempts to remove a node associated with the specified key
.
bool RemoveNode(TKey key, out TNodeValue removed)
Parameters
key
TKeyKey to remove.
removed
TNodeValueout parameter that returns the removed node's value.
Returns
- bool
true when node was removed, otherwise false.
Remarks
Removes all connected edges as well.
TryAddEdge(TKey, TKey, TEdgeValue, GraphDirection, out IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)
Attempts to add a new edge to this graph.
bool TryAddEdge(TKey firstKey, TKey secondKey, TEdgeValue value, GraphDirection direction, out IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> added)
Parameters
firstKey
TKeySource node's key.
secondKey
TKeyTarget node's key.
value
TEdgeValueEdge's value.
direction
GraphDirectionEdge's direction.
added
IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>out parameter that returns the created IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance.
Returns
- bool
true when a new edge was added, otherwise false.
Remarks
When source and target nodes are the same, then the direction
will be equal to Both.
Exceptions
- ArgumentException
When
direction
is equal to None.
TryAddNode(TKey, TNodeValue, out IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>)
Attempts to add a new node to this graph.
bool TryAddNode(TKey key, TNodeValue value, out IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> added)
Parameters
key
TKeyNode's key.
value
TNodeValueNode's value.
added
IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>out parameter that returns the created IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance.
Returns
- bool
true when a new node was added, otherwise false.