-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathHistogram.cs
More file actions
54 lines (45 loc) · 1.01 KB
/
Histogram.cs
File metadata and controls
54 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
namespace Waher.Utility.ExStat
{
public class Histogram<T>
{
public SortedDictionary<T, Bucket> Buckets = new SortedDictionary<T, Bucket>();
public void Inc(T Key, params string[] SubKeys)
{
if (!this.Buckets.TryGetValue(Key, out Bucket Bucket))
{
Bucket = new Bucket();
this.Buckets[Key] = Bucket;
}
Bucket.Inc(SubKeys);
}
public void Join(T Key, int Count, bool First, params string[] SubKeys)
{
if (!this.Buckets.TryGetValue(Key, out Bucket Bucket))
{
if (!First)
return;
Bucket = new Bucket();
this.Buckets[Key] = Bucket;
}
Bucket.Join(Count, First, SubKeys);
}
public void RemoveUntouched()
{
LinkedList<T> ToRemove = new LinkedList<T>();
foreach (KeyValuePair<T, Bucket> P in Buckets)
{
if (P.Value.Touched)
{
P.Value.Touched = false;
P.Value.RemoveUntouched();
}
else
ToRemove.AddLast(P.Key);
}
foreach (T Key in ToRemove)
Buckets.Remove(Key);
}
}
}