Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

HistogramExtensions.GetMaxValue — LINQ over a Hot Path

Aperta
#146 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
performance

Direzione di ricerca

Start in HistogramExtensions.cs and inspect HistogramBase, especially the existing _maxValue field and UpdatedMaxValue maintenance. Compare the current RecordedValues() behavior with the proposed direct or backward lookup, then verify that GetMaxValue returns the expected highest equivalent value without a full enumeration. Done means the hot path avoids the O(N) scan and existing behavior remains correct.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent enhancement

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).

Lingua principale
C#
Stelle
185
Fork
31
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di HdrHistogram/HdrHistogram.NET

Tutte le issue di HdrHistogram/HdrHistogram.NET

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.