[v5,34/47] ipa: libipa: histogram: Add `operator[]` to query bin
diff mbox series

Message ID 20260817114349.994123-35-barnabas.pocze@ideasonboard.com
State Superseded
Headers show
Series
  • ipa: libipa: agc rework
Related show

Commit Message

Barnabás Pőcze Aug. 17, 2026, 11:43 a.m. UTC
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>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/histogram.cpp | 6 ++++++
 src/ipa/libipa/histogram.h   | 7 +++++++
 2 files changed, 13 insertions(+)

Comments

Stefan Klug Aug. 20, 2026, 10:56 a.m. UTC | #1
Hi Barnabás,

Quoting Barnabás Pőcze (2026-08-17 13:43:35)
> 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>
> Reviewed-by: Jacopo Mondi <jacopo.mondi@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;
> +       }

I answered your answer in the v4 thread. Do whichever you prefer.

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>

Best regards,
Stefan

> +
>  private:
>         std::vector<uint64_t> cumulative_;
>  };
> -- 
> 2.55.0
>

Patch
diff mbox series

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_;
 };