[RFC,v2,1/3] ipa: libipa: histogram: Add `empty()`
diff mbox series

Message ID 20261106125807.1238919-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [RFC,v2,1/3] ipa: libipa: histogram: Add `empty()`
Related show

Commit Message

Barnabás Pőcze Nov. 6, 2026, 12:58 p.m. UTC
Empty histograms are usually of little use, so add a function that checks
if the histogram contains any data points.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/libipa/histogram.cpp | 10 ++++++++++
 src/ipa/libipa/histogram.h   |  1 +
 2 files changed, 11 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp
index 9e46a05a90..c516ace7da 100644
--- a/src/ipa/libipa/histogram.cpp
+++ b/src/ipa/libipa/histogram.cpp
@@ -74,6 +74,16 @@  Histogram::Histogram(std::span<const uint32_t> data)
  * \return Number of values
  */
 
+/**
+ * \fn Histogram::empty()
+ * \brief Determine if the histogram is empty
+ *
+ * An empty histogram is one which has only empty bins,
+ * that is, bins with a count of 0.
+ *
+ * \return True if the histogram is empty
+ */
+
 /**
  * \fn Histogram::operator[](size_t bin) const
  * \brief Retrieve the value for \a bin
diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h
index b50868ab4d..cbc34e8c70 100644
--- a/src/ipa/libipa/histogram.h
+++ b/src/ipa/libipa/histogram.h
@@ -41,6 +41,7 @@  public:
 	uint64_t cumulativeFrequency(double bin) const;
 	double quantile(double q, uint32_t first = 0, uint32_t last = UINT_MAX) const;
 	double interQuantileMean(double lowQuantile, double hiQuantile) const;
+	bool empty() const { return total() == 0; }
 
 	uint32_t operator[](size_t bin) const
 	{