C Container Collection (CCC)
Loading...
Searching...
No Matches
bitset.h
Go to the documentation of this file.
1
51#ifndef CCC_BITSET
52#define CCC_BITSET
53
55#include <stddef.h>
56#include <stdint.h>
59#include "impl/impl_bitset.h"
60#include "types.h"
61
73typedef struct ccc_bitset ccc_bitset;
74
82
115#define ccc_bs_blocks(bit_cap) ccc_impl_bs_blocks(bit_cap)
116
155#define ccc_bs_init(bitblock_ptr, alloc_fn, aux, cap, optional_size...) \
156 ccc_impl_bs_init(bitblock_ptr, alloc_fn, aux, cap, optional_size)
157
219 ccc_any_alloc_fn *fn);
220
239
251ccc_tribool ccc_bs_test(ccc_bitset const *bs, size_t i);
252
268
275
289ccc_result ccc_bs_set_range(ccc_bitset *bs, size_t i, size_t count,
290 ccc_tribool b);
291
300
306
319ccc_result ccc_bs_reset_range(ccc_bitset *bs, size_t i, size_t count);
320
329
335
347ccc_result ccc_bs_flip_range(ccc_bitset *bs, size_t i, size_t count);
348
360
368ccc_tribool ccc_bs_any_range(ccc_bitset const *bs, size_t i, size_t count);
369
375
383ccc_tribool ccc_bs_none_range(ccc_bitset const *bs, size_t i, size_t count);
384
390
398ccc_tribool ccc_bs_all_range(ccc_bitset const *bs, size_t i, size_t count);
399
406
416 size_t count);
417
427
439 size_t count, size_t num_ones);
440
446
455 size_t count);
456
466
477 size_t count, size_t num_zeros);
478
485
498 size_t count);
499
511
523 size_t count, size_t num_ones);
524
531
540 size_t count);
541
551
563 size_t count, size_t num_zeros);
564
583
601
614
624ccc_result ccc_bs_shiftl(ccc_bitset *bs, size_t left_shifts);
625
635ccc_result ccc_bs_shiftr(ccc_bitset *bs, size_t right_shifts);
636
644
662 ccc_bitset const *subset);
663
674
689
695
702
710
718
726
732
740ccc_ucount ccc_bs_popcount_range(ccc_bitset const *bs, size_t i, size_t count);
741
753
761
786
800
806
811#ifdef BITSET_USING_NAMESPACE_CCC
812typedef ccc_bitset bitset;
813typedef ccc_bitblock bitblock;
814# define bs_blocks(args...) ccc_bs_blocks(args)
815# define bs_init(args...) ccc_bs_init(args)
816# define bs_copy(args...) ccc_bs_copy(args)
817# define bs_reserve(args...) ccc_bs_reserve(args)
818# define bs_test(args...) ccc_bs_test(args)
819# define bs_set(args...) ccc_bs_set(args)
820# define bs_set_all(args...) ccc_bs_set_all(args)
821# define bs_set_range(args...) ccc_bs_set_range(args)
822# define bs_reset(args...) ccc_bs_reset(args)
823# define bs_reset_all(args...) ccc_bs_reset_all(args)
824# define bs_reset_range(args...) ccc_bs_reset_range(args)
825# define bs_flip(args...) ccc_bs_flip(args)
826# define bs_flip_all(args...) ccc_bs_flip_all(args)
827# define bs_flip_range(args...) ccc_bs_flip_range(args)
828# define bs_any(args...) ccc_bs_any(args)
829# define bs_any_range(args...) ccc_bs_any_range(args)
830# define bs_none(args...) ccc_bs_none(args)
831# define bs_none_range(args...) ccc_bs_none_range(args)
832# define bs_all(args...) ccc_bs_all(args)
833# define bs_all_range(args...) ccc_bs_all_range(args)
834# define bs_first_trailing_one(args...) ccc_bs_first_trailing_one(args)
835# define bs_first_trailing_one_range(args...) \
836 ccc_bs_first_trailing_one_range(args)
837# define bs_first_trailing_ones(args...) ccc_bs_first_trailing_ones(args)
838# define bs_first_trailing_ones_range(args...) \
839 ccc_bs_first_trailing_ones_range(args)
840# define bs_first_trailing_zero(args...) ccc_bs_first_trailing_zero(args)
841# define bs_first_trailing_zero_range(args...) \
842 ccc_bs_first_trailing_zero_range(args)
843# define bs_first_trailing_zeros(args...) ccc_bs_first_trailing_zeros(args)
844# define bs_first_trailing_zeros_range(args...) \
845 ccc_bs_first_trailing_zeros_range(args)
846# define bs_first_leading_one(args...) ccc_bs_first_leading_one(args)
847# define bs_first_leading_one_range(args...) \
848 ccc_bs_first_leading_one_range(args)
849# define bs_first_leading_ones(args...) ccc_bs_first_leading_ones(args)
850# define bs_first_leading_ones_range(args...) \
851 ccc_bs_first_leading_ones_range(args)
852# define bs_first_leading_zero(args...) ccc_bs_first_leading_zero(args)
853# define bs_first_leading_zero_range(args...) \
854 ccc_bs_first_leading_zero_range(args)
855# define bs_first_leading_zeros(args...) ccc_bs_first_leading_zeros(args)
856# define bs_first_leading_zeros_range(args...) \
857 ccc_bs_first_leading_zeros_range(args)
858# define bs_or(args...) ccc_bs_or(args)
859# define bs_and(args...) ccc_bs_and(args)
860# define bs_xor(args...) ccc_bs_xor(args)
861# define bs_shiftl(args...) ccc_bs_shiftl(args)
862# define bs_shiftr(args...) ccc_bs_shiftr(args)
863# define bs_eq(args...) ccc_bs_eq(args)
864# define bs_is_proper_subset(args...) ccc_bs_is_proper_subset(args)
865# define bs_is_subset(args...) ccc_bs_is_subset(args)
866# define bs_data(args...) ccc_bs_data(args)
867# define bs_capacity(args...) ccc_bs_capacity(args)
868# define bs_blocks_capacity(args...) ccc_bs_blocks_capacity(args)
869# define bs_size(args...) ccc_bs_size(args)
870# define bs_blocks_size(args...) ccc_bs_blocks_size(args)
871# define bs_empty(args...) ccc_bs_empty(args)
872# define bs_popcount(args...) ccc_bs_popcount(args)
873# define bs_popcount_range(args...) ccc_bs_popcount_range(args)
874# define bs_clear(args...) ccc_bs_clear(args)
875# define bs_clear_and_free(args...) ccc_bs_clear_and_free(args)
876# define bs_clear_and_free_reserve(args...) \
877 ccc_bs_clear_and_free_reserve(args)
878# define bs_push_back(args...) ccc_bs_push_back(args)
879# define bs_pop_back(args...) ccc_bs_pop_back(args)
880#endif /* BITSET_USING_NAMESPACE_CCC */
881
882#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_bitblock ccc_bitblock
The type used to efficiently store bits in the bit set.
Definition: bitset.h:81
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_result ccc_bs_clear_and_free_reserve(ccc_bitset *bs, ccc_any_alloc_fn *fn)
Frees the buffer for the bit set that was previously dynamically reserved with the reserve function.
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.
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
ccc_result ccc_bs_reserve(ccc_bitset *bs, size_t to_add, ccc_any_alloc_fn *fn)
Reserves space for at least to_add more 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_result ccc_bs_copy(ccc_bitset *dst, ccc_bitset const *src, ccc_any_alloc_fn *fn)
Copy the bit set at source to destination.
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_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:187
The C Container Collection Fundamental Types.
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
ccc_result
A result of actions on containers.
Definition: types.h:132
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:117