C Container Collection (CCC)
Loading...
Searching...
No Matches
bitset.h
Go to the documentation of this file.
1
36#ifndef CCC_BITSET
37#define CCC_BITSET
38
40#include <stddef.h>
41#include <stdint.h>
44#include "impl/impl_bitset.h"
45#include "types.h"
46
59typedef struct ccc_bitset_ ccc_bitset;
60
67typedef ccc_bitblock_ ccc_bitblock;
68
101#define ccc_bs_blocks(bit_cap) ccc_impl_bs_blocks(bit_cap)
102
130#define ccc_bs_init(bitblock_ptr, alloc_fn, aux, cap, optional_size...) \
131 ccc_impl_bs_init(bitblock_ptr, alloc_fn, aux, cap, optional_size)
132
194 ccc_alloc_fn *fn);
195
207ccc_tribool ccc_bs_test(ccc_bitset const *bs, size_t i);
208
224
231
245ccc_result ccc_bs_set_range(ccc_bitset *bs, size_t i, size_t count,
246 ccc_tribool b);
247
256
262
275ccc_result ccc_bs_reset_range(ccc_bitset *bs, size_t i, size_t count);
276
285
291
303ccc_result ccc_bs_flip_range(ccc_bitset *bs, size_t i, size_t count);
304
316
324ccc_tribool ccc_bs_any_range(ccc_bitset const *bs, size_t i, size_t count);
325
331
339ccc_tribool ccc_bs_none_range(ccc_bitset const *bs, size_t i, size_t count);
340
346
354ccc_tribool ccc_bs_all_range(ccc_bitset const *bs, size_t i, size_t count);
355
362
372 size_t count);
373
383
395 size_t count, size_t num_ones);
396
402
411 size_t count);
412
422
433 size_t count, size_t num_zeros);
434
441
454 size_t count);
455
467
479 size_t count, size_t num_ones);
480
487
496 size_t count);
497
507
519 size_t count, size_t num_zeros);
520
539
557
570
580ccc_result ccc_bs_shiftl(ccc_bitset *bs, size_t left_shifts);
581
591ccc_result ccc_bs_shiftr(ccc_bitset *bs, size_t right_shifts);
592
600
618 ccc_bitset const *subset);
619
630
645
651
658
666
674
682
688
696ccc_ucount ccc_bs_popcount_range(ccc_bitset const *bs, size_t i, size_t count);
697
709
717
731
737
742#ifdef BITSET_USING_NAMESPACE_CCC
743typedef ccc_bitset bitset;
744typedef ccc_bitblock bitblock;
745# define bs_blocks(args...) ccc_bs_blocks(args)
746# define bs_init(args...) ccc_bs_init(args)
747# define bs_copy(args...) ccc_bs_copy(args)
748# define bs_test(args...) ccc_bs_test(args)
749# define bs_set(args...) ccc_bs_set(args)
750# define bs_set_all(args...) ccc_bs_set_all(args)
751# define bs_set_range(args...) ccc_bs_set_range(args)
752# define bs_reset(args...) ccc_bs_reset(args)
753# define bs_reset_all(args...) ccc_bs_reset_all(args)
754# define bs_reset_range(args...) ccc_bs_reset_range(args)
755# define bs_flip(args...) ccc_bs_flip(args)
756# define bs_flip_all(args...) ccc_bs_flip_all(args)
757# define bs_flip_range(args...) ccc_bs_flip_range(args)
758# define bs_any(args...) ccc_bs_any(args)
759# define bs_any_range(args...) ccc_bs_any_range(args)
760# define bs_none(args...) ccc_bs_none(args)
761# define bs_none_range(args...) ccc_bs_none_range(args)
762# define bs_all(args...) ccc_bs_all(args)
763# define bs_all_range(args...) ccc_bs_all_range(args)
764# define bs_first_trailing_one(args...) ccc_bs_first_trailing_one(args)
765# define bs_first_trailing_one_range(args...) \
766 ccc_bs_first_trailing_one_range(args)
767# define bs_first_trailing_ones(args...) ccc_bs_first_trailing_ones(args)
768# define bs_first_trailing_ones_range(args...) \
769 ccc_bs_first_trailing_ones_range(args)
770# define bs_first_trailing_zero(args...) ccc_bs_first_trailing_zero(args)
771# define bs_first_trailing_zero_range(args...) \
772 ccc_bs_first_trailing_zero_range(args)
773# define bs_first_trailing_zeros(args...) ccc_bs_first_trailing_zeros(args)
774# define bs_first_trailing_zeros_range(args...) \
775 ccc_bs_first_trailing_zeros_range(args)
776# define bs_first_leading_one(args...) ccc_bs_first_leading_one(args)
777# define bs_first_leading_one_range(args...) \
778 ccc_bs_first_leading_one_range(args)
779# define bs_first_leading_ones(args...) ccc_bs_first_leading_ones(args)
780# define bs_first_leading_ones_range(args...) \
781 ccc_bs_first_leading_ones_range(args)
782# define bs_first_leading_zero(args...) ccc_bs_first_leading_zero(args)
783# define bs_first_leading_zero_range(args...) \
784 ccc_bs_first_leading_zero_range(args)
785# define bs_first_leading_zeros(args...) ccc_bs_first_leading_zeros(args)
786# define bs_first_leading_zeros_range(args...) \
787 ccc_bs_first_leading_zeros_range(args)
788# define bs_or(args...) ccc_bs_or(args)
789# define bs_and(args...) ccc_bs_and(args)
790# define bs_xor(args...) ccc_bs_xor(args)
791# define bs_shiftl(args...) ccc_bs_shiftl(args)
792# define bs_shiftr(args...) ccc_bs_shiftr(args)
793# define bs_eq(args...) ccc_bs_eq(args)
794# define bs_is_proper_subset(args...) ccc_bs_is_proper_subset(args)
795# define bs_is_subset(args...) ccc_bs_is_subset(args)
796# define bs_data(args...) ccc_bs_data(args)
797# define bs_capacity(args...) ccc_bs_capacity(args)
798# define bs_blocks_capacity(args...) ccc_bs_blocks_capacity(args)
799# define bs_size(args...) ccc_bs_size(args)
800# define bs_blocks_size(args...) ccc_bs_blocks_size(args)
801# define bs_empty(args...) ccc_bs_empty(args)
802# define bs_popcount(args...) ccc_bs_popcount(args)
803# define bs_popcount_range(args...) ccc_bs_popcount_range(args)
804# define bs_clear(args...) ccc_bs_clear(args)
805# define bs_clear_and_free(args...) ccc_bs_clear_and_free(args)
806# define bs_push_back(args...) ccc_bs_push_back(args)
807# define bs_pop_back(args...) ccc_bs_pop_back(args)
808#endif /* BITSET_USING_NAMESPACE_CCC */
809
810#endif /* CCC_BITSET */
ccc_ucount ccc_bs_capacity(ccc_bitset const *bs)
Return total number of bits the capacity of the set can hold.
ccc_tribool ccc_bs_is_proper_subset(ccc_bitset const *set, ccc_bitset const *subset)
Return CCC_TRUE if subset is a proper subset of set (subset ⊂ set).
ccc_bitblock * ccc_bs_data(ccc_bitset const *bs)
Return a reference to the base of the underlying block array.
ccc_ucount ccc_bs_blocks_size(ccc_bitset const *bs)
Return number of ccc_bitblocks used by the bit set for size bits.
ccc_result ccc_bs_shiftr(ccc_bitset *bs, size_t right_shifts)
Shift the bit set right by right_shifts amount.
ccc_result ccc_bs_reset_range(ccc_bitset *bs, size_t i, size_t count)
Set all the bits in the specified range starting at the Least Significant Bit of the range and ending...
ccc_ucount ccc_bs_first_trailing_ones_range(ccc_bitset const *bs, size_t i, size_t count, size_t num_ones)
Returns the index of the start of the first trailing num_ones contiguous 1 bits in the specified rang...
ccc_result ccc_bs_set_all(ccc_bitset *bs, ccc_tribool b)
Set all the bits to the provided value (CCC_TRUE or CCC_FALSE).
ccc_result ccc_bs_clear(ccc_bitset *bs)
Clears the bit set by setting the size to 0 and all bits to 0. The underlying memory capacity remains...
ccc_ucount ccc_bs_first_trailing_zero(ccc_bitset const *bs)
Return the index of the first bit set to 0 in the set.
ccc_result ccc_bs_or(ccc_bitset *dst, ccc_bitset const *src)
Bitwise OR dst set with src set.
ccc_ucount ccc_bs_first_trailing_one(ccc_bitset const *bs)
Return the index of the first trailing bit set to 1 in the set.
ccc_result ccc_bs_push_back(ccc_bitset *bs, ccc_tribool b)
Append a bit value to the set as the new Most Significant Bit.
ccc_ucount ccc_bs_first_trailing_one_range(ccc_bitset const *bs, size_t i, size_t count)
Return the index of the first trailing bit set to 1 in the range, starting from the Least Significant...
ccc_ucount ccc_bs_first_trailing_ones(ccc_bitset const *bs, size_t num_ones)
Returns the index of the start of the first trailing num_ones contiguous 1 bits.
ccc_result ccc_bs_flip_all(ccc_bitset *bs)
Toggle all of the bits to their opposing boolean value.
ccc_result ccc_bs_flip_range(ccc_bitset *bs, size_t i, size_t count)
Flip all the bits in the range, starting at the Least Significant Bit in range and ending at the Most...
ccc_tribool ccc_bs_set(ccc_bitset *bs, size_t i, ccc_tribool b)
Set the bit at valid index i to value b (true or false).
ccc_tribool ccc_bs_any_range(ccc_bitset const *bs, size_t i, size_t count)
Return true if any bits are 1 in the specified range.
ccc_ucount ccc_bs_popcount_range(ccc_bitset const *bs, size_t i, size_t count)
Return the number of bits set to CCC_TRUE in the range. O(n).
ccc_ucount ccc_bs_first_leading_ones_range(ccc_bitset const *bs, size_t i, size_t count, size_t num_ones)
Returns the index of the start of the first leading num_ones contiguous 1 bits in the specified range...
ccc_tribool ccc_bs_all(ccc_bitset const *bs)
Return true if all bits in set are 1.
ccc_tribool ccc_bs_empty(ccc_bitset const *bs)
Return true if no bits are actively tracked by the user and set.
ccc_ucount ccc_bs_first_leading_zero(ccc_bitset const *bs)
Return the index of the first leading bit set to 0 in the set, starting from the Most Significant Bit...
ccc_ucount ccc_bs_first_leading_zeros_range(ccc_bitset const *bs, size_t i, size_t count, size_t num_zeros)
Returns the index of the start of the first leading num_zeros contiguous 0 bits in the specified rang...
ccc_tribool ccc_bs_any(ccc_bitset const *bs)
Return true if any bits in set are 1.
ccc_ucount ccc_bs_first_leading_one(ccc_bitset const *bs)
Return the index of the first leading bit set to 1 in the set, starting from the Most Significant Bit...
ccc_ucount ccc_bs_first_leading_zeros(ccc_bitset const *bs, size_t num_zeros)
Returns the index of the start of the first leading num_zeros contiguous 0 bits.
ccc_tribool ccc_bs_test(ccc_bitset const *bs, size_t i)
Test the bit at index i for boolean status (CCC_TRUE or CCC_FALSE).
ccc_ucount ccc_bs_first_trailing_zeros_range(ccc_bitset const *bs, size_t i, size_t count, size_t num_zeros)
Returns the index of the start of the first trailing num_zeros contiguous 0 bits in the specified ran...
ccc_result ccc_bs_clear_and_free(ccc_bitset *bs)
Clears the bit set by setting the size to 0 and freeing the underlying memory. Capacity becomes 0 as ...
ccc_ucount ccc_bs_first_trailing_zeros(ccc_bitset const *bs, size_t num_zeros)
Returns the index of the start of the first trailing num_zeros contiguous 0 bits.
ccc_ucount ccc_bs_first_leading_one_range(ccc_bitset const *bs, size_t i, size_t count)
Return the index of the first leading bit set to 1 in the set, starting from the Most Significant Bit...
ccc_bitblock_ ccc_bitblock
The type used to efficiently store bits in the bit set.
Definition: bitset.h:67
struct ccc_bitset_ ccc_bitset
The bit set type that may be stored and initialized on the stack, heap, or data segment at compile ti...
Definition: bitset.h:59
ccc_tribool ccc_bs_none(ccc_bitset const *bs)
Return true if all bits are set to 0.
ccc_result ccc_bs_and(ccc_bitset *dst, ccc_bitset const *src)
Bitwise AND dst set with src set.
ccc_ucount ccc_bs_size(ccc_bitset const *bs)
Return total number of bits actively tracked by the user and set.
ccc_tribool ccc_bs_none_range(ccc_bitset const *bs, size_t i, size_t count)
Return true if all bits are 0 in the specified range.
ccc_tribool ccc_bs_all_range(ccc_bitset const *bs, size_t i, size_t count)
Return true if all bits are set to 1 in the specified range.
ccc_tribool ccc_bs_reset(ccc_bitset *bs, size_t i)
Set the bit at valid index i to boolean value b (true or false).
ccc_result ccc_bs_xor(ccc_bitset *dst, ccc_bitset const *src)
Bitwise XOR dst set with src set.
ccc_result ccc_bs_set_range(ccc_bitset *bs, size_t i, size_t count, ccc_tribool b)
Set all the bits in the specified range starting at the Least Significant Bit of the range and ending...
ccc_result ccc_bs_copy(ccc_bitset *dst, ccc_bitset const *src, ccc_alloc_fn *fn)
Copy the bit set at source to destination.
ccc_ucount ccc_bs_first_leading_zero_range(ccc_bitset const *bs, size_t i, size_t count)
Return the index of the first leading bit set to 0 in the set, starting from the Most Significant Bit...
ccc_ucount ccc_bs_first_leading_ones(ccc_bitset const *bs, size_t num_ones)
Returns the index of the start of the first leading num_ones contiguous 1 bits.
ccc_ucount ccc_bs_first_trailing_zero_range(ccc_bitset const *bs, size_t i, size_t count)
Return the index of the first bit set to 0 in the range.
ccc_ucount ccc_bs_blocks_capacity(ccc_bitset const *bs)
Return number of ccc_bitblocks used by bit set for capacity bits.
ccc_result ccc_bs_reset_all(ccc_bitset *bs)
Set all the bits to CCC_FALSE.
ccc_tribool ccc_bs_eq(ccc_bitset const *a, ccc_bitset const *b)
Checks two bit sets of the same size (not capacity) for equality.
ccc_ucount ccc_bs_popcount(ccc_bitset const *bs)
Return the number of bits set to CCC_TRUE. O(n).
ccc_tribool ccc_bs_pop_back(ccc_bitset *bs)
Remove the Most Significant Bit from the set.
ccc_result ccc_bs_shiftl(ccc_bitset *bs, size_t left_shifts)
Shift the bit set left by left_shifts amount.
ccc_tribool ccc_bs_flip(ccc_bitset *bs, size_t i)
Toggle the bit at index i.
ccc_tribool ccc_bs_is_subset(ccc_bitset const *set, ccc_bitset const *subset)
Return CCC_TRUE if subset is a subset of set (subset ⊆ set).
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:172
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:117
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:102
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:283