/ Tools / TranscriptAnalysis / OccuranceMap.cs
OccuranceMap.cs
 1  namespace TranscriptAnalysis
 2  {
 3      public class OccuranceMap
 4      {
 5          private readonly Dictionary<int, int> map = new Dictionary<int, int>();
 6  
 7          public void Add(int point)
 8          {
 9              if (map.ContainsKey(point))
10              {
11                  map[point]++;
12              }
13              else
14              {
15                  map.Add(point, 1);
16              }
17          }
18  
19          public void Print(Action<int, int> action)
20          {
21              Print(false, action);
22          }
23  
24          public void PrintContinous(Action<int, int> action)
25          {
26              Print(true, action);
27          }
28  
29          private void Print(bool continuous, Action<int, int> action)
30          {
31              var min = map.Keys.Min();
32              var max = map.Keys.Max();
33  
34              for (var i = min; i <= max; i++)
35              {
36                  if (map.ContainsKey(i))
37                  {
38                      action(i, map[i]);
39                  }
40                  else if (continuous)
41                  {
42                      action(i, 0);
43                  }
44              }
45          }
46      }
47  }