| Message ID | 20260803131435.153927-36-barnabas.pocze@ideasonboard.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
Hi Barnabás On Mon, Aug 03, 2026 at 03:14:20PM +0200, Barnabás Pőcze wrote: > Add an `operator[]` that takes an integral bin number and returns > the count pertaining to that specific bin. > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > --- > src/ipa/libipa/histogram.cpp | 6 ++++++ > src/ipa/libipa/histogram.h | 7 +++++++ > 2 files changed, 13 insertions(+) > > diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp > index bcf2639082..2f91ffb6d7 100644 > --- a/src/ipa/libipa/histogram.cpp > +++ b/src/ipa/libipa/histogram.cpp > @@ -74,6 +74,12 @@ Histogram::Histogram(Span<const uint32_t> data) > * \return Number of values > */ > > +/** > + * \fn Histogram::operator[](size_t bin) const > + * \brief Retrieve the value for \a bin > + * \return The value in \a bin, or 0 if \a bin is out of range > + */ > + > /** > * \brief Cumulative frequency up to a (fractional) point in a bin > * \param[in] bin The bin up to which to cumulate > diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h > index 0c02dda2ba..b3f59b7c31 100644 > --- a/src/ipa/libipa/histogram.h > +++ b/src/ipa/libipa/histogram.h > @@ -42,6 +42,13 @@ public: > double quantile(double q, uint32_t first = 0, uint32_t last = UINT_MAX) const; > double interQuantileMean(double lowQuantile, double hiQuantile) const; > > + uint32_t operator[](size_t bin) const > + { > + return bin < bins() > + ? cumulative_[bin + 1] - cumulative_[bin] > + : 0; Could fit in 1 line. Up to you Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> > + } > + > private: > std::vector<uint64_t> cumulative_; > }; > -- > 2.55.0 >
diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp index bcf2639082..2f91ffb6d7 100644 --- a/src/ipa/libipa/histogram.cpp +++ b/src/ipa/libipa/histogram.cpp @@ -74,6 +74,12 @@ Histogram::Histogram(Span<const uint32_t> data) * \return Number of values */ +/** + * \fn Histogram::operator[](size_t bin) const + * \brief Retrieve the value for \a bin + * \return The value in \a bin, or 0 if \a bin is out of range + */ + /** * \brief Cumulative frequency up to a (fractional) point in a bin * \param[in] bin The bin up to which to cumulate diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h index 0c02dda2ba..b3f59b7c31 100644 --- a/src/ipa/libipa/histogram.h +++ b/src/ipa/libipa/histogram.h @@ -42,6 +42,13 @@ public: double quantile(double q, uint32_t first = 0, uint32_t last = UINT_MAX) const; double interQuantileMean(double lowQuantile, double hiQuantile) const; + uint32_t operator[](size_t bin) const + { + return bin < bins() + ? cumulative_[bin + 1] - cumulative_[bin] + : 0; + } + private: std::vector<uint64_t> cumulative_; };
Add an `operator[]` that takes an integral bin number and returns the count pertaining to that specific bin. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- src/ipa/libipa/histogram.cpp | 6 ++++++ src/ipa/libipa/histogram.h | 7 +++++++ 2 files changed, 13 insertions(+)