6 * jbitset - variable-length bitset (based on libJudy)
8 * This provides a convenient wrapper for using Judy bitsets; using
9 * integers or pointers as an index, Judy arrays provide an efficient
10 * bit array or bit map of variable size.
12 * jbitset.h simply contains wrappers for a size_t-indexed bitset, and
13 * jbitset_type.h contain a wrapper macro for pointer bitsets.
16 * // Simple analysis of one-byte mallocs.
20 * #include <ccan/jbitset/jbitset_type.h>
22 * // Define jbit_char_<op> and jbitset_char, for char * bitset.
23 * JBIT_DEFINE_TYPE(char, char);
25 * int main(int argc, char *argv[])
27 * unsigned int i, runs, reuse;
28 * size_t mindist = -1;
29 * struct jbitset_char *set = jbit_char_new();
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 (!jbit_char_set(set, malloc(1)))
38 * errx(1, "same pointer allocated twice!");
40 * // Calculate minimum distance
41 * prev = jbit_char_first(set)+1;
42 * for (p = jbit_char_first(set); p; prev = p, p = jbit_char_next(set,p))
43 * if (p - prev < mindist)
46 * // Free them all, see how many we reallocate.
47 * for (p = jbit_char_first(set); p; p = jbit_char_next(set, p))
49 * for (reuse = 0, i = 0; i < runs; i++)
50 * reuse += jbit_char_test(set, malloc(1));
52 * printf("Allocation density (bytes): %zu\n"
53 * "Minimum inter-pointer distance: %zu\n"
54 * "Reuse rate: %.0f%%\n",
55 * (jbit_char_last(set) - jbit_char_first(set)) / runs,
57 * 100.0 * reuse / runs);
61 * License: LGPL (2 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");
76 if (strcmp(argv[1], "libs") == 0) {