]> git.ozlabs.org Git - ccan/blob - ccan/jset/_info
ccan: Correct some poor conventions in _info includes
[ccan] / ccan / jset / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * jset - set of pointers (based on libJudy)
7  *
8  * This provides a convenient wrapper for using Judy bitsets; using
9  * pointers (or unsigned longs) as the index, Judy arrays provide an
10  * efficient bit array or bit map of variable size.
11  *
12  * jset.h contains typesafe wrappers for this usage.
13  *
14  * Example:
15  * // Simple analysis of one-byte mallocs.
16  * #include <ccan/jset/jset.h>
17  * #include <stdlib.h>
18  * #include <stdio.h>
19  * #include <err.h>
20  *
21  * struct jset_char {
22  *      JSET_MEMBERS(char *);
23  * };
24  *
25  * int main(int argc, char *argv[])
26  * {
27  *      unsigned int i, runs, reuse;
28  *      size_t mindist = -1;
29  *      struct jset_char *set = jset_new(struct jset_char);
30  *      char *p, *prev;
31  *
32  *      runs = (argc == 1 ? 1000 : atoi(argv[1]));
33  *      if (!runs)
34  *              errx(1, "Invalid number of allocations '%s'", argv[1]);
35  *
36  *      for (i = 0; i < runs; i++)
37  *              if (!jset_set(set, malloc(1)))
38  *                      errx(1, "same pointer allocated twice!");
39  *
40  *      // Calculate minimum distance
41  *      prev = jset_first(set)+1;
42  *      for (p = jset_first(set); p; prev = p, p = jset_next(set,p))
43  *              if (p - prev < mindist)
44  *                      mindist = p - prev;
45  *
46  *      // Free them all, see how many we reallocate.
47  *      for (p = jset_first(set); p; p = jset_next(set, p))
48  *              free(p);
49  *      for (reuse = 0, i = 0; i < runs; i++)
50  *              reuse += jset_test(set, malloc(1));
51  *
52  *      printf("Allocation density (bytes): %zu\n"
53  *             "Minimum inter-pointer distance: %zu\n"
54  *             "Reuse rate: %.0f%%\n",
55  *             (jset_last(set) - jset_first(set)) / runs,
56  *             mindist,
57  *             100.0 * reuse / runs);
58  *      return 0;
59  * }
60  *
61  * License: LGPL (v2.1 or any later version)
62  * Author: Rusty Russell <rusty@rustcorp.com.au>
63  */
64 int main(int argc, char *argv[])
65 {
66         if (argc != 2)
67                 return 1;
68
69         if (strcmp(argv[1], "depends") == 0) {
70                 printf("ccan/build_assert\n");
71                 printf("ccan/compiler\n");
72                 printf("ccan/tcon\n");
73                 printf("Judy\n");
74                 return 0;
75         }
76
77         if (strcmp(argv[1], "libs") == 0) {
78                 printf("Judy\n");
79                 return 0;
80         }
81
82         return 1;
83 }