Class TreeMap<T, TEquate, THash>
A generic tree data structure using a dictionary to store node data.
Inheritance
Implements
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public class TreeMap<T, TEquate, THash> : object, ITree<T>, IDataStructure<T>, ISteppable<T>, System.Collections.Generic.IEnumerable<T>, DataStructure.ICountable, DataStructure.IRemovable<T>, ICloneable<TreeMap<T, TEquate, THash>>, DataStructure.IHashing<T, THash>, DataStructure.IEquating<T, TEquate> where TEquate : struct, IFunc<T, T, bool> where THash : struct, IFunc<T, int>
Type Parameters
Name | Description |
---|---|
T | The generic type stored in this data structure. |
TEquate | The type of function for quality checking |
THash | The type of function for hashing |
Constructors
| Improve this Doc View SourceTreeMap(T, TEquate, THash)
Constructs a new tree.
Declaration
public TreeMap(T top, TEquate equate = default(TEquate), THash hash = default(THash))
Parameters
Type | Name | Description |
---|---|---|
T | top | The top of the tree. |
TEquate | equate | The function for quality checking |
THash | hash | The function for hashing |
Properties
| Improve this Doc View SourceCount
Gets the current count of the data structure.
Declaration
public int Count { 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 |
Top
The head of the tree.
Declaration
public T Top { get; }
Property Value
Type | Description |
---|---|
T |
Methods
| Improve this Doc View SourceChildren(T, Action<T>)
Stepper function for the children of a given node.
Declaration
public void Children(T parent, Action<T> step)
Parameters
Type | Name | Description |
---|---|---|
T | parent | The node to step through the children of. |
Action<T> | step | The step function. |
Clone()
Clones a T
.
Declaration
public TreeMap<T, TEquate, THash> Clone()
Returns
Type | Description |
---|---|
TreeMap<T, TEquate, THash> | A clone of the |
GetEnumerator()
Declaration
public System.Collections.Generic.IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> |
IsChildOf(T, T)
Determines if a node is the child of another node.
Declaration
public bool IsChildOf(T node, T parent)
Parameters
Type | Name | Description |
---|---|---|
T | node | The child to check the parent of. |
T | parent | The parent to check the child of. |
Returns
Type | Description |
---|---|
System.Boolean | True if the node is a child of the parent; False if not. |
Parent(T)
Gets the parent of a given node.
Declaration
public T Parent(T child)
Parameters
Type | Name | Description |
---|---|---|
T | child | The child to get the parent of. |
Returns
Type | Description |
---|---|
T | The parent of the given child. |
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, T)
Adds a node to the tree.
Declaration
public (bool Success, Exception? Exception) TryAdd(T node, T parent)
Parameters
Type | Name | Description |
---|---|---|
T | node | |
T | parent | The parent of the node to be added. |
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. |