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
181#define CCC_bitset_initialize(allocate, context, cap, count, \
182 bitblock_pointer...) \
183 CCC_private_bitset_initialize(allocate, context, cap, count, \
184 bitblock_pointer)
185
223#define CCC_bitset_from(allocate, context, start_string_index, count, \
224 bit_on_char, input_string, optional_capacity...) \
225 CCC_private_bitset_from(allocate, context, start_string_index, count, \
226 bit_on_char, input_string, optional_capacity)
227
261#define CCC_bitset_with_capacity(allocate, context, capacity, \
262 optional_count...) \
263 CCC_private_bitset_with_capacity(allocate, context, capacity, \
264 optional_count)
265
289#define CCC_bitset_with_compound_literal(count, compound_literal_array) \
290 CCC_private_bitset_with_compound_literal(count, compound_literal_array)
291
316#define CCC_bitset_with_context_compound_literal(context, count, \
317 compound_literal_array) \
318 CCC_private_bitset_with_context_compound_literal(context, count, \
319 compound_literal_array)
320
334#define CCC_bitset_with_allocator(allocator) \
335 CCC_private_bitset_with_allocator(allocator)
336
351#define CCC_bitset_with_context_allocator(allocator, context) \
352 CCC_private_bitset_with_context_allocator(allocator, context)
353
447
467
480CCC_Tribool CCC_bitset_test(CCC_Bitset const *bitset, size_t index);
481
496
503
517CCC_Result CCC_bitset_set_range(CCC_Bitset *bitset, size_t range_start_index,
518 size_t range_bit_count, CCC_Tribool bit);
519
527
533
545CCC_Result CCC_bitset_reset_range(CCC_Bitset *bitset, size_t range_start_index,
546 size_t range_bit_count);
547
555
561
573CCC_Result CCC_bitset_flip_range(CCC_Bitset *bitset, size_t range_start_index,
574 size_t range_bit_count);
575
587
596 size_t range_start_index,
597 size_t range_bit_count);
598
604
613 size_t range_start_index,
614 size_t range_bit_count);
615
621
631 size_t range_start_index,
632 size_t range_bit_count);
633
640
650 size_t range_start_index,
651 size_t range_bit_count);
652
662 size_t ones_count);
663
674 size_t range_start_index,
675 size_t range_bit_count,
676 size_t ones_count);
677
684
694 size_t range_start_index,
695 size_t range_bit_count);
696
706 size_t zeros_count);
707
718 size_t range_start_index,
719 size_t range_bit_count,
720 size_t zeros_count);
721
728
737 size_t index, size_t count);
738
749 size_t ones_count);
750
763 size_t range_start_index,
764 size_t range_bit_count,
765 size_t ones_count);
766
774
785 size_t range_start_index,
786 size_t range_bit_count);
787
798 size_t zeros_count);
799
812 size_t range_start_index,
813 size_t range_bit_count,
814 size_t zeros_count);
815
833CCC_Result CCC_bitset_or(CCC_Bitset *destination, CCC_Bitset const *source);
834
851CCC_Result CCC_bitset_and(CCC_Bitset *destination, CCC_Bitset const *source);
852
864CCC_Result CCC_bitset_xor(CCC_Bitset *destination, CCC_Bitset const *source);
865
875CCC_Result CCC_bitset_shift_left(CCC_Bitset *bitset, size_t left_shifts);
876
886CCC_Result CCC_bitset_shift_right(CCC_Bitset *bitset, size_t right_shifts);
887
895 CCC_Bitset const *right);
896
914 CCC_Bitset const *set);
915
926 CCC_Bitset const *set);
927
941void *CCC_bitset_data(CCC_Bitset const *bitset);
942
948
955
963
971
979
985
994 size_t range_start_index,
995 size_t range_bit_count);
996
1008
1016
1043
1057
1063
1068#ifdef BITSET_USING_NAMESPACE_CCC
1069typedef CCC_Bitset Bitset;
1070# define BITSET_BLOCK_BITS CCC_BITSET_BLOCK_BITS
1071# define bitset_block_count(arguments...) CCC_bitset_block_count(arguments)
1072# define bitset_block_bytes(arguments...) CCC_bitset_block_bytes(arguments)
1073# define bitset_blocks(arguments...) CCC_bitset_blocks(arguments)
1074# define bitset_initialize(arguments...) CCC_bitset_initialize(arguments)
1075# define bitset_from(arguments...) CCC_bitset_from(arguments)
1076# define bitset_with_capacity(arguments...) \
1077 CCC_bitset_with_capacity(arguments)
1078# define bitset_with_compound_literal(arguments...) \
1079 CCC_bitset_with_compound_literal(arguments)
1080# define bitset_with_context_compound_literal(arguments...) \
1081 CCC_bitset_with_context_compound_literal(arguments)
1082# define bitset_with_allocator(arguments...) \
1083 CCC_bitset_with_allocator(arguments)
1084# define bitset_with_context_allocator(arguments...) \
1085 CCC_bitset_with_context_allocator(arguments)
1086# define bitset_copy(arguments...) CCC_bitset_copy(arguments)
1087# define bitset_reserve(arguments...) CCC_bitset_reserve(arguments)
1088# define bitset_test(arguments...) CCC_bitset_test(arguments)
1089# define bitset_set(arguments...) CCC_bitset_set(arguments)
1090# define bitset_set_all(arguments...) CCC_bitset_set_all(arguments)
1091# define bitset_set_range(arguments...) CCC_bitset_set_range(arguments)
1092# define bitset_reset(arguments...) CCC_bitset_reset(arguments)
1093# define bitset_reset_all(arguments...) CCC_bitset_reset_all(arguments)
1094# define bitset_reset_range(arguments...) CCC_bitset_reset_range(arguments)
1095# define bitset_flip(arguments...) CCC_bitset_flip(arguments)
1096# define bitset_flip_all(arguments...) CCC_bitset_flip_all(arguments)
1097# define bitset_flip_range(arguments...) CCC_bitset_flip_range(arguments)
1098# define bitset_any(arguments...) CCC_bitset_any(arguments)
1099# define bitset_any_range(arguments...) CCC_bitset_any_range(arguments)
1100# define bitset_none(arguments...) CCC_bitset_none(arguments)
1101# define bitset_none_range(arguments...) CCC_bitset_none_range(arguments)
1102# define bitset_all(arguments...) CCC_bitset_all(arguments)
1103# define bitset_all_range(arguments...) CCC_bitset_all_range(arguments)
1104# define bitset_first_trailing_one(arguments...) \
1105 CCC_bitset_first_trailing_one(arguments)
1106# define bitset_first_trailing_one_range(arguments...) \
1107 CCC_bitset_first_trailing_one_range(arguments)
1108# define bitset_first_trailing_ones(arguments...) \
1109 CCC_bitset_first_trailing_ones(arguments)
1110# define bitset_first_trailing_ones_range(arguments...) \
1111 CCC_bitset_first_trailing_ones_range(arguments)
1112# define bitset_first_trailing_zero(arguments...) \
1113 CCC_bitset_first_trailing_zero(arguments)
1114# define bitset_first_trailing_zero_range(arguments...) \
1115 CCC_bitset_first_trailing_zero_range(arguments)
1116# define bitset_first_trailing_zeros(arguments...) \
1117 CCC_bitset_first_trailing_zeros(arguments)
1118# define bitset_first_trailing_zeros_range(arguments...) \
1119 CCC_bitset_first_trailing_zeros_range(arguments)
1120# define bitset_first_leading_one(arguments...) \
1121 CCC_bitset_first_leading_one(arguments)
1122# define bitset_first_leading_one_range(arguments...) \
1123 CCC_bitset_first_leading_one_range(arguments)
1124# define bitset_first_leading_ones(arguments...) \
1125 CCC_bitset_first_leading_ones(arguments)
1126# define bitset_first_leading_ones_range(arguments...) \
1127 CCC_bitset_first_leading_ones_range(arguments)
1128# define bitset_first_leading_zero(arguments...) \
1129 CCC_bitset_first_leading_zero(arguments)
1130# define bitset_first_leading_zero_range(arguments...) \
1131 CCC_bitset_first_leading_zero_range(arguments)
1132# define bitset_first_leading_zeros(arguments...) \
1133 CCC_bitset_first_leading_zeros(arguments)
1134# define bitset_first_leading_zeros_range(arguments...) \
1135 CCC_bitset_first_leading_zeros_range(arguments)
1136# define bitset_or(arguments...) CCC_bitset_or(arguments)
1137# define bitset_and(arguments...) CCC_bitset_and(arguments)
1138# define bitset_xor(arguments...) CCC_bitset_xor(arguments)
1139# define bitset_shift_left(arguments...) CCC_bitset_shift_left(arguments)
1140# define bitset_shift_right(arguments...) CCC_bitset_shift_right(arguments)
1141# define bitset_is_equal(arguments...) CCC_bitset_is_equal(arguments)
1142# define bitset_is_proper_subset(arguments...) \
1143 CCC_bitset_is_proper_subset(arguments)
1144# define bitset_is_subset(arguments...) CCC_bitset_is_subset(arguments)
1145# define bitset_data(arguments...) CCC_bitset_data(arguments)
1146# define bitset_capacity(arguments...) CCC_bitset_capacity(arguments)
1147# define bitset_blocks_capacity(arguments...) \
1148 CCC_bitset_blocks_capacity(arguments)
1149# define bitset_count(arguments...) CCC_bitset_count(arguments)
1150# define bitset_blocks_count(arguments...) CCC_bitset_blocks_count(arguments)
1151# define bitset_is_empty(arguments...) CCC_bitset_is_empty(arguments)
1152# define bitset_popcount(arguments...) CCC_bitset_popcount(arguments)
1153# define bitset_popcount_range(arguments...) \
1154 CCC_bitset_popcount_range(arguments)
1155# define bitset_clear(arguments...) CCC_bitset_clear(arguments)
1156# define bitset_clear_and_free(arguments...) \
1157 CCC_bitset_clear_and_free(arguments)
1158# define bitset_clear_and_free_reserve(arguments...) \
1159 CCC_bitset_clear_and_free_reserve(arguments)
1160# define bitset_push_back(arguments...) CCC_bitset_push_back(arguments)
1161# define bitset_pop_back(arguments...) CCC_bitset_pop_back(arguments)
1162#endif /* BITSET_USING_NAMESPACE_CCC */
1163
1164#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