C Container Collection (CCC)
Loading...
Searching...
No Matches
impl_bitset.h
1
16#ifndef CCC_IMPL_BITSET
17#define CCC_IMPL_BITSET
18
20#include <limits.h>
21#include <stddef.h>
24#include "../types.h"
25
32struct ccc_bitset
33{
35 unsigned *blocks;
37 size_t count;
39 size_t capacity;
41 ccc_any_alloc_fn *alloc;
43 void *aux;
44};
45
46enum : size_t
47{
49 CCC_IMPL_BS_BLOCK_BITS = (sizeof(*(struct ccc_bitset){}.blocks) * CHAR_BIT),
50};
51
54#define ccc_impl_bs_block_count(impl_bit_cap) \
55 (((impl_bit_cap) + (CCC_IMPL_BS_BLOCK_BITS - 1)) / CCC_IMPL_BS_BLOCK_BITS)
56
58#define ccc_impl_bs_block_bytes(impl_bit_cap) \
59 (sizeof(*(struct ccc_bitset){}.blocks) * (impl_bit_cap))
60
64#define ccc_impl_bs_blocks(impl_bit_cap, ...) \
65 (__VA_OPT__(__VA_ARGS__) typeof ( \
66 *(struct ccc_bitset){}.blocks)[ccc_impl_bs_block_count(impl_bit_cap)]) \
67 {}
68
70#define IMPL_BS_NON_IMPL_BS_DEFAULT_SIZE(impl_cap, ...) __VA_ARGS__
72#define IMPL_BS_DEFAULT_SIZE(impl_cap, ...) impl_cap
74#define IMPL_BS_OPTIONAL_SIZE(impl_cap, ...) \
75 __VA_OPT__(IMPL_BS_NON_)##IMPL_BS_DEFAULT_SIZE(impl_cap, __VA_ARGS__)
76
81#define ccc_impl_bs_init(impl_bitblock_ptr, impl_alloc_fn, impl_aux, impl_cap, \
82 ...) \
83 { \
84 .blocks = (impl_bitblock_ptr), \
85 .count = IMPL_BS_OPTIONAL_SIZE((impl_cap), __VA_ARGS__), \
86 .capacity = (impl_cap), \
87 .alloc = (impl_alloc_fn), \
88 .aux = (impl_aux), \
89 }
90
91#endif /* CCC_IMPL_BITSET */
struct ccc_bitset ccc_bitset
The bit set type that may be stored and initialized on the stack, heap, or data segment at compile or...
Definition: bitset.h:73
void * ccc_any_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:312