8 * tally_new - allocate the tally structure.
9 * @buckets: the number of frequency buckets.
11 * This allocates a tally structure using malloc(). The greater the value
12 * of @buckets, the more accurate tally_approx_median() and tally_approx_mode()
13 * and tally_histogram() will be, but more memory is consumed. If you want
14 * to use tally_histogram(), the optimal bucket value is the same as that
17 struct tally *tally_new(unsigned int buckets);
20 * tally_add - add a value.
21 * @tally: the tally structure.
22 * @val: the value to add.
24 void tally_add(struct tally *tally, ssize_t val);
27 * tally_num - how many times as tally_add been called?
28 * @tally: the tally structure.
30 size_t tally_num(const struct tally *tally);
33 * tally_min - the minimum value passed to tally_add.
34 * @tally: the tally structure.
36 * Undefined if tally_num() == 0.
38 ssize_t tally_min(const struct tally *tally);
41 * tally_max - the maximum value passed to tally_add.
42 * @tally: the tally structure.
44 * Undefined if tally_num() == 0.
46 ssize_t tally_max(const struct tally *tally);
49 * tally_mean - the mean value passed to tally_add.
50 * @tally: the tally structure.
52 * Undefined if tally_num() == 0, but will not crash.
54 ssize_t tally_mean(const struct tally *tally);
57 * tally_total - the total value passed to tally_add.
58 * @tally: the tally structure.
59 * @overflow: the overflow value (or NULL).
61 * If your total can't overflow a ssize_t, you don't need @overflow.
62 * Otherwise, @overflow is the upper ssize_t, and the return value should
63 * be treated as the lower size_t (ie. the sign bit is in @overflow).
65 ssize_t tally_total(const struct tally *tally, ssize_t *overflow);
68 * tally_approx_median - the approximate median value passed to tally_add.
69 * @tally: the tally structure.
70 * @err: the error in the returned value (ie. real median is +/- @err).
72 * Undefined if tally_num() == 0, but will not crash. Because we
73 * don't reallocate, we don't store all values, so this median cannot be
76 ssize_t tally_approx_median(const struct tally *tally, size_t *err);
79 * tally_approx_mode - the approximate mode value passed to tally_add.
80 * @tally: the tally structure.
81 * @err: the error in the returned value (ie. real mode is +/- @err).
83 * Undefined if tally_num() == 0, but will not crash. Because we
84 * don't reallocate, we don't store all values, so this mode cannot be
85 * exact. It could well be a value which was never passed to tally_add!
87 ssize_t tally_approx_mode(const struct tally *tally, size_t *err);
89 #define TALLY_MIN_HISTO_WIDTH 8
90 #define TALLY_MIN_HISTO_HEIGHT 3
93 * tally_graph - return an ASCII image of the tally_add distribution
94 * @tally: the tally structure.
95 * @width: the maximum string width to use (>= TALLY_MIN_HISTO_WIDTH)
96 * @height: the maximum string height to use (>= TALLY_MIN_HISTO_HEIGHT)
98 * Returns a malloc()ed string which draws a multi-line graph of the
99 * distribution of values. On out of memory returns NULL.
101 char *tally_histogram(const struct tally *tally,
102 unsigned width, unsigned height);
103 #endif /* CCAN_TALLY_H */