]> git.ozlabs.org Git - ccan/blob - ccan/tally/_info
ilog: credit Tim Terriberry as author in ccan/ilog/_info
[ccan] / ccan / tally / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * tally - running tally of integers
7  *
8  * The tally module implements simple analysis of a stream of integers.
9  * Numbers are fed in via tally_add(), and then the mean, median, mode and
10  * a histogram can be read out.
11  *
12  * Example:
13  *      #include <stdio.h>
14  *      #include <err.h>
15  *      #include <ccan/tally/tally.h>
16  *
17  *      int main(int argc, char *argv[])
18  *      {
19  *              struct tally *t;
20  *              unsigned int i;
21  *              size_t err;
22  *              ssize_t val;
23  *              char *histogram;
24  *
25  *              if (argc < 2)
26  *                      errx(1, "Usage: %s <number>...\n", argv[0]);
27  *
28  *              t = tally_new(100);
29  *              for (i = 1; i < argc; i++)
30  *                      tally_add(t, atol(argv[i]));
31  *
32  *              printf("Mean = %zi\n", tally_mean(t));
33  *              val = tally_approx_median(t, &err);
34  *              printf("Median = %zi (+/- %zu)\n", val, err);
35  *              val = tally_approx_mode(t, &err);
36  *              printf("Mode = %zi (+/- %zu)\n", val, err);
37  *              histogram = tally_histogram(t, 50, 10);
38  *              printf("Histogram:\n%s", histogram);
39  *              free(histogram);
40  *              return 0;
41  *      }
42  *
43  * License: LGPL (3 or any later version)
44  * Author: Rusty Russell <rusty@rustcorp.com.au>
45  */
46 int main(int argc, char *argv[])
47 {
48         if (argc != 2)
49                 return 1;
50
51         if (strcmp(argv[1], "depends") == 0) {
52                 printf("ccan/build_assert\n");
53                 printf("ccan/likely\n");
54                 return 0;
55         }
56
57         return 1;
58 }