Class GraphWeightedMap<T, TWeight, TEquate, THash>
Implements a weighted graph. Implements a Dictionary of Nodes and edges.
Inheritance
Implements
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public class GraphWeightedMap<T, TWeight, TEquate, THash> : object, IGraphWeighted<T, TWeight>, IGraph<T>, IDataStructure<T>, ISteppable<T>, System.Collections.Generic.IEnumerable<T>, DataStructure.IAddable<T>, DataStructure.IRemovable<T>, DataStructure.IClearable, ICloneable<GraphWeightedMap<T, TWeight, TEquate, THash>>, DataStructure.IEquating<T, TEquate>, DataStructure.IHashing<T, THash> where TEquate : struct, IFunc<T, T, bool> where THash : struct, IFunc<T, int>
Type Parameters
Name | Description |
---|---|
T | The generic node type of this graph. |
TWeight | The generic weight type of this graph. |
TEquate | The type of function for quality checking |
THash | The type of function for hashing |
Constructors
| Improve this Doc View SourceGraphWeightedMap(TEquate, THash)
Constructs a new graph.
Declaration
public GraphWeightedMap(TEquate equate = default(TEquate), THash hash = default(THash))
Parameters
Type | Name | Description |
---|---|---|
TEquate | equate | The function for equality checking |
THash | hash | The function for hashing |
Properties
| Improve this Doc View SourceEdgeCount
The number of edges in the graph.
Declaration
public int EdgeCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Equate
Gets the value of the type that is checking T
values for equality.
Declaration
public TEquate Equate { get; }
Property Value
Type | Description |
---|---|
TEquate |
Hash
Gets the value of the type that is hashing T
values.
Declaration
public THash Hash { get; }
Property Value
Type | Description |
---|---|
THash |
NodeCount
The number of nodes in the graph.
Declaration
public int NodeCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAdjacent(T, T)
Checks if an edge exists from a
to b
.
Declaration
public bool Adjacent(T a, T b)
Parameters
Type | Name | Description |
---|---|---|
T | a | The start of the edge. |
T | b | The end of the edge. |
Returns
Type | Description |
---|---|
System.Boolean | True if an edge exists from |
Adjacent(T, T, out TWeight)
Checks if b is adjacent to a.
Declaration
public bool Adjacent(T a, T b, out TWeight weight)
Parameters
Type | Name | Description |
---|---|---|
T | a | The starting point of the edge to check. |
T | b | The ending point of the edge to check. |
TWeight | weight | The weight of the edge, if it exists. |
Returns
Type | Description |
---|---|
System.Boolean | True if b is adjacent to a; False if not |
Clear()
Returns the data structure to an empty state.
Declaration
public void Clear()
Clone()
Clones a T
.
Declaration
public GraphWeightedMap<T, TWeight, TEquate, THash> Clone()
Returns
Type | Description |
---|---|
GraphWeightedMap<T, TWeight, TEquate, THash> | A clone of the |
EdgesAndWeightsToArray()
Enumerates and returns all edges present in the graph
Declaration
public (T, T, TWeight)[] EdgesAndWeightsToArray()
Returns
Type | Description |
---|---|
System.ValueTuple<T, T, TWeight>[] | Array of Tuple of nodes and weight that represent an edge |
EdgesBreak<TStep>(TStep)
Invokes a function on every edge in the graph.
Declaration
public StepStatus EdgesBreak<TStep>(TStep step = default(TStep))
where TStep : struct, IFunc<(T, T), StepStatus>
Parameters
Type | Name | Description |
---|---|---|
TStep | step | The function to perform on every edge in the graph. |
Returns
Type | Description |
---|---|
StepStatus | The status of the traversal. |
Type Parameters
Name | Description |
---|---|
TStep | The type of the step function. |
EdgesToArray()
Enumerates and returns all edges present in the graph
Declaration
public (T, T)[] EdgesToArray()
Returns
Type | Description |
---|---|
System.ValueTuple<T, T>[] | Array of Tuple of nodes that represent an edge |
GetEnumerator()
Declaration
public System.Collections.Generic.IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> |
GetNeighbours(T)
Gets enumerator of all neighbours of a node
Declaration
public System.Collections.Generic.IEnumerable<T> GetNeighbours(T node)
Parameters
Type | Name | Description |
---|---|---|
T | node | The node to get neighbours of |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | IEnumerable of all neighbours of the given node |
GetWeight(T, T)
Gets the weight of an edge.
Declaration
public TWeight GetWeight(T a, T b)
Parameters
Type | Name | Description |
---|---|---|
T | a | The starting node of the edge. |
T | b | The ending node of the edge. |
Returns
Type | Description |
---|---|
TWeight | The weight of the edge. |
Neighbors(T, Action<T>)
Gets all the nodes adjacent to a and performs the provided delegate on each.
Declaration
public void Neighbors(T a, Action<T> function)
Parameters
Type | Name | Description |
---|---|---|
T | a | The node to find all the adjacent node to. |
Action<T> | function | The delegate to perform on each adjacent node to a. |
StepperBreak<TStep>(TStep)
Traverses values and invokes a function on every T
value.
Declaration
public StepStatus StepperBreak<TStep>(TStep step = default(TStep))
where TStep : struct, IFunc<T, StepStatus>
Parameters
Type | Name | Description |
---|---|---|
TStep | step | The function to invoke on every |
Returns
Type | Description |
---|---|
StepStatus | The status of the traversal. |
Type Parameters
Name | Description |
---|---|
TStep | The type of function to invoke on every |
ToArray()
Constructs an array with the values of this data structure.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] | An array with the values of this data structure. |
TryAdd(T)
Tries to add a value to a data structure.
Declaration
public (bool Success, Exception? Exception) TryAdd(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to add to the data structure. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> | True if the value was added or false if not. |
TryAdd(T, T, TWeight)
Adds a weighted edge to the graph
Declaration
public (bool Success, Exception? Exception) TryAdd(T start, T end, TWeight weight)
Parameters
Type | Name | Description |
---|---|---|
T | start | The starting point of the edge to add |
T | end | The ending point of the edge to add |
TWeight | weight | The weight of the edge |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> | (
|
TryRemove(T)
Tries to remove a value.
Declaration
public (bool Success, Exception? Exception) TryRemove(T node)
Parameters
Type | Name | Description |
---|---|---|
T | node |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> | True if the value was removed or false if not. |
TryRemove(T, T)
Removes an edge from the graph.
Declaration
public (bool Success, Exception? Exception) TryRemove(T start, T end)
Parameters
Type | Name | Description |
---|---|---|
T | start | The starting point of the edge to remove. |
T | end | The ending point of the edge to remove. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> |
|