Simple histogram generation of integer data in C#

后端 未结 4 1511
花落未央
花落未央 2020-12-31 19:44

As part of a test bench I\'m building, I\'m looking for a simple class to calculate a histogram of integer values (number of iterations taken for an algorithm to solve a pro

4条回答
  •  梦毁少年i
    2020-12-31 20:01

    My implementation of a simple extension method to create a histogram:

    public static IReadOnlyDictionary ToHistogram(this IEnumerable enumerable)
       => enumerable.GroupBy(item => item).ToDictionary(grouping => grouping.Key, grouping => grouping.Count());
    

提交回复
热议问题