16#ifndef CCC_PRIVATE_BITSET
17#define CCC_PRIVATE_BITSET
49 CCC_PRIVATE_BITSET_BLOCK_BITS
50 = (
sizeof(*(
struct CCC_Bitset){}.blocks) * CHAR_BIT),
63#define CCC_private_bitset_block_count(private_bit_cap) \
64 (((private_bit_cap) + (CCC_PRIVATE_BITSET_BLOCK_BITS - 1)) \
65 / CCC_PRIVATE_BITSET_BLOCK_BITS)
68#define CCC_private_bitset_block_bytes(private_bit_cap) \
69 (sizeof(*(struct CCC_Bitset){}.blocks) * (private_bit_cap))
74#define CCC_private_bitset_blocks(private_bit_cap, ...) \
75 (__VA_OPT__(__VA_ARGS__) typeof ( \
76 *(struct CCC_Bitset){} \
77 .blocks)[CCC_private_bitset_block_count(private_bit_cap)]) \
81#define CCC_private_bitset_non_CCC_private_bitset_default_size(private_cap, \
85#define CCC_private_bitset_default_size(private_cap, ...) private_cap
87#define CCC_private_bitset_optional_size(private_cap, ...) \
88 __VA_OPT__(CCC_private_bitset_non_) \
89 ##CCC_private_bitset_default_size(private_cap, __VA_ARGS__)
96#define CCC_private_bitset_initialize(private_bitblock_pointer, \
97 private_allocate, private_context, \
100 .blocks = (private_bitblock_pointer), \
101 .count = CCC_private_bitset_optional_size((private_cap), __VA_ARGS__), \
102 .capacity = (private_cap), \
103 .allocate = (private_allocate), \
104 .context = (private_context), \
110CCC_private_bitset_with_capacity_fn(
CCC_Allocator *
const private_allocate,
111 void *
const private_context,
112 size_t const private_cap,
113 size_t const private_count)
115 struct CCC_Bitset b = CCC_private_bitset_initialize(NULL, private_allocate,
117 if (CCC_private_bitset_reserve(&b, private_cap, private_allocate)
120 b.
count = private_count;
127#define CCC_private_bitset_from(private_allocate, private_context, \
128 private_start_index, private_count, \
129 private_on_char, private_string, ...) \
131 struct CCC_Bitset private_bitset = CCC_private_bitset_initialize( \
132 NULL, private_allocate, private_context, 0); \
133 size_t const private_cap \
134 = CCC_private_bitset_optional_size((private_count), __VA_ARGS__); \
135 size_t private_index = (private_start_index); \
136 if (CCC_private_bitset_reserve( \
138 private_cap < private_count ? private_count : private_cap, \
142 private_bitset.count = private_count; \
143 while (private_index < private_count \
144 && private_string[private_index]) \
146 (void)CCC_private_bitset_set(&private_bitset, private_index, \
147 private_string[private_index] \
148 == private_on_char); \
151 private_bitset.count = private_index; \
157#define CCC_private_bitset_with_capacity(private_allocate, private_context, \
160 struct CCC_Bitset private_bitset = CCC_private_bitset_initialize( \
161 NULL, private_allocate, private_context, 0); \
162 size_t const private_count \
163 = CCC_private_bitset_optional_size((private_cap), __VA_ARGS__); \
164 if (CCC_private_bitset_reserve(&private_bitset, private_cap, \
168 private_bitset.count = private_count; \
174#define CCC_private_bitset_with_compound_literal( \
175 private_count, private_compound_literal_array) \
177 .blocks = (private_compound_literal_array), \
178 .count = (private_count), \
179 .capacity = sizeof(private_compound_literal_array) * CHAR_BIT, \
185#define CCC_private_bitset_with_context_compound_literal( \
186 private_context, private_count, private_compound_literal_array) \
188 .blocks = (private_compound_literal_array), \
189 .count = (private_count), \
190 .capacity = sizeof(private_compound_literal_array) * CHAR_BIT, \
192 .context = (private_context), \
Definition: private_bitset.h:33
void * context
Definition: private_bitset.h:43
unsigned * blocks
Definition: private_bitset.h:35
CCC_Allocator * allocate
Definition: private_bitset.h:41
size_t count
Definition: private_bitset.h:37
size_t capacity
Definition: private_bitset.h:39
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:133
CCC_Result
A result of actions on containers.
Definition: types.h:148
@ CCC_RESULT_OK
Definition: types.h:150
void * CCC_Allocator(CCC_Allocator_context)
An allocation function at the core of all containers.
Definition: types.h:340