C Container Collection (CCC)
Loading...
Searching...
No Matches
bitset.h
Go to the documentation of this file.
1
59#ifndef CCC_BITSET_H
60#define CCC_BITSET_H
61
63#include <stddef.h>
64#include <stdint.h>
67#include "private/private_bitset.h"
68#include "types.h"
69
81typedef struct CCC_Bitset CCC_Bitset;
82
89enum : size_t
90{
92 CCC_BITSET_BLOCK_BITS = CCC_PRIVATE_BITSET_BLOCK_BITS,
93};
94
99#define CCC_bitset_block_count(bit_cap) CCC_private_bitset_block_count(bit_cap)
100
105#define CCC_bitset_block_bytes(bit_cap) CCC_private_bitset_block_bytes(bit_cap)
106
144#define CCC_bitset_blocks(bit_cap, optional_storage_duration...) \
145 CCC_private_bitset_blocks(bit_cap, optional_storage_duration)
146
185#define CCC_bitset_initialize(bitblock_pointer, allocate, context, cap, \
186 optional_count...) \
187 CCC_private_bitset_initialize(bitblock_pointer, allocate, context, cap, \
188 optional_count)
189
227#define CCC_bitset_from(allocate, context, start_string_index, count, \
228 bit_on_char, input_string, optional_capacity...) \
229 CCC_private_bitset_from(allocate, context, start_string_index, count, \
230 bit_on_char, input_string, optional_capacity)
231
265#define CCC_bitset_with_capacity(allocate, context, capacity, \
266 optional_count...) \
267 CCC_private_bitset_with_capacity(allocate, context, capacity, \
268 optional_count)
269
293#define CCC_bitset_with_compound_literal(count, compound_literal_array) \
294 CCC_private_bitset_with_compound_literal(count, compound_literal_array)
295
320#define CCC_bitset_with_context_compound_literal(count, \
321 compound_literal_array) \
322 CCC_private_bitset_with_context_compound_literal(count, \
323 compound_literal_array)
324
418
438
451CCC_Tribool CCC_bitset_test(CCC_Bitset const *bitset, size_t index);
452
467
474
488CCC_Result CCC_bitset_set_range(CCC_Bitset *bitset, size_t range_start_index,
489 size_t range_bit_count, CCC_Tribool bit);
490
498
504
516CCC_Result CCC_bitset_reset_range(CCC_Bitset *bitset, size_t range_start_index,
517 size_t range_bit_count);
518
526
532
544CCC_Result CCC_bitset_flip_range(CCC_Bitset *bitset, size_t range_start_index,
545 size_t range_bit_count);
546
558
567 size_t range_start_index,
568 size_t range_bit_count);
569
575
584 size_t range_start_index,
585 size_t range_bit_count);
586
592
602 size_t range_start_index,
603 size_t range_bit_count);
604
611
621 size_t range_start_index,
622 size_t range_bit_count);
623
633 size_t ones_count);
634
645 size_t range_start_index,
646 size_t range_bit_count,
647 size_t ones_count);
648
655
665 size_t range_start_index,
666 size_t range_bit_count);
667
677 size_t zeros_count);
678
689 size_t range_start_index,
690 size_t range_bit_count,
691 size_t zeros_count);
692
699
708 size_t index, size_t count);
709
720 size_t ones_count);
721
734 size_t range_start_index,
735 size_t range_bit_count,
736 size_t ones_count);
737
745
756 size_t range_start_index,
757 size_t range_bit_count);
758
769 size_t zeros_count);
770
783 size_t range_start_index,
784 size_t range_bit_count,
785 size_t zeros_count);
786
804CCC_Result CCC_bitset_or(CCC_Bitset *destination, CCC_Bitset const *source);
805
822CCC_Result CCC_bitset_and(CCC_Bitset *destination, CCC_Bitset const *source);
823
835CCC_Result CCC_bitset_xor(CCC_Bitset *destination, CCC_Bitset const *source);
836
846CCC_Result CCC_bitset_shift_left(CCC_Bitset *bitset, size_t left_shifts);
847
857CCC_Result CCC_bitset_shift_right(CCC_Bitset *bitset, size_t right_shifts);
858
866 CCC_Bitset const *right);
867
885 CCC_Bitset const *set);
886
897 CCC_Bitset const *set);
898
912void *CCC_bitset_data(CCC_Bitset const *bitset);
913
919
926
934
942
950
956
965 size_t range_start_index,
966 size_t range_bit_count);
967
979
987
1014
1028
1034
1039#ifdef BITSET_USING_NAMESPACE_CCC
1040typedef CCC_Bitset Bitset;
1041# define BITSET_BLOCK_BITS CCC_BITSET_BLOCK_BITS
1042# define bitset_block_count(args...) CCC_bitset_block_count(args)
1043# define bitset_block_bytes(args...) CCC_bitset_block_bytes(args)
1044# define bitset_blocks(args...) CCC_bitset_blocks(args)
1045# define bitset_initialize(args...) CCC_bitset_initialize(args)
1046# define bitset_from(args...) CCC_bitset_from(args)
1047# define bitset_with_capacity(args...) CCC_bitset_with_capacity(args)
1048# define bitset_with_compound_literal(args...) \
1049 CCC_bitset_with_compound_literal(args)
1050# define bitset_with_context_compound_literal(args...) \
1051 CCC_bitset_with_context_compound_literal(args)
1052# define bitset_copy(args...) CCC_bitset_copy(args)
1053# define bitset_reserve(args...) CCC_bitset_reserve(args)
1054# define bitset_test(args...) CCC_bitset_test(args)
1055# define bitset_set(args...) CCC_bitset_set(args)
1056# define bitset_set_all(args...) CCC_bitset_set_all(args)
1057# define bitset_set_range(args...) CCC_bitset_set_range(args)
1058# define bitset_reset(args...) CCC_bitset_reset(args)
1059# define bitset_reset_all(args...) CCC_bitset_reset_all(args)
1060# define bitset_reset_range(args...) CCC_bitset_reset_range(args)
1061# define bitset_flip(args...) CCC_bitset_flip(args)
1062# define bitset_flip_all(args...) CCC_bitset_flip_all(args)
1063# define bitset_flip_range(args...) CCC_bitset_flip_range(args)
1064# define bitset_any(args...) CCC_bitset_any(args)
1065# define bitset_any_range(args...) CCC_bitset_any_range(args)
1066# define bitset_none(args...) CCC_bitset_none(args)
1067# define bitset_none_range(args...) CCC_bitset_none_range(args)
1068# define bitset_all(args...) CCC_bitset_all(args)
1069# define bitset_all_range(args...) CCC_bitset_all_range(args)
1070# define bitset_first_trailing_one(args...) \
1071 CCC_bitset_first_trailing_one(args)
1072# define bitset_first_trailing_one_range(args...) \
1073 CCC_bitset_first_trailing_one_range(args)
1074# define bitset_first_trailing_ones(args...) \
1075 CCC_bitset_first_trailing_ones(args)
1076# define bitset_first_trailing_ones_range(args...) \
1077 CCC_bitset_first_trailing_ones_range(args)
1078# define bitset_first_trailing_zero(args...) \
1079 CCC_bitset_first_trailing_zero(args)
1080# define bitset_first_trailing_zero_range(args...) \
1081 CCC_bitset_first_trailing_zero_range(args)
1082# define bitset_first_trailing_zeros(args...) \
1083 CCC_bitset_first_trailing_zeros(args)
1084# define bitset_first_trailing_zeros_range(args...) \
1085 CCC_bitset_first_trailing_zeros_range(args)
1086# define bitset_first_leading_one(args...) CCC_bitset_first_leading_one(args)
1087# define bitset_first_leading_one_range(args...) \
1088 CCC_bitset_first_leading_one_range(args)
1089# define bitset_first_leading_ones(args...) \
1090 CCC_bitset_first_leading_ones(args)
1091# define bitset_first_leading_ones_range(args...) \
1092 CCC_bitset_first_leading_ones_range(args)
1093# define bitset_first_leading_zero(args...) \
1094 CCC_bitset_first_leading_zero(args)
1095# define bitset_first_leading_zero_range(args...) \
1096 CCC_bitset_first_leading_zero_range(args)
1097# define bitset_first_leading_zeros(args...) \
1098 CCC_bitset_first_leading_zeros(args)
1099# define bitset_first_leading_zeros_range(args...) \
1100 CCC_bitset_first_leading_zeros_range(args)
1101# define bitset_or(args...) CCC_bitset_or(args)
1102# define bitset_and(args...) CCC_bitset_and(args)
1103# define bitset_xor(args...) CCC_bitset_xor(args)
1104# define bitset_shift_left(args...) CCC_bitset_shift_left(args)
1105# define bitset_shift_right(args...) CCC_bitset_shift_right(args)
1106# define bitset_is_equal(args...) CCC_bitset_is_equal(args)
1107# define bitset_is_proper_subset(args...) CCC_bitset_is_proper_subset(args)
1108# define bitset_is_subset(args...) CCC_bitset_is_subset(args)
1109# define bitset_data(args...) CCC_bitset_data(args)
1110# define bitset_capacity(args...) CCC_bitset_capacity(args)
1111# define bitset_blocks_capacity(args...) CCC_bitset_blocks_capacity(args)
1112# define bitset_count(args...) CCC_bitset_count(args)
1113# define bitset_blocks_count(args...) CCC_bitset_blocks_count(args)
1114# define bitset_is_empty(args...) CCC_bitset_is_empty(args)
1115# define bitset_popcount(args...) CCC_bitset_popcount(args)
1116# define bitset_popcount_range(args...) CCC_bitset_popcount_range(args)
1117# define bitset_clear(args...) CCC_bitset_clear(args)
1118# define bitset_clear_and_free(args...) CCC_bitset_clear_and_free(args)
1119# define bitset_clear_and_free_reserve(args...) \
1120 CCC_bitset_clear_and_free_reserve(args)
1121# define bitset_push_back(args...) CCC_bitset_push_back(args)
1122# define bitset_pop_back(args...) CCC_bitset_pop_back(args)
1123#endif /* BITSET_USING_NAMESPACE_CCC */
1124
1125#endif /* CCC_BITSET_H */
CCC_Result CCC_bitset_clear(CCC_Bitset *bitset)
Clears the bit set by setting the size to 0 and all bits to 0. The underlying memory capacity remains...
CCC_Tribool CCC_bitset_reset(CCC_Bitset *bitset, size_t index)
Set the bit at valid index index to boolean value b (true or false).
CCC_Tribool CCC_bitset_is_equal(CCC_Bitset const *left, CCC_Bitset const *right)
Checks two bit sets of the same size (not capacity) for equality.
CCC_Tribool CCC_bitset_test(CCC_Bitset const *bitset, size_t index)
Test the bit at index index for boolean status (CCC_TRUE or CCC_FALSE).
CCC_Count CCC_bitset_first_leading_zero(CCC_Bitset const *bitset)
Return the index of the first leading bit set to 0 in the set, starting from the Most Significant Bit...
CCC_Result CCC_bitset_reset_all(CCC_Bitset *bitset)
Set all the bits to CCC_FALSE.
CCC_Result CCC_bitset_xor(CCC_Bitset *destination, CCC_Bitset const *source)
Bitwise XOR destination set with source set.
CCC_Result CCC_bitset_copy(CCC_Bitset *destination, CCC_Bitset const *source, CCC_Allocator *allocate)
Copy the bit set at source to destination.
CCC_Result CCC_bitset_flip_all(CCC_Bitset *bitset)
Toggle all of the bits to their opposing boolean value.
CCC_Count CCC_bitset_count(CCC_Bitset const *bitset)
Return total number of bits actively tracked by the user and set.
CCC_Tribool CCC_bitset_is_proper_subset(CCC_Bitset const *subset, CCC_Bitset const *set)
Return CCC_TRUE if subset is a proper subset of set (subset ⊂ set).
CCC_Count CCC_bitset_blocks_count(CCC_Bitset const *bitset)
Return number of CCC_bitblocks used by the bit set for size bits.
CCC_Count CCC_bitset_first_leading_zeros(CCC_Bitset const *bitset, size_t zeros_count)
Returns the index of the start of the first leading number of contiguous 0 bits.
CCC_Count CCC_bitset_popcount(CCC_Bitset const *bitset)
Return the number of bits set to CCC_TRUE. O(n).
CCC_Count CCC_bitset_first_leading_one_range(CCC_Bitset const *bitset, size_t index, size_t count)
Return the index of the first leading bit set to 1 in the range [i, index + count).
CCC_Tribool CCC_bitset_pop_back(CCC_Bitset *bitset)
Remove the Most Significant Bit from the set.
CCC_Result CCC_bitset_and(CCC_Bitset *destination, CCC_Bitset const *source)
Bitwise AND destination set with source set.
CCC_Count CCC_bitset_first_trailing_zero(CCC_Bitset const *bitset)
Return the index of the first bit set to 0 in the set.
CCC_Result CCC_bitset_reserve(CCC_Bitset *bitset, size_t to_add, CCC_Allocator *allocate)
Reserves space for at least to_add more bits.
@ CCC_BITSET_BLOCK_BITS
The number of bits in a block of the bit set.
Definition: bitset.h:92
CCC_Tribool CCC_bitset_any(CCC_Bitset const *bitset)
Return true if any bits in set are 1.
CCC_Tribool CCC_bitset_all_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return true if all bits are set to 1 in the range [index, index + count).
CCC_Tribool CCC_bitset_all(CCC_Bitset const *bitset)
Return true if all bits in set are 1.
CCC_Tribool CCC_bitset_flip(CCC_Bitset *bitset, size_t index)
Toggle the bit at index i.
CCC_Count CCC_bitset_first_leading_one(CCC_Bitset const *bitset)
Return the index of the first leading bit set to 1 in the set, starting from the Most Significant Bit...
CCC_Count CCC_bitset_first_trailing_one(CCC_Bitset const *bitset)
Return the index of the first trailing bit set to 1 in the set.
CCC_Result CCC_bitset_flip_range(CCC_Bitset *bitset, size_t range_start_index, size_t range_bit_count)
Flip all the bits in the range, starting at the Least Significant Bit in range and ending at the Most...
CCC_Result CCC_bitset_clear_and_free_reserve(CCC_Bitset *bitset, CCC_Allocator *allocate)
Frees the Buffer for the bit set that was previously dynamically reserved with the reserve function.
CCC_Result CCC_bitset_push_back(CCC_Bitset *bitset, CCC_Tribool bit)
Append a bit value to the set as the new Most Significant Bit.
CCC_Tribool CCC_bitset_any_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return true if any bits are 1 in the range [index, index + count).
CCC_Result CCC_bitset_shift_right(CCC_Bitset *bitset, size_t right_shifts)
Shift the bit set right by right_shifts amount.
CCC_Count CCC_bitset_first_trailing_ones(CCC_Bitset const *bitset, size_t ones_count)
Returns the index of the start of the first trailing number of contiguous 1 bits.
CCC_Result CCC_bitset_set_all(CCC_Bitset *bitset, CCC_Tribool bit)
Set all the bits to the provided value (CCC_TRUE or CCC_FALSE).
CCC_Tribool CCC_bitset_set(CCC_Bitset *bitset, size_t index, CCC_Tribool bit)
Set the bit at valid index index to value bit (true or false).
CCC_Count CCC_bitset_first_leading_ones(CCC_Bitset const *bitset, size_t ones_count)
Returns the index of the start of the first leading bit_count contiguous 1 bits.
CCC_Count CCC_bitset_first_leading_zero_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return the index of the first leading bit set to 0 in the range [i, index + count).
CCC_Result CCC_bitset_reset_range(CCC_Bitset *bitset, size_t range_start_index, size_t range_bit_count)
Set all the bits in the specified range starting at the Least Significant Bit of the range and ending...
CCC_Count CCC_bitset_first_trailing_one_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return the index of the first trailing bit set to 1 in the range [i, index + count).
CCC_Count CCC_bitset_first_trailing_zero_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return the index of the first bit set to 0 in the range [i, index + count).
CCC_Count CCC_bitset_blocks_capacity(CCC_Bitset const *bitset)
Return number of CCC_bitblocks used by bit set for capacity bits.
CCC_Result CCC_bitset_set_range(CCC_Bitset *bitset, size_t range_start_index, size_t range_bit_count, CCC_Tribool bit)
Set all the bits in the specified range starting at the Least Significant Bit of the range and ending...
CCC_Count CCC_bitset_first_trailing_zeros(CCC_Bitset const *bitset, size_t zeros_count)
Returns the index of the start of the first trailing number of contiguous 0 bits in the set.
CCC_Result CCC_bitset_or(CCC_Bitset *destination, CCC_Bitset const *source)
Bitwise OR destination set with source set.
CCC_Tribool CCC_bitset_none(CCC_Bitset const *bitset)
Return true if all bits are set to 0.
CCC_Result CCC_bitset_shift_left(CCC_Bitset *bitset, size_t left_shifts)
Shift the bit set left by left_shifts amount.
CCC_Result CCC_bitset_clear_and_free(CCC_Bitset *bitset)
Clears the bit set by setting the size to 0 and freeing the underlying memory. Capacity becomes 0 as ...
CCC_Count CCC_bitset_first_trailing_zeros_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count, size_t zeros_count)
Returns the index of the start of the first trailing zeros_count contiguous 0 bits in the range [i,...
CCC_Tribool CCC_bitset_is_subset(CCC_Bitset const *subset, CCC_Bitset const *set)
Return CCC_TRUE if subset is a subset of set (subset ⊆ set).
CCC_Tribool CCC_bitset_none_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return true if all bits are 0 in the range [index, index + count).
CCC_Count CCC_bitset_first_leading_zeros_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count, size_t zeros_count)
Returns the index of the start of the first leading number of contiguous 0 bits in the range [i,...
void * CCC_bitset_data(CCC_Bitset const *bitset)
Return a reference to the base of the underlying block array.
CCC_Tribool CCC_bitset_is_empty(CCC_Bitset const *bitset)
Return true if no bits are actively tracked by the user and set.
CCC_Count CCC_bitset_capacity(CCC_Bitset const *bitset)
Return total number of bits the capacity of the set can hold.
CCC_Count CCC_bitset_popcount_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count)
Return the number of bits set to CCC_TRUE in the range. O(n).
CCC_Count CCC_bitset_first_leading_ones_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count, size_t ones_count)
Returns the index of the start of the first leading bit_count contiguous 1 bits in the range [i,...
CCC_Count CCC_bitset_first_trailing_ones_range(CCC_Bitset const *bitset, size_t range_start_index, size_t range_bit_count, size_t ones_count)
Returns the index of the start of the first trailing number of contiguous 1 bits in the range [index,...
Definition: private_bitset.h:33
CCC_Allocator * allocate
Definition: private_bitset.h:41
size_t count
Definition: private_bitset.h:37
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:202
The C Container Collection Fundamental Types.
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:133
CCC_Result
A result of actions on containers.
Definition: types.h:148
void * CCC_Allocator(CCC_Allocator_context)
An allocation function at the core of all containers.
Definition: types.h:340