16#ifndef CCC_PRIVATE_BITSET
17#define CCC_PRIVATE_BITSET
45 CCC_PRIVATE_BITSET_BLOCK_BITS
46 = (
sizeof(*(
struct CCC_Bitset){}.blocks) * CHAR_BIT),
59#define CCC_private_bitset_block_count(private_bit_capacity) \
60 (((private_bit_capacity) + (CCC_PRIVATE_BITSET_BLOCK_BITS - 1)) \
61 / CCC_PRIVATE_BITSET_BLOCK_BITS)
64#define CCC_private_bitset_block_bytes(private_bit_capacity) \
65 (sizeof(*(struct CCC_Bitset){}.blocks) \
66 * CCC_private_bitset_block_count(private_bit_capacity))
69#define CCC_private_bitset_default() \
70 (struct CCC_Bitset) { \
74#define CCC_private_bitset_non_CCC_private_bitset_default_size( \
79#define CCC_private_bitset_default_size(private_cap, ...) private_cap
81#define CCC_private_bitset_optional_size(private_cap, ...) \
82 __VA_OPT__(CCC_private_bitset_non_) \
83 ##CCC_private_bitset_default_size(private_cap, __VA_ARGS__)
87#define CCC_private_bitset_for( \
88 private_cap, private_count, private_bitblock_pointer \
90 (struct CCC_Bitset) { \
92 (private_bitblock_pointer), \
94 CCC_private_bitset_block_bytes(private_cap) \
96 .count = (private_count), .capacity = (private_cap), \
101#define CCC_private_bitset_from( \
103 private_start_index, \
109 (struct { struct CCC_Bitset private; }){(__extension__({ \
110 struct CCC_Bitset private_bitset = CCC_private_bitset_default(); \
111 size_t const private_cap \
112 = CCC_private_bitset_optional_size((private_count), __VA_ARGS__); \
113 size_t private_index = (private_start_index); \
114 if (CCC_private_bitset_reserve( \
116 private_cap < private_count ? private_count : private_cap, \
119 == CCC_RESULT_OK) { \
120 private_bitset.count = private_count; \
121 while (private_index < private_count \
122 && private_string[private_index]) { \
123 (void)CCC_private_bitset_set( \
126 private_string[private_index] == private_on_char \
130 private_bitset.count = private_index; \
136#define CCC_private_bitset_with_capacity(private_allocate, private_cap, ...) \
137 (struct { struct CCC_Bitset private; }){(__extension__({ \
138 struct CCC_Bitset private_bitset = CCC_private_bitset_default(); \
139 size_t const private_count \
140 = CCC_private_bitset_optional_size((private_cap), __VA_ARGS__); \
141 if (CCC_private_bitset_reserve( \
142 &private_bitset, private_cap, &private_allocate \
144 == CCC_RESULT_OK) { \
145 private_bitset.count = private_count; \
154#if defined(__clang__) || defined(__llvm__)
158# define CCC_private_bitset_count_check_storage_for( \
160 private_bit_compound_literal, \
161 private_optional_storage_specifier... \
163 (private_optional_storage_specifier struct { \
165 sizeof(private_bit_compound_literal), \
166 "Specify non-zero capacity of bits." \
169 sizeof(*(private_bit_compound_literal)) == sizeof(CCC_Bit), \
170 "CCC_bitset_storage_for and CCC_bitset_with_storage only " \
172 "a (CCC_Bit[N]){} compound literal array as an argument. Do " \
174 "use CCC_bitset_storage_for as an argument to " \
175 "CCC_bitset_with_storage." \
178 (private_count) <= sizeof(private_bit_compound_literal), \
179 "Bit count is less than or equal to capacity." \
181 typeof(*(struct CCC_Bitset){}.blocks) private \
182 [CCC_private_bitset_block_count( \
183 sizeof(private_bit_compound_literal) \
189# define CCC_private_bitset_storage_for( \
190 private_bit_compound_literal, private_optional_storage_specifier... \
192 CCC_private_bitset_count_check_storage_for( \
194 private_bit_compound_literal, \
195 private_optional_storage_specifier \
200# define CCC_private_bitset_count_check_storage_for( \
202 private_bit_compound_literal, \
203 private_optional_storage_specifier... \
206 *(struct CCC_Bitset){}.blocks \
207 )[CCC_private_bitset_block_count( \
208 sizeof(private_bit_compound_literal) \
213# define CCC_private_bitset_storage_for( \
214 private_bit_compound_literal, private_optional_storage_specifier... \
216 CCC_private_bitset_count_check_storage_for( \
218 private_bit_compound_literal, \
219 private_optional_storage_specifier \
224#define CCC_private_bitset_with_storage( \
226 private_compound_literal_array, \
227 private_optional_storage_specifier... \
229 (struct CCC_Bitset) { \
230 .blocks = CCC_private_bitset_count_check_storage_for( \
232 private_compound_literal_array, \
233 private_optional_storage_specifier \
235 .count = (private_count), \
236 .capacity = CCC_private_bitset_block_count( \
237 sizeof(private_compound_literal_array) \
239 * sizeof(*(struct CCC_Bitset){}.blocks) * CHAR_BIT, \
The C Container Collection Configuration Header. For full download and install instructions using a u...
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:376
Definition: private_bitset.h:34
unsigned * blocks
Definition: private_bitset.h:36
size_t count
Definition: private_bitset.h:38
size_t capacity
Definition: private_bitset.h:40
CCC_Tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:178
CCC_Result
A result of actions on containers.
Definition: types.h:192