23#ifndef CCC_PRIVATE_FLAT_BITSET
24#define CCC_PRIVATE_FLAT_BITSET
32#include "../configuration.h"
71#define CCC_private_flat_bitset_block_count(private_bit_capacity) \
72 (((private_bit_capacity) + (CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS - 1)) \
73 / CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS)
76#define CCC_private_flat_bitset_block_bytes(private_bit_capacity) \
77 (sizeof(*(struct CCC_Flat_bitset){}.blocks) \
78 * CCC_private_flat_bitset_block_count(private_bit_capacity))
81#define CCC_private_flat_bitset_default() \
82 (struct CCC_Flat_bitset) { \
86#define CCC_private_flat_bitset_non_CCC_private_flat_bitset_default_size( \
91#define CCC_private_flat_bitset_default_size(private_cap, ...) private_cap
93#define CCC_private_flat_bitset_optional_size(private_cap, ...) \
94 __VA_OPT__(CCC_private_flat_bitset_non_) \
95 ##CCC_private_flat_bitset_default_size(private_cap, __VA_ARGS__)
99#define CCC_private_flat_bitset_for( \
100 private_cap, private_count, private_bitblock_pointer \
102 (struct CCC_Flat_bitset) { \
104 (private_bitblock_pointer), \
106 CCC_private_flat_bitset_block_bytes(private_cap) \
108 .count = (private_count), .capacity = (private_cap), \
113#define CCC_private_flat_bitset_from( \
115 private_start_index, \
121 (struct { struct CCC_Flat_bitset private; }){(__extension__({ \
122 struct CCC_Flat_bitset private_bitset \
123 = CCC_private_flat_bitset_default(); \
124 size_t const private_cap = CCC_private_flat_bitset_optional_size( \
125 (private_count), __VA_ARGS__ \
127 size_t private_index = (private_start_index); \
128 if (CCC_private_flat_bitset_reserve( \
130 private_cap < private_count ? private_count : private_cap, \
133 == CCC_RESULT_OK) { \
134 private_bitset.count = private_count; \
135 while (private_index < private_count \
136 && private_string[private_index]) { \
137 (void)CCC_private_flat_bitset_set( \
140 (CCC_Tribool)(private_string[private_index] \
141 == private_on_char) \
145 private_bitset.count = private_index; \
151#define CCC_private_flat_bitset_with_capacity( \
152 private_allocate, private_cap, ... \
154 (struct { struct CCC_Flat_bitset private; }){(__extension__({ \
155 struct CCC_Flat_bitset private_bitset \
156 = CCC_private_flat_bitset_default(); \
157 size_t const private_count = CCC_private_flat_bitset_optional_size( \
158 (private_cap), __VA_ARGS__ \
160 if (CCC_private_flat_bitset_reserve( \
161 &private_bitset, private_cap, &private_allocate \
163 == CCC_RESULT_OK) { \
164 private_bitset.count = private_count; \
173#if defined(__clang__) || defined(__llvm__)
177# define CCC_private_flat_bitset_count_check_storage_for( \
179 private_bit_compound_literal, \
180 private_optional_storage_specifier... \
182 (private_optional_storage_specifier struct { \
184 sizeof(private_bit_compound_literal), \
185 "Specify non-zero capacity of bits." \
188 sizeof(*(private_bit_compound_literal)) \
189 == sizeof(CCC_Tribool), \
190 "CCC_flat_bitset_storage_for and " \
191 "CCC_flat_bitset_with_storage only " \
193 "a (CCC_Tribool[N]){} compound literal array as an argument. " \
196 "use CCC_flat_bitset_storage_for as an argument to " \
197 "CCC_flat_bitset_with_storage." \
200 (private_count) <= sizeof(private_bit_compound_literal), \
201 "Bit count is less than or equal to capacity." \
203 typeof(*(struct CCC_Flat_bitset){}.blocks) private \
204 [CCC_private_flat_bitset_block_count( \
205 sizeof(private_bit_compound_literal) \
211# define CCC_private_flat_bitset_storage_for( \
212 private_bit_compound_literal, private_optional_storage_specifier... \
214 CCC_private_flat_bitset_count_check_storage_for( \
216 private_bit_compound_literal, \
217 private_optional_storage_specifier \
222# define CCC_private_flat_bitset_count_check_storage_for( \
224 private_bit_compound_literal, \
225 private_optional_storage_specifier... \
228 *(struct CCC_Flat_bitset){}.blocks \
229 )[CCC_private_flat_bitset_block_count( \
230 sizeof(private_bit_compound_literal) \
235# define CCC_private_flat_bitset_storage_for( \
236 private_bit_compound_literal, private_optional_storage_specifier... \
238 CCC_private_flat_bitset_count_check_storage_for( \
240 private_bit_compound_literal, \
241 private_optional_storage_specifier \
246#define CCC_private_flat_bitset_with_storage( \
248 private_compound_literal_array, \
249 private_optional_storage_specifier... \
251 (struct CCC_Flat_bitset) { \
252 .blocks = CCC_private_flat_bitset_count_check_storage_for( \
254 private_compound_literal_array, \
255 private_optional_storage_specifier \
257 .count = (private_count), \
258 .capacity = CCC_private_flat_bitset_block_count( \
259 sizeof(private_compound_literal_array) \
261 * 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