26 typedef unsigned int optk_bits_t;
32 #define OPTK_BITSIZEOF(object) (sizeof(object) * CHAR_BIT)
40 OPTK_BITS_ELT_MIN = 0,
41 OPTK_BITS_ELT_MAX = (int)(OPTK_BITSIZEOF(optk_bits_t) - 1)
51 optk_bits_test(optk_bits_t
set,
int elt)
53 return (
set & (1U << elt)) != 0;
57 optk_bits_set(optk_bits_t *
set,
int elt)
63 optk_bits_reset(optk_bits_t *
set,
int elt)
69 optk_bits_flip(optk_bits_t *
set,
int elt)
75 optk_bits__range__(
int start_elt,
int stop_elt)
77 return ((1U << (stop_elt - start_elt) << 1) - 1) << start_elt;
81 optk_bits_test_all_in_range(optk_bits_t
set,
int start_elt,
int stop_elt)
83 return (start_elt <= stop_elt) ?
84 ((~set & optk_bits__range__(start_elt, stop_elt)) == 0) : 1;
88 optk_bits_test_any_in_range(optk_bits_t
set,
int start_elt,
int stop_elt)
90 return (start_elt <= stop_elt) ?
91 ((
set & optk_bits__range__(start_elt, stop_elt)) != 0) : 0;
95 optk_bits_set_range(optk_bits_t *
set,
int start_elt,
int stop_elt)
97 if (start_elt <= stop_elt)
98 *
set |= (((1U << (stop_elt - start_elt) << 1) - 1) << start_elt);
102 optk_bits_reset_range(optk_bits_t *
set,
int start_elt,
int stop_elt)
104 if (start_elt <= stop_elt)
105 *
set &= ~(((1U << (stop_elt - start_elt) << 1) - 1) << start_elt);
109 optk_bits_flip_range(optk_bits_t *
set,
int start_elt,
int stop_elt)
111 if (start_elt <= stop_elt)
112 *
set ^= (((1U << (stop_elt - start_elt) << 1) - 1) << start_elt);
117 #define optk_bits_test(set, elt) \
118 (((set) & (1U << (elt))) != 0)
120 #define optk_bits_set(set, elt) \
121 (*(set) |= (1U << (elt)))
123 #define optk_bits_reset(set, elt) \
124 (*(set) &= ~(1U << (elt)))
126 #define optk_bits_flip(set, elt) \
127 (*(set) ^= (1U << (elt)))
129 #define optk_bits__range__(start_elt, stop_elt) \
130 (((1U << ((stop_elt) - (start_elt)) << 1) - 1) << (start_elt))
132 #define optk_bits_test_all_in_range(set, start_elt, stop_elt) \
133 (((start_elt) <= (stop_elt)) \
134 ? (~(set) & optk_bits__range__(start_elt, stop_elt)) == 0 \
137 #define optk_bits_test_any_in_range(set, start_elt, stop_elt) \
138 (((start_elt) <= (stop_elt)) \
139 ? ((set) & optk_bits__range__(start_elt, stop_elt)) != 0 \
142 #define optk_bits_set_range(set, start_elt, stop_elt) \
143 (*(set) |= ((start_elt) <= (stop_elt)) \
144 ? optk_bits__range__(start_elt, stop_elt) \
147 #define optk_bits_reset_range(set, start_elt, stop_elt) \
148 (*(set) &= ((start_elt) <= (stop_elt)) \
149 ? ~optk_bits__range__(start_elt, stop_elt) \
152 #define optk_bits_flip_range(set, start_elt, stop_elt) \
153 (*(set) ^= ((start_elt) <= (stop_elt)) \
154 ? optk_bits__range__(start_elt, stop_elt) \
166 optk_bits_count(optk_bits_t
set);
175 optk_bits_find_first(optk_bits_t
set);
184 optk_bits_find_next(optk_bits_t
set,
int elt);
193 optk_bits_find_last(optk_bits_t
set);
202 optk_bits_find_prev(optk_bits_t
set,
int elt);
231 optk_rangeset_string_to_bits(
const char *str,
size_t *end_idx);
243 optk_bits_to_rangeset_string(
char *sbuf,
size_t sbuf_size, optk_bits_t
set);