-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Labels
Description
File: HistogramExtensions.cs
public static long GetMaxValue(this HistogramBase histogram)
{
var max = histogram.RecordedValues().Select(hiv => hiv.ValueIteratedTo).LastOrDefault();
return histogram.HighestEquivalentValue(max);
}
This iterates the entire histogram via a full RecordedValues() enumeration just to get the last value. The HistogramBase already tracks _maxValue internally; expose it:
public static long GetMaxValue(this HistogramBase histogram)
{
// Walk backward from CountsArrayLength to find last non-zero index
for (int i = histogram.CountsArrayLength - 1; i >= 0; i--)
{
if (histogram.GetCountAtIndex(i) > 0)
return histogram.HighestEquivalentValue(histogram.ValueFromIndex(i));
}
return 0;
}
Or better: the _maxValue field should be surfaced as a public/internal property (it's already maintained incrementally by UpdatedMaxValue) and returned directly. This turns an O(N) full-scan into O(1).
Reactions are currently unavailable