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)) == sizeof(CCC_Bit), \
189 "CCC_flat_bitset_storage_for and " \
190 "CCC_flat_bitset_with_storage only " \
192 "a (CCC_Bit[N]){} compound literal array as an argument. Do " \
194 "use CCC_flat_bitset_storage_for as an argument to " \
195 "CCC_flat_bitset_with_storage." \
198 (private_count) <= sizeof(private_bit_compound_literal), \
199 "Bit count is less than or equal to capacity." \
201 typeof(*(struct CCC_Flat_bitset){}.blocks) private \
202 [CCC_private_flat_bitset_block_count( \
203 sizeof(private_bit_compound_literal) \
209# define CCC_private_flat_bitset_storage_for( \
210 private_bit_compound_literal, private_optional_storage_specifier... \
212 CCC_private_flat_bitset_count_check_storage_for( \
214 private_bit_compound_literal, \
215 private_optional_storage_specifier \
220# define CCC_private_flat_bitset_count_check_storage_for( \
222 private_bit_compound_literal, \
223 private_optional_storage_specifier... \
226 *(struct CCC_Flat_bitset){}.blocks \
227 )[CCC_private_flat_bitset_block_count( \
228 sizeof(private_bit_compound_literal) \
233# define CCC_private_flat_bitset_storage_for( \
234 private_bit_compound_literal, private_optional_storage_specifier... \
236 CCC_private_flat_bitset_count_check_storage_for( \
238 private_bit_compound_literal, \
239 private_optional_storage_specifier \
244#define CCC_private_flat_bitset_with_storage( \
246 private_compound_literal_array, \
247 private_optional_storage_specifier... \
249 (struct CCC_Flat_bitset) { \
250 .blocks = CCC_private_flat_bitset_count_check_storage_for( \
252 private_compound_literal_array, \
253 private_optional_storage_specifier \
255 .count = (private_count), \
256 .capacity = CCC_private_flat_bitset_block_count( \
257 sizeof(private_compound_literal_array) \
259 * 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