diff mbox

[i-g-t,02/16] stats: Add an igt_stats_init_from_array() variant

Message ID 1436186144-19665-3-git-send-email-damien.lespiau@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lespiau, Damien July 6, 2015, 12:35 p.m. UTC
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 lib/igt_stats.c | 22 ++++++++++++++++++++++
 lib/igt_stats.h |  2 ++
 2 files changed, 24 insertions(+)
diff mbox

Patch

diff --git a/lib/igt_stats.c b/lib/igt_stats.c
index 37fcc23..1103a7b 100644
--- a/lib/igt_stats.c
+++ b/lib/igt_stats.c
@@ -133,6 +133,28 @@  void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity)
 	stats->max = 0;
 }
 
+/**
+ * igt_stats_init_from_array:
+ * @stats: An #igt_stats_t instance
+ * @array: (array length=n): Array of uint64_t
+ * @n: Length of @array
+ *
+ * Short hand for:
+ * |[
+ *	static const uint64_t s[] = { 10, 12, 14, 16, 87, 53, 90, 72 };
+ *	igt_stats_t stats;
+ *
+ *	igt_stats_init(&stats);
+ *	igt_stats_push_array(&stats, s, ARRAY_SIZE(s));
+ * ]|
+ */
+void igt_stats_init_from_array(igt_stats_t *stats,
+			       const uint64_t *array, unsigned int n)
+{
+	igt_stats_init(stats);
+	igt_stats_push_array(stats, array, n);
+}
+
 /* https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform */
 static double rand_normal(double mean, double stddev)
 {
diff --git a/lib/igt_stats.h b/lib/igt_stats.h
index e1757b7..d6eb48f 100644
--- a/lib/igt_stats.h
+++ b/lib/igt_stats.h
@@ -49,6 +49,8 @@  typedef struct {
 
 void igt_stats_init(igt_stats_t *stats);
 void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity);
+void igt_stats_init_from_array(igt_stats_t *stats,
+			       const uint64_t *array, unsigned int n);
 void igt_stats_init_normal(igt_stats_t *stats,
 			   double mean, double std_deviation,
 			   unsigned int n_values);