-
Notifications
You must be signed in to change notification settings - Fork 30
/
HistogramIterationValue.cs
108 lines (96 loc) · 5.06 KB
/
HistogramIterationValue.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* This is a .NET port of the original Java version, which was written by
* Gil Tene as described in
* https://github.com/HdrHistogram/HdrHistogram
* and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
using System;
namespace HdrHistogram.Iteration
{
/// <summary>
/// Represents a value point iterated through in a Histogram, with associated stats.
/// </summary>
public sealed class HistogramIterationValue
{
/// <summary>
/// The actual value level that was iterated to by the iterator
/// </summary>
public long ValueIteratedTo { get; private set; }
/// <summary>
/// The actual value level that was iterated from by the iterator
/// </summary>
public long ValueIteratedFrom { get; private set; }
/// <summary>
/// The count of recorded values in the histogram that exactly match this [lowestEquivalentValue(valueIteratedTo)...highestEquivalentValue(valueIteratedTo)] value range.
/// </summary>
public long CountAtValueIteratedTo { get; private set; }
/// <summary>
/// The count of recorded values in the histogram that were added to the totalCountToThisValue(below) as a result on this iteration step. Since multiple iteration steps may occur with overlapping equivalent value ranges, the count may be lower than the count found at the value (e.g.multiple linear steps or percentile levels can occur within a single equivalent value range)
/// </summary>
public long CountAddedInThisIterationStep { get; private set; }
/// <summary>
/// The total count of all recorded values in the histogram at values equal or smaller than valueIteratedTo.
/// </summary>
public long TotalCountToThisValue { get; private set; }
/// <summary>
/// The sum of all recorded values in the histogram at values equal or smaller than valueIteratedTo.
/// </summary>
public long TotalValueToThisValue { get; private set; }
/// <summary>
/// The percentile of recorded values in the histogram at values equal or smaller than valueIteratedTo.
/// </summary>
public double Percentile { get; private set; }
/// <summary>
/// The percentile level that the iterator returning this HistogramIterationValue had iterated to.
/// Generally, percentileLevelIteratedTo will be equal to or smaller than percentile, but the same value point can contain multiple iteration levels for some iterators.
/// e.g. a PercentileEnumerator can stop multiple times in the exact same value point (if the count at that value covers a range of multiple percentiles in the requested percentile iteration points).
/// </summary>
public double PercentileLevelIteratedTo { get; private set; }
/// <summary>
/// Indicates if this item is to be considered the last value in the set.
/// </summary>
/// <returns>Returns <c>true</c> if it is the last value, else <c>false</c>.</returns>
public bool IsLastValue()
{
//return PercentileLevelIteratedTo == 100.0D;
return Math.Abs(PercentileLevelIteratedTo - 100.0D) < 0.0001;
}
// Set is all-or-nothing to avoid the potential for accidental omission of some values...
internal void Set(long valueIteratedTo,
long valueIteratedFrom,
long countAtValueIteratedTo,
long countInThisIterationStep,
long totalCountToThisValue,
long totalValueToThisValue,
double percentile,
double percentileLevelIteratedTo)
{
ValueIteratedTo = valueIteratedTo;
ValueIteratedFrom = valueIteratedFrom;
CountAtValueIteratedTo = countAtValueIteratedTo;
CountAddedInThisIterationStep = countInThisIterationStep;
TotalCountToThisValue = totalCountToThisValue;
TotalValueToThisValue = totalValueToThisValue;
Percentile = percentile;
PercentileLevelIteratedTo = percentileLevelIteratedTo;
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>
/// A string that represents the current object.
/// </returns>
public override string ToString()
{
return "ValueIteratedTo:" + ValueIteratedTo +
", ValueIteratedFrom:" + ValueIteratedFrom +
", CountAtValueIteratedTo:" + CountAtValueIteratedTo +
", CountAddedInThisIterationStep:" + CountAddedInThisIterationStep +
", TotalCountToThisValue:" + TotalCountToThisValue +
", TotalValueToThisValue:" + TotalValueToThisValue +
", Percentile:" + Percentile +
", PercentileLevelIteratedTo:" + PercentileLevelIteratedTo;
}
}
}