Interface IOccurrencesCounter
An object able to count the number of occurrences of each item of a
Namespace: MoreStructures.Lists.Counting
Assembly: MoreStructures.dll
Syntax
public interface IOccurrencesCounter
Methods
| Improve this Doc View SourceCount<T>(IEnumerable<T>)
For each item t of type T
in enumerable
and for each index i of E,
counts the total number of items equal to t in E[0..i] (extremes included).
Declaration
IDictionary<T, IDictionary<int, int>> Count<T>(IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumerable | The enumerable, to count the items of. |
Returns
Type | Description |
---|---|
IDictionary<T, IDictionary<System.Int32, System.Int32>> | A new, lazy evaluated two-levels dictionary of System.Int32, the 1st-level one having as many items as
the number of distinct chars in |
Type Parameters
Name | Description |
---|---|
T | The type of items of |
Examples
var counter = ...
var enumerable = new List<int> { 1, 4, 2, 1, 3, 4, 2, 2 }
var counts = counter.Count(enumerable)
// Result =
// {
// [1, 0] = 1, [2, 0] = 0, [3, 0] = 0, [4, 0] = 0, // Counts by char in E[0..0]
// [1, 1] = 1, [2, 1] = 0, [3, 1] = 0, [4, 1] = 1, // Counts by char in E[0..1]
// [1, 2] = 1, [2, 2] = 1, [3, 2] = 0, [4, 2] = 1, // Counts by char in E[0..2]
// ...
// [1, 7] = 2, [2, 7] = 2, [3, 7] = 1, [4, 7] = 2, // Counts by char in E[0..7]
// }