Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static CCC_Flat_buffer buffer
static CCC_Flat_bitset bitset
= CCC_flat_bitset_with_storage(
1024,
(CCC_Bit[1024]){}
(CCC_Tribool[1024]){}
);
```

Expand Down
2 changes: 1 addition & 1 deletion DOXYGEN_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ static CCC_Flat_buffer buffer
static CCC_Flat_bitset bitset
= CCC_flat_bitset_with_storage(
1024,
(CCC_Bit[1024]){}
(CCC_Tribool[1024]){}
);
```

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ validate_sudoku_box(int const board[9][9], Flat_bitset *const row_check,
Flat_bitset *const col_check, size_t const row_start,
size_t const col_start) {
Flat_bitset box_check
= flat_bitset_with_storage(DIGITS, (Bit[DIGITS]){});
= flat_bitset_with_storage(DIGITS, (CCC_Tribool[DIGITS]){});
CCC_Tribool was_on = CCC_FALSE;
for (size_t r = row_start; r < row_start + BOX_SIZE; ++r) {
for (size_t c = col_start; c < col_start + BOX_SIZE; ++c) {
Expand Down Expand Up @@ -223,9 +223,9 @@ validate_sudoku_box(int const board[9][9], Flat_bitset *const row_check,
static CCC_Tribool
is_valid_sudoku(int const board[9][9]) {
Flat_bitset row_check = flat_bitset_with_storage(
ROWS * DIGITS, (Bit[ROWS * DIGITS]){});
ROWS * DIGITS, (CCC_Tribool[ROWS * DIGITS]){});
Flat_bitset col_check = flat_bitset_with_storage(
COLS * DIGITS, (Bit[COLS * DIGITS]){});
COLS * DIGITS, (CCC_Tribool[COLS * DIGITS]){});
for (size_t row = 0; row < ROWS; row += BOX_SIZE) {
for (size_t col = 0; col < COLS; col += BOX_SIZE) {
if (!validate_sudoku_box(board, &row_check, &col_check, row, col)) {
Expand Down Expand Up @@ -1003,7 +1003,7 @@ static CCC_Flat_buffer buffer
static CCC_Flat_bitset bitset
= CCC_flat_bitset_with_storage(
1024,
(CCC_Bit[1024]){}
(CCC_Tribool[1024]){}
);
```

Expand Down
22 changes: 7 additions & 15 deletions ccc/flat_bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ All types and functions can then be written without the `CCC_` prefix. */
Types available in the container interface. */
/**@{*/

/** @brief A type to represent a single bit in the bit set.

This is used to pass a compound literal of desired bits to various initializers
and macros. The bit set is then custom built to accommodate this bit count with
platform specific blocks of fixed width integers. */
typedef uint8_t CCC_Bit;

/** @brief The bit set type that may be stored and initialized on the stack,
heap, or data segment at compile or run time.

Expand Down Expand Up @@ -120,7 +113,7 @@ number of bytes occupied by the number of bit blocks that must be allocated. */
or compile time with no allocation permissions or context from a compound
literal of bitset blocks.
@param[in] count the count of bits <= capacity of this bit set.
@param[in] compound_literal_array the compound literal of CCC_Bit specifying
@param[in] compound_literal_array the compound literal of CCC_Tribool specifying
the desired bit count for the bit set. A platform specific array of fixed width
integers is constructed to accommodate this bit count.
@param[in] optional_storage_specifier a storage specifier for the backing block
Expand All @@ -135,7 +128,7 @@ A fixed size bit set.
#define FLAT_BITSET_USING_NAMESPACE_CCC
static Flat_bitset bitset = flat_bitset_with_storage(
4096,
(Bit[4096]){}
(CCC_Tribool[4096]){}
);
```

Expand Down Expand Up @@ -237,7 +230,7 @@ static and stack based initialization options. */

/** @brief Create the underlying fixed size storage for a bit set given a
compound literal array of bits the user wishes to store.
@param[in] bit_compound_literal_array a compound literal array of `CCC_Bit`
@param[in] bit_compound_literal_array a compound literal array of `CCC_Tribool`
representing the number of bits the user wishes to store in the bit set.
@param[in] optional_storage_specifier a storage specifier for the backing block
storage may be added on newer compilers.
Expand All @@ -255,7 +248,7 @@ int
main(void)
{
void *const storage = malloc(
sizeof(CCC_flat_bitset_storage_for((CCC_Bit[4096]){}))
sizeof(CCC_flat_bitset_storage_for((CCC_Tribool[4096]){}))
);
defer free(storage);
CCC_Flat_bitset bitset = CCC_flat_bitset_for(
Expand Down Expand Up @@ -301,7 +294,7 @@ int
main(void)
{
void *const storage = malloc(
sizeof(CCC_flat_bitset_storage_for((CCC_Bit[4096]){}))
sizeof(CCC_flat_bitset_storage_for((CCC_Tribool[4096]){}))
);
defer free(storage);
CCC_Flat_bitset bitset = CCC_flat_bitset_for(
Expand Down Expand Up @@ -340,12 +333,12 @@ Manual memory management with no allocation function provided.
#define FLAT_BITSET_USING_NAMESPACE_CCC
static Flat_bitset source = flat_bitset_with_storage(
11,
(Bit[11]){}
(Tribool[11]){}
);
set_rand_bits(&source);
static Flat_bitset source = flat_bitset_with_storage(
13
(Bit[13]){}
(CCC_Tribool[13]){}
);
CCC_Result res = flat_bitset_copy(&destination, &source, &(CCC_Allocator){});
```
Expand Down Expand Up @@ -1011,7 +1004,6 @@ CCC_Tribool CCC_flat_bitset_pop_back(CCC_Flat_bitset *bitset);
container. Check for namespace clashes before name shortening. */
#ifdef FLAT_BITSET_USING_NAMESPACE_CCC
/* NOLINTBEGIN(readability-identifier-naming) */
typedef CCC_Bit Bit;
typedef CCC_Flat_bitset Flat_bitset;
# define FLAT_BITSET_BLOCK_BITS CCC_FLAT_BITSET_BLOCK_BITS
# define flat_bitset_block_count(arguments...) \
Expand Down
6 changes: 4 additions & 2 deletions ccc/private/private_flat_bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ specifiers which is a feature of C23. Not all compilers support this yet. */
"Specify non-zero capacity of bits." \
); \
static_assert( \
sizeof(*(private_bit_compound_literal)) == sizeof(CCC_Bit), \
sizeof(*(private_bit_compound_literal)) \
== sizeof(CCC_Tribool), \
"CCC_flat_bitset_storage_for and " \
"CCC_flat_bitset_with_storage only " \
"accept " \
"a (CCC_Bit[N]){} compound literal array as an argument. Do " \
"a (CCC_Tribool[N]){} compound literal array as an argument. " \
"Do " \
"not " \
"use CCC_flat_bitset_storage_for as an argument to " \
"CCC_flat_bitset_with_storage." \
Expand Down
4 changes: 2 additions & 2 deletions samples/ccczip.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ set blocks. The queue is initialized as empty with the specified capacity. */
#define bitq_from_storage(capacity, optional_storage_specifier...) \
(struct Bit_queue) { \
.bs = CCC_flat_bitset_with_storage( \
capacity, (CCC_Bit[capacity]){}, optional_storage_specifier \
capacity, (CCC_Tribool[capacity]){}, optional_storage_specifier \
) \
}

Expand Down Expand Up @@ -1573,7 +1573,7 @@ lzw_encode(
check(!first_char.error);
Lzw_code prefix = first_char.c;
CCC_Flat_bitset sliding_code_window = flat_bitset_with_storage(
0, (CCC_Bit[sizeof(Lzw_code) * CHAR_BIT]){}
0, (CCC_Tribool[sizeof(Lzw_code) * CHAR_BIT]){}
);
foreach_filechar(f, 1, c, {
CCC_Entry const e = lzw_try_insert(
Expand Down
8 changes: 4 additions & 4 deletions tests/array_tree_map/test_array_tree_map_erase.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ check_static_begin(array_tree_map_test_prime_shuffle) {
reduce the shuffle range so it will repeat some values. */
size_t shuffled_index = PRIME % (SHUFFLE_CAP - LESS);
Flat_bitset repeats
= flat_bitset_with_storage(SHUFFLE_CAP, (CCC_Bit[SHUFFLE_CAP]){});
= flat_bitset_with_storage(SHUFFLE_CAP, (CCC_Tribool[SHUFFLE_CAP]){});
for (size_t i = 0; i < SHUFFLE_CAP; ++i) {
if (occupied(array_tree_map_try_insert_wrap(
&s,
Expand Down Expand Up @@ -111,7 +111,7 @@ check_static_begin(array_tree_map_test_weak_srand) {
};
int id_keys[SRAND_CAP];
Flat_bitset repeats
= flat_bitset_with_storage(SRAND_CAP, (CCC_Bit[SRAND_CAP]){});
= flat_bitset_with_storage(SRAND_CAP, (CCC_Tribool[SRAND_CAP]){});
for (int i = 0; i < SRAND_CAP; ++i) {
int const rand_i = (int)rand(); /* NOLINT */
if (occupied(array_tree_map_try_insert_wrap(
Expand Down Expand Up @@ -156,7 +156,7 @@ check_static_begin(array_tree_map_test_insert_erase_cycles_no_allocate) {
);
int id_keys[CYCLES_TEST_CAP];
Flat_bitset repeats = flat_bitset_with_storage(
CYCLES_TEST_CAP, (CCC_Bit[CYCLES_TEST_CAP]){}
CYCLES_TEST_CAP, (CCC_Tribool[CYCLES_TEST_CAP]){}
);
for (int i = 0; i < CYCLES_TEST_CAP; ++i) {
int const rand_i = (int)rand(); /* NOLINT */
Expand Down Expand Up @@ -210,7 +210,7 @@ check_static_begin(array_tree_map_test_insert_erase_cycles_allocate) {
);
int id_keys[CYCLES_TEST_CAP];
CCC_Flat_bitset repeats = CCC_flat_bitset_with_storage(
CYCLES_TEST_CAP, (CCC_Bit[CYCLES_TEST_CAP]){}
CYCLES_TEST_CAP, (CCC_Tribool[CYCLES_TEST_CAP]){}
);
for (int i = 0; i < CYCLES_TEST_CAP; ++i) {
int const rand_i = (int)rand(); /* NOLINT */
Expand Down
6 changes: 4 additions & 2 deletions tests/array_tree_map/test_array_tree_map_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ check_static_begin(array_tree_map_test_clear_with_destructor) {
CCC_Array_tree_map map = array_tree_map_with_storage(
id, (CCC_Key_comparator){.compare = id_order}, (struct Val[MIN_CAP]){}
);
Flat_bitset is_destroyed = flat_bitset_with_storage(0, (Bit[MIN_CAP]){});
Flat_bitset is_destroyed
= flat_bitset_with_storage(0, (CCC_Tribool[MIN_CAP]){});
int i = 0;
for (;;) {
CCC_Handle const *const e = array_tree_map_try_insert_with(
Expand Down Expand Up @@ -546,7 +547,8 @@ check_static_begin(array_tree_map_test_clear_and_free_with_destructor) {
allocator,
MIN_CAP
);
Flat_bitset is_destroyed = flat_bitset_with_storage(0, (Bit[MIN_CAP]){});
Flat_bitset is_destroyed
= flat_bitset_with_storage(0, (CCC_Tribool[MIN_CAP]){});
int i = 0;
for (;;) {
CCC_Handle const *const e = array_tree_map_try_insert_with(
Expand Down
3 changes: 2 additions & 1 deletion tests/doubly_linked_list/test_doubly_linked_list_iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ check_static_begin(doubly_linked_list_test_clear_with_destructor) {
CCC_doubly_linked_list_clear(&list, &(CCC_Destructor){}, NULL),
CCC_RESULT_ARGUMENT_ERROR
);
Flat_bitset is_destroyed = flat_bitset_with_storage(CAP, (Bit[CAP]){});
Flat_bitset is_destroyed
= flat_bitset_with_storage(CAP, (CCC_Tribool[CAP]){});
check(
CCC_doubly_linked_list_clear(
&list,
Expand Down
43 changes: 25 additions & 18 deletions tests/flat_bitset/test_flat_bitset_construct.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
typedef typeof(*(CCC_Flat_bitset){}.blocks) Bitblocks;

static CCC_Flat_bitset static_bitset
= CCC_flat_bitset_with_storage(32, (CCC_Bit[32]){});
= CCC_flat_bitset_with_storage(32, (CCC_Tribool[32]){});

check_static_begin(flat_bitset_test_static) {
check(CCC_flat_bitset_data(NULL), NULL);
Expand Down Expand Up @@ -37,7 +37,7 @@ check_static_begin(flat_bitset_test_static) {

check_static_begin(flat_bitset_test_construct) {
CCC_Flat_bitset bs = CCC_flat_bitset_for(
10, 10, CCC_flat_bitset_storage_for((CCC_Bit[10]){})
10, 10, CCC_flat_bitset_storage_for((CCC_Tribool[10]){})
);
check(CCC_flat_bitset_popcount(&bs).count, 0);
size_t i = 0;
Expand All @@ -50,7 +50,7 @@ check_static_begin(flat_bitset_test_construct) {
}

check_static_begin(flat_bitset_test_construct_with_literal) {
CCC_Flat_bitset bs = CCC_flat_bitset_with_storage(10, (CCC_Bit[10]){});
CCC_Flat_bitset bs = CCC_flat_bitset_with_storage(10, (CCC_Tribool[10]){});
check(CCC_flat_bitset_popcount(&bs).count, 0);
size_t i = 0;
for (; i < CCC_flat_bitset_count(&bs).count; ++i) {
Expand All @@ -63,7 +63,7 @@ check_static_begin(flat_bitset_test_construct_with_literal) {

check_static_begin(flat_bitset_test_construct_with_literal_full_block) {
CCC_Flat_bitset bs = CCC_flat_bitset_with_storage(
CCC_FLAT_BITSET_BLOCK_BITS, (CCC_Bit[CCC_FLAT_BITSET_BLOCK_BITS]){}
CCC_FLAT_BITSET_BLOCK_BITS, (CCC_Tribool[CCC_FLAT_BITSET_BLOCK_BITS]){}
);
check(CCC_flat_bitset_popcount(&bs).count, 0);
size_t i = 0;
Expand All @@ -76,7 +76,8 @@ check_static_begin(flat_bitset_test_construct_with_literal_full_block) {
}

check_static_begin(flat_bitset_test_copy_no_allocate) {
CCC_Flat_bitset source = CCC_flat_bitset_with_storage(0, (CCC_Bit[512]){});
CCC_Flat_bitset source
= CCC_flat_bitset_with_storage(0, (CCC_Tribool[512]){});
check(CCC_flat_bitset_capacity(&source).count, 512);
check(CCC_flat_bitset_count(&source).count, 0);
CCC_Result push_status = CCC_RESULT_OK;
Expand All @@ -93,7 +94,7 @@ check_static_begin(flat_bitset_test_copy_no_allocate) {
}
check(push_status, CCC_RESULT_NO_ALLOCATION_FUNCTION);
CCC_Flat_bitset destination
= CCC_flat_bitset_with_storage(0, (CCC_Bit[513]){});
= CCC_flat_bitset_with_storage(0, (CCC_Tribool[513]){});
check(
CCC_flat_bitset_copy(NULL, &source, &(CCC_Allocator){}),
CCC_RESULT_ARGUMENT_ERROR
Expand Down Expand Up @@ -146,8 +147,9 @@ check_static_begin(flat_bitset_test_copy_no_allocate) {
check_static_begin(flat_bitset_test_copy_allocate) {
CCC_Allocator const allocator = {
.allocate = stack_allocator_allocate,
.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[1024]){})),
.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[1024]){})
),
};
CCC_Flat_bitset source = CCC_flat_bitset_with_capacity(allocator, 512, 0);
for (size_t i = 0; i < 512; ++i) {
Expand Down Expand Up @@ -197,17 +199,19 @@ check_static_begin(flat_bitset_test_copy_allocate) {
check_static_begin(flat_bitset_test_copy_exhaustion) {
CCC_Allocator allocator = {
.allocate = stack_allocator_allocate,
.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[512]){})),
.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[512]){})
),
};
CCC_Flat_bitset source = CCC_flat_bitset_with_capacity(allocator, 512, 0);
CCC_Flat_bitset destination = CCC_flat_bitset_default();
check(
CCC_flat_bitset_copy(&destination, &source, &allocator),
CCC_RESULT_ALLOCATOR_ERROR
);
allocator.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[1024]){}));
allocator.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[1024]){})
);
source.blocks = NULL;
check(
CCC_flat_bitset_copy(&destination, &source, &allocator),
Expand All @@ -220,8 +224,9 @@ check_static_begin(flat_bitset_test_init_from) {
SV_Str_view const input = SV_from("110110");
CCC_Allocator const allocator = {
.allocate = stack_allocator_allocate,
.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[256]){})),
.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[256]){})
),
};
CCC_Flat_bitset b = CCC_flat_bitset_from(
allocator, 0, SV_len(input), '1', SV_begin(input)
Expand All @@ -238,8 +243,9 @@ check_static_begin(flat_bitset_test_init_from_cap) {
SV_Str_view input = SV_from("110110");
CCC_Allocator const allocator = {
.allocate = stack_allocator_allocate,
.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[256]){})),
.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[256]){})
),
};
CCC_Flat_bitset b = CCC_flat_bitset_from(
allocator, 0, SV_len(input), '1', SV_begin(input), SV_len(input) * 2
Expand Down Expand Up @@ -287,8 +293,9 @@ check_static_begin(flat_bitset_test_init_from_cap_fail) {
check_static_begin(flat_bitset_test_init_with_capacity) {
CCC_Allocator const allocator = {
.allocate = stack_allocator_allocate,
.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[10]){})),
.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[10]){})
),
};
CCC_Flat_bitset b = CCC_flat_bitset_with_capacity(allocator, 10);
check(CCC_flat_bitset_popcount(&b).count, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/flat_bitset/test_flat_bitset_erase.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

check_static_begin(flat_bitset_test_push_pop_back_no_reallocate) {
CCC_Flat_bitset bs = CCC_flat_bitset_for(
16, 0, CCC_flat_bitset_storage_for((CCC_Bit[16]){})
16, 0, CCC_flat_bitset_storage_for((CCC_Tribool[16]){})
);
check(CCC_flat_bitset_capacity(&bs).count, 16);
check(CCC_flat_bitset_count(&bs).count, 0);
Expand Down
7 changes: 4 additions & 3 deletions tests/flat_bitset/test_flat_bitset_insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ check_static_begin(flat_bitset_test_push_back_no_reallocate) {
CCC_RESULT_ARGUMENT_ERROR
);
CCC_Flat_bitset bs = CCC_flat_bitset_for(
16, 0, CCC_flat_bitset_storage_for((CCC_Bit[16]){})
16, 0, CCC_flat_bitset_storage_for((CCC_Tribool[16]){})
);
check(
CCC_flat_bitset_push_back(&bs, CCC_TRIBOOL_ERROR, &(CCC_Allocator){}),
Expand Down Expand Up @@ -114,8 +114,9 @@ check_static_begin(flat_bitset_test_push_back_reserve) {
check_static_begin(flat_bitset_test_reserve_fail) {
CCC_Allocator const allocator = {
.allocate = stack_allocator_allocate,
.context
= &stack_allocator_for(CCC_flat_bitset_storage_for((CCC_Bit[32]){})),
.context = &stack_allocator_for(
CCC_flat_bitset_storage_for((CCC_Tribool[32]){})
),
};
CCC_Flat_bitset bs = CCC_flat_bitset_default();
check(
Expand Down
Loading
Loading