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_approx_median - the approximate median value passed to tally_add.
56 * @tally: the tally structure.
57 * @err: the error in the returned value (ie. real median is +/- @err).
59 * Undefined if tally_num() == 0, but will not crash. Because we
60 * don't reallocate, we don't store all values, so this median cannot be
63 ssize_t tally_approx_median(const struct tally *tally, size_t *err);
66 * tally_approx_mode - the approximate mode value passed to tally_add.
67 * @tally: the tally structure.
68 * @err: the error in the returned value (ie. real mode 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 mode cannot be
72 * exact. It could well be a value which was never passed to tally_add!
74 ssize_t tally_approx_mode(const struct tally *tally, size_t *err);
76 #define TALLY_MIN_HISTO_WIDTH 8
77 #define TALLY_MIN_HISTO_HEIGHT 3
80 * tally_graph - return an ASCII image of the tally_add distribution
81 * @tally: the tally structure.
82 * @width: the maximum string width to use (>= TALLY_MIN_HISTO_WIDTH)
83 * @height: the maximum string height to use (>= TALLY_MIN_HISTO_HEIGHT)
85 * Returns a malloc()ed string which draws a multi-line graph of the
86 * distribution of values. On out of memory returns NULL.
88 char *tally_histogram(const struct tally *tally,
89 unsigned width, unsigned height);
90 #endif /* CCAN_TALLY_H */