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
27typedef unsigned ccc_bitblock;
28
35struct ccc_bitset
36{
38 ccc_bitblock *blocks;
40 size_t count;
42 size_t capacity;
44 ccc_any_alloc_fn *alloc;
46 void *aux;
47};
48
51#define ccc_impl_bs_blocks(impl_bit_cap) \
52 (((impl_bit_cap) + ((sizeof(ccc_bitblock) * CHAR_BIT) - 1)) \
53 / (sizeof(ccc_bitblock) * CHAR_BIT))
54
56#define IMPL_BS_NON_IMPL_BS_DEFAULT_SIZE(impl_cap, ...) __VA_ARGS__
58#define IMPL_BS_DEFAULT_SIZE(impl_cap, ...) impl_cap
60#define IMPL_BS_OPTIONAL_SIZE(impl_cap, ...) \
61 __VA_OPT__(IMPL_BS_NON_)##IMPL_BS_DEFAULT_SIZE(impl_cap, __VA_ARGS__)
62
67#define ccc_impl_bs_init(impl_bitblock_ptr, impl_alloc_fn, impl_aux, impl_cap, \
68 ...) \
69 { \
70 .blocks = (impl_bitblock_ptr), \
71 .count = IMPL_BS_OPTIONAL_SIZE((impl_cap), __VA_ARGS__), \
72 .capacity = (impl_cap), \
73 .alloc = (impl_alloc_fn), \
74 .aux = (impl_aux), \
75 }
76
77#endif /* CCC_IMPL_BITSET */
ccc_bitblock ccc_bitblock
The type used to efficiently store bits in the bit set.
Definition: bitset.h:81
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