Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ExponentialHistogramAggregator.cs
Go to the documentation of this file.
2
4
6{
7 private struct Bucket
8 {
9 public double Value;
10
11 public int Count;
12
13 public Bucket(double value, int count)
14 {
15 Value = value;
16 Count = count;
17 }
18 }
19
20 private readonly QuantileAggregation _config;
21
22 private int[][] _counters;
23
24 private int _count;
25
26 private readonly int _mantissaMax;
27
28 private readonly int _mantissaMask;
29
30 private readonly int _mantissaShift;
31
33 {
35 _counters = new int[4096][];
36 if (_config.MaxRelativeError < 0.0001)
37 {
38 throw new ArgumentException();
39 }
40 int num = (int)Math.Ceiling(Math.Log(1.0 / _config.MaxRelativeError, 2.0)) - 1;
41 _mantissaShift = 52 - num;
42 _mantissaMax = 1 << num;
44 }
45
47 {
48 int[][] counters;
49 int count;
50 lock (this)
51 {
53 count = _count;
54 _counters = new int[4096][];
55 _count = 0;
56 }
58 int num = 0;
59 if (num == _config.Quantiles.Length)
60 {
61 return new HistogramStatistics(array);
62 }
65 int num3 = 0;
67 {
68 num3 += item.Count;
69 while (num3 > num2)
70 {
71 array[num] = new QuantileValue(_config.Quantiles[num], item.Value);
72 num++;
73 if (num == _config.Quantiles.Length)
74 {
75 return new HistogramStatistics(array);
76 }
78 }
79 }
80 return new HistogramStatistics(Array.Empty<QuantileValue>());
81 }
82
83 private int GetInvalidCount(int[][] counters)
84 {
85 int[] array = counters[2047];
86 int[] array2 = counters[4095];
87 int num = 0;
88 if (array != null)
89 {
90 int[] array3 = array;
91 foreach (int num2 in array3)
92 {
93 num += num2;
94 }
95 }
96 if (array2 != null)
97 {
98 int[] array4 = array2;
99 foreach (int num3 in array4)
100 {
101 num += num3;
102 }
103 }
104 return num;
105 }
106
108 {
109 for (int exponent2 = 4094; exponent2 >= 2048; exponent2--)
110 {
112 if (mantissaCounts2 != null)
113 {
114 for (int mantissa2 = _mantissaMax - 1; mantissa2 >= 0; mantissa2--)
115 {
116 int num = mantissaCounts2[mantissa2];
117 if (num > 0)
118 {
120 }
121 }
122 }
123 }
124 for (int exponent2 = 0; exponent2 < 2047; exponent2++)
125 {
127 if (mantissaCounts2 == null)
128 {
129 continue;
130 }
131 for (int mantissa2 = 0; mantissa2 < _mantissaMax; mantissa2++)
132 {
134 if (num2 > 0)
135 {
137 }
138 }
139 }
140 }
141
142 public override void Update(double measurement)
143 {
144 lock (this)
145 {
146 ulong num = (ulong)BitConverter.DoubleToInt64Bits(measurement);
147 int num2 = (int)(num >> 52);
148 int num3 = (int)(num >> _mantissaShift) & _mantissaMask;
149 ref int[] reference = ref _counters[num2];
150 if (reference == null)
151 {
152 reference = new int[_mantissaMax];
153 }
154 reference[num3]++;
155 _count++;
156 }
157 }
158
159 private int QuantileToRank(double quantile, int count)
160 {
161 return Math.Min(Math.Max(0, (int)(quantile * (double)count)), count - 1);
162 }
163
165 {
166 long value = ((long)exponent << 52) | ((long)mantissa << _mantissaShift);
168 }
169}
static unsafe double Int64BitsToDouble(long value)
static unsafe long DoubleToInt64Bits(double value)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Ceiling(double a)
static double Log(double d)
static byte Max(byte val1, byte val2)
Definition Math.cs:738