1 #ifndef CCAN_JBITSET_TYPE_H
2 #define CCAN_JBITSET_TYPE_H
3 #include <ccan/jbitset/jbitset.h>
6 * JBIT_DEFINE_TYPE - create a set of jbit ops for a given pointer type
7 * @type: a type whose pointers will go into the bitset.
8 * @name: a name for all the functions to define (of form jbit_<name>_*)
10 * This macro defines a set of inline functions for typesafe and convenient
11 * usage of a Judy bitset for pointers. It is assumed that a NULL pointer
12 * is never set in the bitset.
15 * JBIT_DEFINE_TYPE(char, char);
16 * JBIT_DEFINE_TYPE(struct foo, foo);
18 * static struct jbitset_char *jc;
19 * struct jbitset_foo *jf;
21 * static void add_to_bitsets(const char *p, const struct foo *f)
23 * // Note, this adds the pointer, not the string!
24 * jbit_char_set(jc, p);
25 * jbit_foo_set(jf, f);
28 #define JBIT_DEFINE_TYPE(type, name) \
29 struct jbitset_##name; \
30 static inline struct jbitset_##name *jbit_##name##_new(void) \
32 return (struct jbitset_##name *)jbit_new(); \
34 static inline void jbit_##name##_free(const struct jbitset_##name *set) \
36 jbit_free((const struct jbitset *)set); \
38 static inline const char *jbit_##name##_error(struct jbitset_##name *set) \
40 return jbit_error((struct jbitset *)set); \
42 static inline bool jbit_##name##_test(const struct jbitset_##name *set, \
45 return jbit_test((const struct jbitset *)set, (size_t)index); \
47 static inline bool jbit_##name##_set(struct jbitset_##name *set, \
50 return jbit_set((struct jbitset *)set, (size_t)index); \
52 static inline bool jbit_##name##_clear(struct jbitset_##name *set, \
55 return jbit_clear((struct jbitset *)set, (size_t)index); \
57 static inline size_t jbit_##name##_count(struct jbitset_##name *set) \
59 return jbit_popcount((const struct jbitset *)set, 0, -1); \
61 static inline type *jbit_##name##_nth(const struct jbitset_##name *set, \
64 return (type *)jbit_nth((const struct jbitset *)set, n, 0); \
66 static inline type *jbit_##name##_first(const struct jbitset_##name *set) \
68 return (type *)jbit_first((const struct jbitset *)set, 0); \
70 static inline type *jbit_##name##_next(struct jbitset_##name *set, \
73 return (type *)jbit_next((const struct jbitset *)set, (size_t)prev, 0); \
75 static inline type *jbit_##name##_last(struct jbitset_##name *set) \
77 return (type *)jbit_last((const struct jbitset *)set, 0); \
79 static inline type *jbit_##name##_prev(struct jbitset_##name *set, \
82 return (type *)jbit_prev((const struct jbitset *)set, (size_t)prev, 0); \
84 #endif /* CCAN_JBITSET_TYPE_H */