Class DataStructures
- Namespace
- AlgorithmsSW
- Assembly
- AlgorithmsSW.dll
Sensible default implementations of data structures.
public static class DataStructures
- Inheritance
-
DataStructures
- Inherited Members
Remarks
This is useful when you need a container with a certain interface but you do not want to make decisions about what implementation to use.
Methods
Array<T>(int)
Creates a new array of a specified type and size.
public static T[] Array<T>(int count)
Parameters
countintThe number of elements in the array.
Returns
- T[]
A new array of the specified type and size.
Type Parameters
TThe type of the elements in the array.
Array<T>(int, T)
Creates a new array of a specified type and size, and fills it with a specified initial element.
public static T[] Array<T>(int count, T initialElement)
Parameters
countintThe number of elements in the array.
initialElementTThe initial element to fill the array with. Be careful when the supplied value is a reference type; the same reference will be added to every cell.
var grid = DataStructures.Array<int[]>(10, DataStructures.Array<int>(20)); grid[0][0] = 1; Console.WriteLine($"Value at grid[0][1] is {grid[0][1]}"); // Prints 1, not 0, since the same array is in each cell.
Returns
- T[]
A new array of the specified type and size.
Type Parameters
TThe type of the elements in the array.
Digraph(int)
public static IDigraph Digraph(int vertexCount)
Parameters
vertexCountint
Returns
EdgeWeightedDigraph<T>(int)
public static IEdgeWeightedDigraph<T> EdgeWeightedDigraph<T>(int vertexCount)
Parameters
vertexCountint
Returns
Type Parameters
T
EdgeWeightedGraph<T>(int)
public static IEdgeWeightedGraph<T> EdgeWeightedGraph<T>(int vertexCount)
Parameters
vertexCountint
Returns
Type Parameters
T
FixedSizeList<T>(int)
Creates a new IRandomAccessList<T> list with the specified count filed with default.
public static IRandomAccessList<T> FixedSizeList<T>(int count)
Parameters
countintThe initial count of the list.
Returns
- IRandomAccessList<T>
A new instance of the IRandomAccessList<T> interface.
Type Parameters
TThe type of elements in the list.
FixedSizeList<T>(int, T)
Creates a new IRandomAccessList<T> list with the specified count and initial element.
public static IRandomAccessList<T> FixedSizeList<T>(int count, T initialElement)
Parameters
countintThe initial count of the list.
initialElementTThe initial element to fill the list with. Be careful when the supplied value is a reference type; the same reference will be added to every cell.
var grid = DataStructures.List<int[]>(10, DataStructures.List<int>(20)); grid[0][0] = 1; Console.WriteLine($"Value at grid[0][1] is {grid[0][1]}"); // Prints 1, not 0, since the same array is in each cell.
Returns
- IRandomAccessList<T>
A new instance of the IRandomAccessList<T> interface.
Type Parameters
TThe type of elements in the list.
Graph(int)
public static IGraph Graph(int vertexCount)
Parameters
vertexCountint
Returns
HashTable<TKey, TValue>(IComparer<TKey>)
public static ISymbolTable<TKey, TValue> HashTable<TKey, TValue>(IComparer<TKey> comparer)
Parameters
comparerIComparer<TKey>
Returns
- ISymbolTable<TKey, TValue>
Type Parameters
TKeyTValue
HashTable<TKey, TValue>(int, IComparer<TKey>)
public static ISymbolTable<TKey, TValue> HashTable<TKey, TValue>(int capacity, IComparer<TKey> comparer)
Parameters
Returns
- ISymbolTable<TKey, TValue>
Type Parameters
TKeyTValue
IndexedPriorityQueue<T>(int, IComparer<T>)
public static IndexPriorityQueue<T> IndexedPriorityQueue<T>(int capacity, IComparer<T> comparer)
Parameters
Returns
Type Parameters
T
ParseEdges(string)
public static (int source, int target)[] ParseEdges(this string edgeString)
Parameters
edgeStringstring
Returns
ParseEdges<T>(string, IFormatProvider?)
public static (int source, int target, T weight)[] ParseEdges<T>(this string edgeString, IFormatProvider? provider = null) where T : IParsable<T>
Parameters
edgeStringstringproviderIFormatProvider
Returns
Type Parameters
T
PriorityQueue<T>(IComparer<T>)
public static IPriorityQueue<T> PriorityQueue<T>(IComparer<T> comparer)
Parameters
comparerIComparer<T>
Returns
Type Parameters
T
PriorityQueue<T>(int, IComparer<T>)
public static IPriorityQueue<T> PriorityQueue<T>(int capacity, IComparer<T> comparer)
Parameters
Returns
Type Parameters
T
Queue<T>()
public static IQueue<T> Queue<T>()
Returns
- IQueue<T>
Type Parameters
T
Queue<T>(int)
public static IQueue<T> Queue<T>(int capacity)
Parameters
capacityint
Returns
- IQueue<T>
Type Parameters
T
ResizeableList<T>()
public static IRandomAccessList<T> ResizeableList<T>()
Returns
Type Parameters
T
ResizeableList<T>(int)
Creates a new IRandomAccessList<T> list with the specified capacity.
public static IRandomAccessList<T> ResizeableList<T>(int capacity)
Parameters
capacityint
Returns
- IRandomAccessList<T>
A new instance of an empty random access list.
Type Parameters
TThe type of elements in the list.
Set<T>(IComparer<T>)
public static ISet<T> Set<T>(IComparer<T> comparer)
Parameters
comparerIComparer<T>
Returns
- ISet<T>
Type Parameters
T
Stack<T>()
Creates a new IStack<T>.
public static IStack<T> Stack<T>()
Returns
- IStack<T>
Type Parameters
TThe type of elements in the stack.
Stack<T>(int)
Creates a new IStack<T> with the given capacity.
public static IStack<T> Stack<T>(int capacity)
Parameters
capacityint
Returns
- IStack<T>
Type Parameters
TThe type of elements in the stack.
ToDigraph(IEnumerable<(int source, int target)>)
public static IDigraph ToDigraph(this IEnumerable<(int source, int target)> edges)
Parameters
edgesIEnumerable<(int source, int target)>
Returns
ToDigraph(string)
public static IDigraph ToDigraph(this string edges)
Parameters
edgesstring
Returns
ToDigraph<T>(IEnumerable<(int source, int target, T weight)>)
public static IEdgeWeightedDigraph<T> ToDigraph<T>(this IEnumerable<(int source, int target, T weight)> edges)
Parameters
Returns
Type Parameters
T
ToDigraph<T>(string)
public static IEdgeWeightedDigraph<T> ToDigraph<T>(this string edges) where T : IParsable<T>
Parameters
edgesstring
Returns
Type Parameters
T
ToGraph(IEnumerable<(int source, int target)>)
public static IGraph ToGraph(this IEnumerable<(int source, int target)> edges)
Parameters
edgesIEnumerable<(int source, int target)>
Returns
ToGraph(string)
public static IGraph ToGraph(this string edges)
Parameters
edgesstring
Returns
ToGraph<T>(IEnumerable<(int source, int target, T weight)>)
public static IEdgeWeightedGraph<T> ToGraph<T>(this IEnumerable<(int source, int target, T weight)> edges)
Parameters
Returns
Type Parameters
T
ToGraph<T>(string)
public static IEdgeWeightedGraph<T> ToGraph<T>(this string edges) where T : IParsable<T>
Parameters
edgesstring
Returns
Type Parameters
T