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_graph() will be, but more memory is consumed.
15 struct tally *tally_new(size_t buckets);
18 * tally_add - add a value.
19 * @tally: the tally structure.
20 * @val: the value to add.
22 void tally_add(struct tally *tally, ssize_t val);
25 * tally_num - how many times as tally_add been called?
26 * @tally: the tally structure.
28 size_t tally_num(const struct tally *tally);
31 * tally_min - the minimum value passed to tally_add.
32 * @tally: the tally structure.
34 * Undefined if tally_num() == 0.
36 ssize_t tally_min(const struct tally *tally);
39 * tally_max - the maximum value passed to tally_add.
40 * @tally: the tally structure.
42 * Undefined if tally_num() == 0.
44 ssize_t tally_max(const struct tally *tally);
47 * tally_mean - the mean value passed to tally_add.
48 * @tally: the tally structure.
50 * Undefined if tally_num() == 0, but will not crash.
52 ssize_t tally_mean(const struct tally *tally);
55 * tally_total - the total value passed to tally_add.
56 * @tally: the tally structure.
57 * @overflow: the overflow value (or NULL).
59 * If your total can't overflow a ssize_t, you don't need @overflow.
60 * Otherwise, @overflow is the upper ssize_t, and the return value should
61 * be treated as the lower size_t (ie. the sign bit is in @overflow).
63 ssize_t tally_total(const struct tally *tally, ssize_t *overflow);
66 * tally_approx_median - the approximate median value passed to tally_add.
67 * @tally: the tally structure.
68 * @err: the error in the returned value (ie. real median is +/- @err).
70 * Undefined if tally_num() == 0, but will not crash. Because we
71 * don't reallocate, we don't store all values, so this median cannot be
74 ssize_t tally_approx_median(const struct tally *tally, size_t *err);
77 * tally_approx_mode - the approximate mode value passed to tally_add.
78 * @tally: the tally structure.
79 * @err: the error in the returned value (ie. real mode is +/- @err).
81 * Undefined if tally_num() == 0, but will not crash. Because we
82 * don't reallocate, we don't store all values, so this mode cannot be
83 * exact. It could well be a value which was never passed to tally_add!
85 ssize_t tally_approx_mode(const struct tally *tally, size_t *err);
87 #define TALLY_MIN_HISTO_WIDTH 8
88 #define TALLY_MIN_HISTO_HEIGHT 3
91 * tally_graph - return an ASCII image of the tally_add distribution
92 * @tally: the tally structure.
93 * @width: the maximum string width to use (>= TALLY_MIN_HISTO_WIDTH)
94 * @height: the maximum string height to use (>= TALLY_MIN_HISTO_HEIGHT)
96 * Returns a malloc()ed string which draws a multi-line graph of the
97 * distribution of values. On out of memory returns NULL.
99 char *tally_histogram(const struct tally *tally,
100 unsigned width, unsigned height);
101 #endif /* CCAN_TALLY_H */