16#ifndef CCC_PRIVATE_BITSET
17#define CCC_PRIVATE_BITSET
25#include "../configuration.h"
45 CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS
61#define CCC_private_flat_bitset_block_count(private_bit_capacity) \
62 (((private_bit_capacity) + (CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS - 1)) \
63 / CCC_PRIVATE_FLAT_BITSET_BLOCK_BITS)
66#define CCC_private_flat_bitset_block_bytes(private_bit_capacity) \
67 (sizeof(*(struct CCC_Flat_bitset){}.blocks) \
68 * CCC_private_flat_bitset_block_count(private_bit_capacity))
71#define CCC_private_flat_bitset_default() \
72 (struct CCC_Flat_bitset) { \
76#define CCC_private_flat_bitset_non_CCC_private_flat_bitset_default_size( \
81#define CCC_private_flat_bitset_default_size(private_cap, ...) private_cap
83#define CCC_private_flat_bitset_optional_size(private_cap, ...) \
84 __VA_OPT__(CCC_private_flat_bitset_non_) \
85 ##CCC_private_flat_bitset_default_size(private_cap, __VA_ARGS__)
89#define CCC_private_flat_bitset_for( \
90 private_cap, private_count, private_bitblock_pointer \
92 (struct CCC_Flat_bitset) { \
94 (private_bitblock_pointer), \
96 CCC_private_flat_bitset_block_bytes(private_cap) \
98 .count = (private_count), .capacity = (private_cap), \
103#define CCC_private_flat_bitset_from( \
105 private_start_index, \
111 (struct { struct CCC_Flat_bitset private; }){(__extension__({ \
112 struct CCC_Flat_bitset private_bitset \
113 = CCC_private_flat_bitset_default(); \
114 size_t const private_cap = CCC_private_flat_bitset_optional_size( \
115 (private_count), __VA_ARGS__ \
117 size_t private_index = (private_start_index); \
118 if (CCC_private_flat_bitset_reserve( \
120 private_cap < private_count ? private_count : private_cap, \
123 == CCC_RESULT_OK) { \
124 private_bitset.count = private_count; \
125 while (private_index < private_count \
126 && private_string[private_index]) { \
127 (void)CCC_private_flat_bitset_set( \
130 (CCC_Tribool)(private_string[private_index] \
131 == private_on_char) \
135 private_bitset.count = private_index; \
141#define CCC_private_flat_bitset_with_capacity( \
142 private_allocate, private_cap, ... \
144 (struct { struct CCC_Flat_bitset private; }){(__extension__({ \
145 struct CCC_Flat_bitset private_bitset \
146 = CCC_private_flat_bitset_default(); \
147 size_t const private_count = CCC_private_flat_bitset_optional_size( \
148 (private_cap), __VA_ARGS__ \
150 if (CCC_private_flat_bitset_reserve( \
151 &private_bitset, private_cap, &private_allocate \
153 == CCC_RESULT_OK) { \
154 private_bitset.count = private_count; \
163#if defined(__clang__) || defined(__llvm__)
167# define CCC_private_flat_bitset_count_check_storage_for( \
169 private_bit_compound_literal, \
170 private_optional_storage_specifier... \
172 (private_optional_storage_specifier struct { \
174 sizeof(private_bit_compound_literal), \
175 "Specify non-zero capacity of bits." \
178 sizeof(*(private_bit_compound_literal)) == sizeof(CCC_Bit), \
179 "CCC_flat_bitset_storage_for and " \
180 "CCC_flat_bitset_with_storage only " \
182 "a (CCC_Bit[N]){} compound literal array as an argument. Do " \
184 "use CCC_flat_bitset_storage_for as an argument to " \
185 "CCC_flat_bitset_with_storage." \
188 (private_count) <= sizeof(private_bit_compound_literal), \
189 "Bit count is less than or equal to capacity." \
191 typeof(*(struct CCC_Flat_bitset){}.blocks) private \
192 [CCC_private_flat_bitset_block_count( \
193 sizeof(private_bit_compound_literal) \
199# define CCC_private_flat_bitset_storage_for( \
200 private_bit_compound_literal, private_optional_storage_specifier... \
202 CCC_private_flat_bitset_count_check_storage_for( \
204 private_bit_compound_literal, \
205 private_optional_storage_specifier \
210# define CCC_private_flat_bitset_count_check_storage_for( \
212 private_bit_compound_literal, \
213 private_optional_storage_specifier... \
216 *(struct CCC_Flat_bitset){}.blocks \
217 )[CCC_private_flat_bitset_block_count( \
218 sizeof(private_bit_compound_literal) \
223# define CCC_private_flat_bitset_storage_for( \
224 private_bit_compound_literal, private_optional_storage_specifier... \
226 CCC_private_flat_bitset_count_check_storage_for( \
228 private_bit_compound_literal, \
229 private_optional_storage_specifier \
234#define CCC_private_flat_bitset_with_storage( \
236 private_compound_literal_array, \
237 private_optional_storage_specifier... \
239 (struct CCC_Flat_bitset) { \
240 .blocks = CCC_private_flat_bitset_count_check_storage_for( \
242 private_compound_literal_array, \
243 private_optional_storage_specifier \
245 .count = (private_count), \
246 .capacity = CCC_private_flat_bitset_block_count( \
247 sizeof(private_compound_literal_array) \
249 * sizeof(*(struct CCC_Flat_bitset){}.blocks) * CHAR_BIT, \
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:369
Definition: private_flat_bitset.h:34
size_t capacity
Definition: private_flat_bitset.h:40
unsigned * blocks
Definition: private_flat_bitset.h:36
size_t count
Definition: private_flat_bitset.h:38
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