-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Labels
Description
File: HistogramBase.cs
The percentile lookup iterates nested i / j loops over BucketCount × SubBucketCount. Since CountsArrayIndex(bucketIndex, subBucketIndex) maps this to a flat array, and the counts array is already flat in LongHistogram, the entire scan can be done as a single flat loop:
public long GetValueAtPercentile(double percentile) { var countAtPercentile = Math.Max( (long)((Math.Min(percentile, 100.0) / 100.0 * TotalCount) + 0.5), 1);long runningCount = 0; for (int i = 0; i < CountsArrayLength; i++) { runningCount += GetCountAtIndex(i); if (runningCount >= countAtPercentile) return HighestEquivalentValue(ValueFromIndex(i)); } throw new ArgumentOutOfRangeException(...);
}
The nested loop computes GetCountAt(i, j) → GetCountAtIndex(CountsArrayIndex(i, j)) anyway — the flat version eliminates the CountsArrayIndex call per iteration and improves cache locality by accessing memory sequentially.
Reactions are currently unavailable