C Container Collection (CCC)
Loading...
Searching...
No Matches
impl_bitset.h
1#ifndef CCC_IMPL_BITSET
2#define CCC_IMPL_BITSET
3
5#include <limits.h>
6#include <stddef.h>
9#include "../types.h"
10
12typedef unsigned ccc_bitblock_;
13
15struct ccc_bitset_
16{
17 ccc_bitblock_ *mem_;
18 size_t sz_;
19 size_t cap_;
20 ccc_alloc_fn *alloc_;
21 void *aux_;
22};
23
25#define ccc_impl_bs_blocks(bit_cap) \
26 (((bit_cap) + ((sizeof(ccc_bitblock_) * CHAR_BIT) - 1)) \
27 / (sizeof(ccc_bitblock_) * CHAR_BIT))
28
30#define IMPL_BS_NON_IMPL_BS_DEFAULT_SIZE(...) __VA_ARGS__
32#define IMPL_BS_DEFAULT_SIZE(...) 0
34#define IMPL_BS_OPTIONAL_SIZE(...) \
35 __VA_OPT__(IMPL_BS_NON_)##IMPL_BS_DEFAULT_SIZE(__VA_ARGS__)
36
38#define ccc_impl_bs_init(bitblock_ptr, alloc_fn, aux, cap, ...) \
39 { \
40 .mem_ = (bitblock_ptr), \
41 .sz_ = IMPL_BS_OPTIONAL_SIZE(__VA_ARGS__), \
42 .cap_ = (cap), \
43 .alloc_ = (alloc_fn), \
44 .aux_ = (aux), \
45 }
46
47#endif /* CCC_IMPL_BITSET */
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:283