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
TKeyKey type.
TNodeValueNode's value type.
TEdgeValueNode'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
firstKeyTKeySource node's key.
secondKeyTKeyTarget node's key.
valueTEdgeValueEdge's value.
directionGraphDirectionEdge'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
directionis 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
keyTKeyNode's key.
valueTNodeValueNode's value.
Returns
- IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>
Created IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance.
Exceptions
- ArgumentException
When the provided
keyalready 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
keyTKeyNode's key.
valueTNodeValueNode'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
edgeIDirectedGraphEdge<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
nodeIDirectedGraphNode<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
firstKeyTKeyKey of the first node.
secondKeyTKeyKey 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
firstKeyTKeyKey of the first node.
secondKeyTKeyKey of the second node.
removedTEdgeValueout 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
keyTKeyKey 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
keyTKeyKey to remove.
removedTNodeValueout 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
firstKeyTKeySource node's key.
secondKeyTKeyTarget node's key.
valueTEdgeValueEdge's value.
directionGraphDirectionEdge's direction.
addedIDirectedGraphEdge<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
directionis 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
keyTKeyNode's key.
valueTNodeValueNode's value.
addedIDirectedGraphNode<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.