23#ifndef CCC_PRIVATE_FLAT_BITSET
24#define CCC_PRIVATE_FLAT_BITSET
32#include "../configuration.h"
70#define CCC_private_flat_bitset_block_count(private_bit_capacity) \
71 (((private_bit_capacity) + (CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS - 1)) \
72 / CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS)
75#define CCC_private_flat_bitset_block_bytes(private_bit_capacity) \
76 (sizeof(*(struct CCC_Flat_bitset){}.blocks) \
77 * CCC_private_flat_bitset_block_count(private_bit_capacity))
80#define CCC_private_flat_bitset_default() \
81 (struct CCC_Flat_bitset) { \
85#define CCC_private_flat_bitset_non_CCC_private_flat_bitset_default_size( \
90#define CCC_private_flat_bitset_default_size(private_cap, ...) private_cap
92#define CCC_private_flat_bitset_optional_size(private_cap, ...) \
93 __VA_OPT__(CCC_private_flat_bitset_non_) \
94 ##CCC_private_flat_bitset_default_size(private_cap, __VA_ARGS__)
98#define CCC_private_flat_bitset_for( \
99 private_cap, private_count, private_bitblock_pointer \
101 (struct CCC_Flat_bitset) { \
103 (private_bitblock_pointer), \
105 CCC_private_flat_bitset_block_bytes(private_cap) \
107 .count = (private_count), .capacity = (private_cap), \
112#define CCC_private_flat_bitset_from( \
114 private_start_index, \
120 (struct { struct CCC_Flat_bitset private; }){(__extension__({ \
121 struct CCC_Flat_bitset private_bitset \
122 = CCC_private_flat_bitset_default(); \
123 size_t const private_cap = CCC_private_flat_bitset_optional_size( \
124 (private_count), __VA_ARGS__ \
126 size_t private_index = (private_start_index); \
127 if (CCC_private_flat_bitset_reserve( \
129 private_cap < private_count ? private_count : private_cap, \
132 == CCC_RESULT_OK) { \
133 private_bitset.count = private_count; \
134 while (private_index < private_count \
135 && private_string[private_index]) { \
136 (void)CCC_private_flat_bitset_set( \
139 (CCC_Tribool)(private_string[private_index] \
140 == private_on_char) \
144 private_bitset.count = private_index; \
150#define CCC_private_flat_bitset_with_capacity( \
151 private_allocate, private_cap, ... \
153 (struct { struct CCC_Flat_bitset private; }){(__extension__({ \
154 struct CCC_Flat_bitset private_bitset \
155 = CCC_private_flat_bitset_default(); \
156 size_t const private_count = CCC_private_flat_bitset_optional_size( \
157 (private_cap), __VA_ARGS__ \
159 if (CCC_private_flat_bitset_reserve( \
160 &private_bitset, private_cap, &private_allocate \
162 == CCC_RESULT_OK) { \
163 private_bitset.count = private_count; \
172#if defined(__clang__) || defined(__llvm__)
176# define CCC_private_flat_bitset_count_check_storage_for( \
178 private_bit_compound_literal, \
179 private_optional_storage_specifier... \
181 (private_optional_storage_specifier struct { \
183 sizeof(private_bit_compound_literal), \
184 "Specify non-zero capacity of bits." \
187 sizeof(*(private_bit_compound_literal)) == sizeof(CCC_Bit), \
188 "CCC_flat_bitset_storage_for and " \
189 "CCC_flat_bitset_with_storage only " \
191 "a (CCC_Bit[N]){} compound literal array as an argument. Do " \
193 "use CCC_flat_bitset_storage_for as an argument to " \
194 "CCC_flat_bitset_with_storage." \
197 (private_count) <= sizeof(private_bit_compound_literal), \
198 "Bit count is less than or equal to capacity." \
200 typeof(*(struct CCC_Flat_bitset){}.blocks) private \
201 [CCC_private_flat_bitset_block_count( \
202 sizeof(private_bit_compound_literal) \
208# define CCC_private_flat_bitset_storage_for( \
209 private_bit_compound_literal, private_optional_storage_specifier... \
211 CCC_private_flat_bitset_count_check_storage_for( \
213 private_bit_compound_literal, \
214 private_optional_storage_specifier \
219# define CCC_private_flat_bitset_count_check_storage_for( \
221 private_bit_compound_literal, \
222 private_optional_storage_specifier... \
225 *(struct CCC_Flat_bitset){}.blocks \
226 )[CCC_private_flat_bitset_block_count( \
227 sizeof(private_bit_compound_literal) \
232# define CCC_private_flat_bitset_storage_for( \
233 private_bit_compound_literal, private_optional_storage_specifier... \
235 CCC_private_flat_bitset_count_check_storage_for( \
237 private_bit_compound_literal, \
238 private_optional_storage_specifier \
243#define CCC_private_flat_bitset_with_storage( \
245 private_compound_literal_array, \
246 private_optional_storage_specifier... \
248 (struct CCC_Flat_bitset) { \
249 .blocks = CCC_private_flat_bitset_count_check_storage_for( \
251 private_compound_literal_array, \
252 private_optional_storage_specifier \
254 .count = (private_count), \
255 .capacity = CCC_private_flat_bitset_block_count( \
256 sizeof(private_compound_literal_array) \
258 * sizeof(*(struct CCC_Flat_bitset){}.blocks) * CHAR_BIT, \
CCC_Result CCC_private_flat_bitset_reserve(struct CCC_Flat_bitset *, size_t, CCC_Allocator const *)
CCC_Tribool CCC_private_flat_bitset_set(struct CCC_Flat_bitset *, size_t, CCC_Tribool)
@ CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS
Definition: private_flat_bitset.h:52
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:384
Definition: private_flat_bitset.h:41
size_t capacity
Definition: private_flat_bitset.h:47
unsigned * blocks
Definition: private_flat_bitset.h:43
size_t count
Definition: private_flat_bitset.h:45
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