Show / Hide Table of Contents

Class GraphWeightedMap<T, TWeight, TEquate, THash>

Implements a weighted graph. Implements a Dictionary of Nodes and edges.

Inheritance
System.Object
GraphWeightedMap<T, TWeight, TEquate, THash>
Implements
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>
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 T values.

THash

The type of function for hashing T values.

Constructors

| Improve this Doc View Source

GraphWeightedMap(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 T values.

THash hash

The function for hashing T values.

Properties

| Improve this Doc View Source

EdgeCount

The number of edges in the graph.

Declaration
public int EdgeCount { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Equate

Gets the value of the type that is checking T values for equality.

Declaration
public TEquate Equate { get; }
Property Value
Type Description
TEquate
| Improve this Doc View Source

Hash

Gets the value of the type that is hashing T values.

Declaration
public THash Hash { get; }
Property Value
Type Description
THash
| Improve this Doc View Source

NodeCount

The number of nodes in the graph.

Declaration
public int NodeCount { get; }
Property Value
Type Description
System.Int32

Methods

| Improve this Doc View Source

Adjacent(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 a to b; False if not

| Improve this Doc View Source

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

| Improve this Doc View Source

Clear()

Returns the data structure to an empty state.

Declaration
public void Clear()
| Improve this Doc View Source

Clone()

Clones a T.

Declaration
public GraphWeightedMap<T, TWeight, TEquate, THash> Clone()
Returns
Type Description
GraphWeightedMap<T, TWeight, TEquate, THash>

A clone of the T.

| Improve this Doc View Source

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

GetEnumerator()

Declaration
public System.Collections.Generic.IEnumerator<T> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<T>
| Improve this Doc View Source

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 T value.

Returns
Type Description
StepStatus

The status of the traversal.

Type Parameters
Name Description
TStep

The type of function to invoke on every T value.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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>>

( Success, ? Exception)

  • Success: true if the value was added or false
  • ? Exception: the exception that occured if the add was not successful
| Improve this Doc View Source

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.

| Improve this Doc View Source

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>>
  • Success: true if the edge was removed or false if not
  • ? Exception: the exception that occured if the remove failed

Implements

IGraphWeighted<T, TWeight>
IGraph<T>
IDataStructure<T>
ISteppable<T>
System.Collections.Generic.IEnumerable<>
DataStructure.IAddable<T>
DataStructure.IRemovable<T>
DataStructure.IClearable
ICloneable<T>
DataStructure.IEquating<T, TEquate>
DataStructure.IHashing<T, THash>
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX