Lely core libraries
2.3.4
|
Go to the documentation of this file.
36 #define INT_BIT (sizeof(int) * CHAR_BIT)
43 size =
MAX(0, (size + INT_BIT - 1) / INT_BIT);
45 unsigned int *bits = malloc(size *
sizeof(
unsigned int));
72 return set->
size * INT_BIT;
79 assert(set->
size >= 0);
81 size =
MAX(0, (size + INT_BIT - 1) / INT_BIT);
83 unsigned int *bits = realloc(set->
bits, size *
sizeof(
unsigned int));
92 for (
int i = set->
size; i < size; i++)
106 return (set->
bits[n / INT_BIT] >> (n & (INT_BIT - 1))) & 1u;
114 set->
bits[n / INT_BIT] |= 1u << (n & (INT_BIT - 1));
120 for (
int i = 0; i < set->
size; i++)
129 set->
bits[n / INT_BIT] &= ~(1u << (n & (INT_BIT - 1)));
135 for (
int i = 0; i < set->
size; i++)
142 for (
int i = 0; i < set->
size; i++)
149 const unsigned int *bits = set->
bits;
151 for (
int i = 0; i < set->
size; i++) {
152 unsigned int x = *bits++;
154 return offset + ffs(x);
163 const unsigned int *bits = set->
bits;
165 for (
int i = 0; i < set->
size; i++) {
166 unsigned int x = *bits++;
168 return offset + ffs(~x);
182 int size = set->
size - n / INT_BIT;
183 const unsigned int *bits = set->
bits + n / INT_BIT;
184 int offset = n & ~(INT_BIT - 1);
187 unsigned int x = *bits++;
194 return offset + ffs(x);
209 int size = set->
size - n / INT_BIT;
210 const unsigned int *bits = set->
bits + n / INT_BIT;
211 int offset = n & ~(INT_BIT - 1);
214 unsigned int x = *bits++;
217 x |= ~0u >> (INT_BIT - n);
221 return offset + ffs(~x);
228 #endif // !LELY_NO_MALLOC
int bitset_test(const struct bitset *set, int n)
Returns 1 if bit n in set is set, and 0 otherwise.
void bitset_clr(struct bitset *set, int n)
Clears bit n in set.
int bitset_ffs(const struct bitset *set)
Returns the index (starting from one) of the first set bit in set, or 0 if all bits are zero.
void bitset_set(struct bitset *set, int n)
Sets bit n in set.
void bitset_set_all(struct bitset *set)
Sets all bits in set.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
int bitset_fns(const struct bitset *set, int n)
Returns the index (starting from one) of the first set bit higher or equal to n in set,...
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
#define MAX(a, b)
Returns the maximum of a and b.
int size
The number of integers in bits.
void bitset_clr_all(struct bitset *set)
Clears all bits in set.
int bitset_resize(struct bitset *set, int size)
Resizes a bitset.
int bitset_init(struct bitset *set, int size)
Initializes a bitset.
void bitset_fini(struct bitset *set)
Finalizes a bitset.
int bitset_ffz(const struct bitset *set)
Returns the index (starting from one) of the first zero bit in set, or 0 if all bits are set.
int bitset_fnz(const struct bitset *set, int n)
Returns the index (starting from one) of the first zero bit higher or equal to n in set,...
int bitset_size(const struct bitset *set)
Returns the size (in number of bits) of set.
void bitset_compl(struct bitset *set)
Flip all bits in set.
unsigned int * bits
An array of size integers.