Class Bag
Static Extension class for bag interface implementers.
Inheritance
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public static class Bag : object
Methods
| Improve this Doc View SourceCounts<T>(IBag<T>, Action<(Int32 Count, T Value)>)
Performs a function on every pair in a bag.
Declaration
public static void Counts<T>(this IBag<T> bag, Action<(int Count, T Value)> step)
Parameters
Type | Name | Description |
---|---|---|
IBag<T> | bag | The bag to traverse the pairs of. |
Action<System.ValueTuple<System.Int32, T>> | step | The step function to perform on every pair. |
Type Parameters
Name | Description |
---|---|
T | The type of values in the bag. |
Counts<T, TStep>(IBag<T>, TStep)
Performs a function on every pair in a bag.
Declaration
public static void Counts<T, TStep>(this IBag<T> bag, TStep step = default(TStep))
where TStep : struct, IAction<(int Count, T Value)>
Parameters
Type | Name | Description |
---|---|---|
IBag<T> | bag | The bag to traverse the pairs of. |
TStep | step | The step function to perform on every pair. |
Type Parameters
Name | Description |
---|---|
T | The type of values in the bag. |
TStep | The type of step function to perform on every pair. |
CountsBreak<T>(IBag<T>, Func<(Int32 Count, T Value), StepStatus>)
Performs a function on every pair in a bag.
Declaration
public static StepStatus CountsBreak<T>(this IBag<T> bag, Func<(int Count, T Value), StepStatus> step)
Parameters
Type | Name | Description |
---|---|---|
IBag<T> | bag | The bag to traverse the pairs of. |
Func<System.ValueTuple<System.Int32, T>, StepStatus> | step | The step function to perform on every pair. |
Returns
Type | Description |
---|---|
StepStatus | The status of the traversal. |
Type Parameters
Name | Description |
---|---|
T | The type of values in the bag. |
Get<T>(IBag<T>, T)
Gets the count of a value
in a bag
.
Declaration
public static int Get<T>(this IBag<T> bag, T value)
Parameters
Type | Name | Description |
---|---|---|
IBag<T> | bag | The bag to get the count of a |
T | value | The value to get the count of. |
Returns
Type | Description |
---|---|
System.Int32 | The count of the |
Type Parameters
Name | Description |
---|---|
T | The generic type to be stored in this data structure. |
Set<T>(IBag<T>, T, Int32)
Sets the count
of a value
in a bag
.
Declaration
public static (bool Existed, int? OldCount) Set<T>(this IBag<T> bag, T value, int count)
Parameters
Type | Name | Description |
---|---|---|
IBag<T> | bag | The bag to set the value count in. |
T | value | The value to set the |
System.Int32 | count | The count to set the number of |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Boolean, System.Nullable<System.Int32>> |
|
Type Parameters
Name | Description |
---|---|
T | The generic type to be stored in this data structure. |