[RFC,v2,31/43] ipa: libipa: histogram: Add `operator[]` to query bin
diff mbox series

Message ID 20260723154327.1357866-32-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • ipa: libipa: agc rework
Related show

Commit Message

Barnabás Pőcze July 23, 2026, 3:43 p.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>
---
 src/ipa/libipa/histogram.cpp | 6 ++++++
 src/ipa/libipa/histogram.h   | 7 +++++++
 2 files changed, 13 insertions(+)

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