Class DirectedGraphNode<TKey, TNodeValue, TEdgeValue>
- Namespace
- LfrlAnvil.Collections
- Assembly
- LfrlAnvil.Collections.dll
Represents a generic IDirectedGraph<TKey, TNodeValue, TEdgeValue> node.
public sealed class DirectedGraphNode<TKey, TNodeValue, TEdgeValue> : IDirectedGraphNode<TKey, TNodeValue, TEdgeValue> where TKey : notnull
Type Parameters
TKeyGraph's key type.
TNodeValueGraph node's value type.
TEdgeValueGraph edge's value type.
- Inheritance
-
DirectedGraphNode<TKey, TNodeValue, TEdgeValue>
- Implements
-
IDirectedGraphNode<TKey, TNodeValue, TEdgeValue>
- Inherited Members
- Extension Methods
Properties
Edges
Collection of IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instances connected to this node.
public IReadOnlyCollection<DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>> Edges { get; }
Property Value
- IReadOnlyCollection<DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>>
Graph
Associated IReadOnlyDirectedGraph<TKey, TNodeValue, TEdgeValue> instance associated with this node.
public DirectedGraph<TKey, TNodeValue, TEdgeValue>? Graph { get; }
Property Value
- DirectedGraph<TKey, TNodeValue, TEdgeValue>
Key
Underlying key.
public TKey Key { get; }
Property Value
- TKey
Value
Underlying value.
public TNodeValue Value { get; set; }
Property Value
- TNodeValue
Methods
AddEdgeTo(DirectedGraphNode<TKey, TNodeValue, TEdgeValue>, TEdgeValue, GraphDirection)
Adds a new edge that connects this node and the provided target node.
public DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> AddEdgeTo(DirectedGraphNode<TKey, TNodeValue, TEdgeValue> node, TEdgeValue value, GraphDirection direction = GraphDirection.Out)
Parameters
nodeDirectedGraphNode<TKey, TNodeValue, TEdgeValue>Target node.
valueTEdgeValueEdge's value.
directionGraphDirectionEdge's direction. Equal to Out by default.
Returns
- DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>
Created DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance.
Remarks
When source and target nodes are the same, then the direction will be equal to Both.
Exceptions
- InvalidOperationException
When this node has been removed.
- ArgumentException
When
directionis equal to None or when the edge already exists or when the target node does not belong to the same graph.
AddEdgeTo(TKey, TEdgeValue, GraphDirection)
Adds a new edge that connects this node and a node associated with the specified key.
public DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> AddEdgeTo(TKey key, TEdgeValue value, GraphDirection direction = GraphDirection.Out)
Parameters
keyTKeyTarget node's key.
valueTEdgeValueEdge's value.
directionGraphDirectionEdge's direction. Equal to Out by default.
Returns
- DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>
Created DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance.
Remarks
When source and target nodes are the same, then the direction will be equal to Both.
Exceptions
- InvalidOperationException
When this node has been removed.
- KeyNotFoundException
When target node's key does not exist in this graph.
- ArgumentException
When
directionis equal to None or when the edge already exists.
ContainsEdgeTo(TKey)
Checks whether or not this node is connected with a node associated with the provided key.
[Pure]
public bool ContainsEdgeTo(TKey key)
Parameters
keyTKeyNode's key to check.
Returns
- bool
true when the two nodes are directly connected, otherwise false.
GetEdgeTo(TKey)
Returns an IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance that connects this node
and the node associated with the provided key.
[Pure]
public DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> GetEdgeTo(TKey key)
Parameters
keyTKeyOther node's key.
Returns
- DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>
Exceptions
- KeyNotFoundException
When an edge to the node associated with the specified
keydoes not exist.
GetReachableNodes(GraphDirection)
Creates a new IEnumerable<T> instance that contains all graph nodes that are reachable from this node,
using the provided direction.
[Pure]
public IEnumerable<DirectedGraphNode<TKey, TNodeValue, TEdgeValue>> GetReachableNodes(GraphDirection direction = GraphDirection.Out)
Parameters
directionGraphDirectionDirection of node traversal. Equal to Out by default.
Returns
- IEnumerable<DirectedGraphNode<TKey, TNodeValue, TEdgeValue>>
New IEnumerable<T> instance.
Remove()
Removes this node from the associated Graph.
public void Remove()
Remarks
Removes all connected edges as well.
Exceptions
- InvalidOperationException
When this node has already been removed.
Remove(DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)
Attempts to remove the provided edge.
public bool Remove(DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> edge)
Parameters
edgeDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>Edge to remove.
Returns
- bool
true when the edge was connected to this node and was removed, otherwise false.
Exceptions
- InvalidOperationException
When this node has been removed.
RemoveEdgeTo(TKey)
Attempts to remove an edge that connects this node and a node associated with the specified key.
public bool RemoveEdgeTo(TKey key)
Parameters
keyTKeyOther node's key.
Returns
- bool
true when the edge was removed, otherwise false.
Exceptions
- InvalidOperationException
When this node has been removed.
RemoveEdgeTo(TKey, out TEdgeValue)
Attempts to remove an edge that connects this node and a node associated with the specified key.
public bool RemoveEdgeTo(TKey key, out TEdgeValue removed)
Parameters
keyTKeyOther node's key.
removedTEdgeValueout parameter that returns removed edge's value.
Returns
- bool
true when the edge was removed, otherwise false.
Exceptions
- InvalidOperationException
When this node has been removed.
RemoveEdges(GraphDirection)
Removes all edges connected to this node that contain the provided direction.
public int RemoveEdges(GraphDirection direction)
Parameters
directionGraphDirectionDirection that specifies which edges to remove.
Returns
- int
Number of removed edges.
Exceptions
- InvalidOperationException
When this node has been removed.
ToString()
Returns a string representation of this DirectedGraphNode<TKey, TNodeValue, TEdgeValue> instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
TryAddEdgeTo(DirectedGraphNode<TKey, TNodeValue, TEdgeValue>, TEdgeValue, GraphDirection, out DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)
Attempts to add a new edge that connects this node and the provided target node.
public bool TryAddEdgeTo(DirectedGraphNode<TKey, TNodeValue, TEdgeValue> node, TEdgeValue value, GraphDirection direction, out DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> result)
Parameters
nodeDirectedGraphNode<TKey, TNodeValue, TEdgeValue>Target node.
valueTEdgeValueEdge's value.
directionGraphDirectionEdge's direction.
resultDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>out parameter that returns the created DirectedGraphEdge<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
- InvalidOperationException
When this node has been removed.
- ArgumentException
When
directionis equal to None.
TryAddEdgeTo(TKey, TEdgeValue, GraphDirection, out DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)
Attempts to add a new edge that connects this node and a node associated with the specified key.
public bool TryAddEdgeTo(TKey key, TEdgeValue value, GraphDirection direction, out DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> result)
Parameters
keyTKeyTarget node's key.
valueTEdgeValueEdge's value.
directionGraphDirectionEdge's direction.
resultDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>out parameter that returns the created DirectedGraphEdge<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
- InvalidOperationException
When this node has been removed.
- ArgumentException
When
directionis equal to None.
TryGetEdgeTo(TKey, out DirectedGraphEdge<TKey, TNodeValue, TEdgeValue>)
Attempts to return an IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance that connects this node
and the node associated with the provided key.
public bool TryGetEdgeTo(TKey key, out DirectedGraphEdge<TKey, TNodeValue, TEdgeValue> result)
Parameters
keyTKeyOther node's key.
resultDirectedGraphEdge<TKey, TNodeValue, TEdgeValue>out parameter that returns an IDirectedGraphEdge<TKey, TNodeValue, TEdgeValue> instance.
Returns
- bool
true when the connection exists, otherwise false.