Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

HistogramBase.GetValueAtPercentile — Double-Loop When Flat Array Index Is Available

Open
#145 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp
Domain
performance

Research direction

Start in HistogramBase.cs at GetValueAtPercentile and inspect how LongHistogram stores its counts, including CountsArrayLength, GetCountAtIndex, and ValueFromIndex. Compare the existing nested scan with the proposed flat traversal; done means percentile lookup preserves the current result while avoiding the nested index mapping.

Written by the indexing model from the issue text.

Description

agent enhancement

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.

Dominant language
C#
Stars
185
Forks
31
PR merge metrics
No merged PRs in 30d

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HdrHistogram/HdrHistogram.NET

All issues in HdrHistogram/HdrHistogram.NET

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.