Class Bucketizer<TElement, TValue>
Splits collections into multiple buckets based on value-mapping. Create with Bucketize<TElement, TValue>(IEnumerable<TElement>, Func<TElement, TValue>).
Namespace: NanoByte.Common.Dispatch
Assembly: NanoByte.Common.dll
Syntax
public class Bucketizer<TElement, TValue> : Object
Type Parameters
Name | Description |
---|---|
TElement | The common base type of all objects to be bucketized. |
TValue | The type of the values to be matched. |
Constructors
Bucketizer(IEnumerable<TElement>, Func<TElement, TValue>)
Splits collections into multiple buckets based on value-mapping. Create with Bucketize<TElement, TValue>(IEnumerable<TElement>, Func<TElement, TValue>).
Declaration
public Bucketizer(IEnumerable<TElement> elements, Func<TElement, TValue> valueRetriever)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TElement> | elements | The elements to be bucketized. |
Func<TElement, TValue> | valueRetriever | A function to map elements to their according values used for bucketization. |
Methods
Add(TValue, ICollection<TElement>)
Adds a new bucket rule.
Declaration
public Bucketizer<TElement, TValue> Add(TValue value, ICollection<TElement> bucket)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | A value to compare with the result of the value retriever using Equals(Object, Object). |
ICollection<TElement> | bucket | The collection elements are added to if they match the |
Returns
Type | Description |
---|---|
Bucketizer<TElement, TValue> | The "this" pointer for use in a "Fluent API" style. |
GetEnumerator()
Declaration
public IEnumerator<BucketRule<TElement, TValue>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<BucketRule<TElement, TValue>> |
Run()
Adds each element to the first bucket with a matching value (if any). Set up with Add(TValue, ICollection<TElement>) first.
Declaration
public void Run()