]> git.ozlabs.org Git - ccan/blobdiff - ccan/tally/tally.h
tally: Adapt bucket_min to Samba coding conventions
[ccan] / ccan / tally / tally.h
index 1f4b5d5f7576f89673a59ec78a45606ad9220691..c9272f1000fa516cb5c321249ee711088301a2c2 100644 (file)
@@ -1,6 +1,8 @@
+/* Licensed under LGPLv3+ - see LICENSE file for details */
 #ifndef CCAN_TALLY_H
 #define CCAN_TALLY_H
-#include <stdlib.h>
+#include "config.h"
+#include <sys/types.h>
 
 struct tally;
 
@@ -10,9 +12,11 @@ struct tally;
  *
  * This allocates a tally structure using malloc().  The greater the value
  * of @buckets, the more accurate tally_approx_median() and tally_approx_mode()
- * and tally_graph() will be, but more memory is consumed.
+ * and tally_histogram() will be, but more memory is consumed.  If you want
+ * to use tally_histogram(), the optimal bucket value is the same as that
+ * @height argument.
  */
-struct tally *tally_new(size_t buckets);
+struct tally *tally_new(unsigned int buckets);
 
 /**
  * tally_add - add a value.
@@ -51,6 +55,17 @@ ssize_t tally_max(const struct tally *tally);
  */
 ssize_t tally_mean(const struct tally *tally);
 
+/**
+ * tally_total - the total value passed to tally_add.
+ * @tally: the tally structure.
+ * @overflow: the overflow value (or NULL).
+ *
+ * If your total can't overflow a ssize_t, you don't need @overflow.
+ * Otherwise, @overflow is the upper ssize_t, and the return value should
+ * be treated as the lower size_t (ie. the sign bit is in @overflow).
+ */
+ssize_t tally_total(const struct tally *tally, ssize_t *overflow);
+
 /**
  * tally_approx_median - the approximate median value passed to tally_add.
  * @tally: the tally structure.