6 * jset - set of pointers (based on libJudy)
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.
12 * jset.h contains typesafe wrappers for this usage.
15 * // Simple analysis of one-byte mallocs.
16 * #include <ccan/jset/jset.h>
22 * JSET_MEMBERS(char *);
25 * int main(int argc, char *argv[])
27 * unsigned int i, runs, reuse;
28 * size_t mindist = -1;
29 * struct jset_char *set = jset_new(struct jset_char);
32 * runs = (argc == 1 ? 1000 : atoi(argv[1]));
34 * errx(1, "Invalid number of allocations '%s'", argv[1]);
36 * for (i = 0; i < runs; i++)
37 * if (!jset_set(set, malloc(1)))
38 * errx(1, "same pointer allocated twice!");
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)
46 * // Free them all, see how many we reallocate.
47 * for (p = jset_first(set); p; p = jset_next(set, p))
49 * for (reuse = 0, i = 0; i < runs; i++)
50 * reuse += jset_test(set, malloc(1));
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,
57 * 100.0 * reuse / runs);
61 * License: LGPL (v2.1 or any later version)
62 * Author: Rusty Russell <rusty@rustcorp.com.au>
64 int main(int argc, char *argv[])
69 if (strcmp(argv[1], "depends") == 0) {
70 printf("ccan/build_assert\n");
71 printf("ccan/compiler\n");
72 printf("ccan/tcon\n");
77 if (strcmp(argv[1], "libs") == 0) {