Class BagMap<T, TMap>
An unsorted structure of unique items.
Inheritance
Implements
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public class BagMap<T, TMap> : object, IBag<T>, IDataStructure<T>, ISteppable<T>, System.Collections.Generic.IEnumerable<T>, DataStructure.ICountable, DataStructure.IClearable, DataStructure.IAuditable<T>, DataStructure.IRemovable<T>, DataStructure.IAddable<T>, ICloneable<BagMap<T, TMap>> where TMap : IMap<int, T>, ICloneable<TMap>
Type Parameters
Name | Description |
---|---|
T | The generic type of the structure. |
TMap | The type of function for quality checking |
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 |
Item[T]
Allows indexed look-up of the structure. (Set does not replace the Add() method)
Declaration
public int this[T countedValue] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
T | countedValue | The "index" to access of the structure. |
Property Value
Type | Description |
---|---|
System.Int32 | The value at the index of the requested key. |
Methods
| Improve this Doc View SourceClear()
Returns the data structure to an empty state.
Declaration
public void Clear()
Clone()
Clones a T
.
Declaration
public BagMap<T, TMap> Clone()
Returns
Type | Description |
---|---|
BagMap<T, TMap> | A clone of the |
Contains(T)
Checks if the data structure contains a value.
Declaration
public bool Contains(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to look for in the data structure. |
Returns
Type | Description |
---|---|
System.Boolean | True if the value exists in the data structure. False if not. |
CountsBreak<TStep>(TStep)
Performs a function on every pair in a bag.
Declaration
public StepStatus CountsBreak<TStep>(TStep step = default(TStep))
where TStep : struct, IFunc<(int Count, T Value), StepStatus>
Parameters
Type | Name | Description |
---|---|---|
TStep | step | The step function to perform on every pair. |
Returns
Type | Description |
---|---|
StepStatus | The status of traversal. |
Type Parameters
Name | Description |
---|---|
TStep | The type of the step function. |
CountsToArray()
Gets an array with all the pairs in the bag.
Declaration
public (int Count, T Value)[] CountsToArray()
Returns
Type | Description |
---|---|
System.ValueTuple<System.Int32, T>[] | An array with all the pairs in the bag. |
GetCounts()
Gets an enumerator that will traverse the pairs of the bag.
Declaration
public System.Collections.Generic.IEnumerable<(int Count, T Value)> GetCounts()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.ValueTuple<System.Int32, T>> | An enumerator that will traverse the pairs of the bag. |
GetEnumerator()
Declaration
public System.Collections.Generic.IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> |
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, Int32)
Tries to add a value to the bag.
Declaration
public (bool Success, Exception? Exception) TryAdd(T value, int count)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be added. |
System.Int32 | count | The number of values to be added. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>> |
|
TryGet(T)
Tries to get the count of a value.
Declaration
public (bool Success, Exception? Exception, int? Count) TryGet(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to get the count of. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Int32>> |
|
TryRemove(T)
Tries to remove a value from the bag.
Declaration
public (bool Success, Exception? Exception, int? OldCount, int? NewCount) TryRemove(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to remove from the bag. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Int32>, System.Nullable<System.Int32>> |
|
TryRemove(T, Int32)
Tries to remove a value from the bag.
Declaration
public (bool Success, Exception? Exception, int? OldCount, int? NewCount) TryRemove(T value, int count)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be removed. |
System.Int32 | count | The number of values to be removed. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Int32>, System.Nullable<System.Int32>> |
|
TrySet(T, Int32)
Sets value in the bag.
Declaration
public (bool Success, Exception? Exception, bool? Existed, int? OldCount) TrySet(T value, int count)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be set. |
System.Int32 | count | The number of values to set. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Boolean>, System.Nullable<System.Int32>> |
|