64#ifndef __BIT_FIELD_H__
65#define __BIT_FIELD_H__
101 return (b[n >> 5] & (1 << (n & 0x1F))) != 0;
111 b[n >> 5] &= ~(1 << (n & 0x1F));
121 b[n >> 5] |= 1 << (n & 0x1F);
131 for ( ; s > 0; s--) {
146 for ( ; s > 0; s--) {
161 for ( ; s > 0; s--) {
173 for ( ; s > 0; s--) {
185 for ( ; s > 0; s--) {
200 for ( ; s > 0; s--) {
201 empty = empty && (b[s-1] == 0);
226 const uint32_t bits_to_words_shift = 5;
227 const uint32_t bits_to_words_remainder = (1 << bits_to_words_shift) - 1;
230 uint32_t words = bits >> bits_to_words_shift;
233 if ((bits & bits_to_words_remainder) != 0) {
249 for ( ; s > 0; s--) {
250 sum += __builtin_popcount(b[s - 1]);
static void or_bit_fields(bit_field_t restrict b1, const bit_field_t restrict b2, size_t s)
This function ors two bit_fields together.
Definition bit_field.h:156
static bool empty_bit_field(const bit_field_t restrict b, size_t s)
This function tests whether a bit_field is all zeros.
Definition bit_field.h:194
uint32_t size_t
An unsigned integer used for the size of objects.
Definition bit_field.h:77
static void set_bit_field(bit_field_t restrict b, size_t s)
This function sets an entire bit_field.
Definition bit_field.h:181
static void not_bit_field(bit_field_t restrict b, size_t s)
This function negates the bits of an entire bit_field.
Definition bit_field.h:127
static size_t get_bit_field_size(size_t bits)
A function that calculates the size of a bit_field to hold 'bits' bits.
Definition bit_field.h:222
static bool bit_field_test(bit_field_t b, index_t n)
This function tests a particular bit of a bit_field.
Definition bit_field.h:97
uint32_t * bit_field_t
bit_field_t is an arbitrary length bit field (vector of bits) which is used to compactly represent a ...
Definition bit_field.h:73
static void bit_field_clear(bit_field_t restrict b, index_t n)
This function clears a particular bit of a bit_field.
Definition bit_field.h:107
static void bit_field_set(bit_field_t restrict b, index_t n)
This function sets a particular bit of a bit_field.
Definition bit_field.h:117
static void clear_bit_field(bit_field_t restrict b, size_t s)
This function clears an entire bit_field.
Definition bit_field.h:169
static void and_bit_fields(bit_field_t restrict b1, const bit_field_t restrict b2, size_t s)
This function ands two bit_fields together.
Definition bit_field.h:141
static int count_bit_field(const bit_field_t restrict b, size_t s)
Computes the number of set bits in a bit_field.
Definition bit_field.h:243
void random_bit_field(bit_field_t restrict b, size_t s)
Generates a random bit_field for testing purposes.
Definition bit_field.c:116
uint32_t index_t
An unsigned integer used as an index.
Definition bit_field.h:83
void print_bit_field(const bit_field_t restrict b, size_t s)
This function prints out an entire bit_field, as a sequence of hexadecimal numbers,...
Definition bit_field.c:103
void print_bit_field_bits(const bit_field_t restrict b, size_t s)
This function prints out an entire bit_field, as a sequence of ones and zeros.
Definition bit_field.c:90
bit_field_t bit_field_alloc(uint32_t n_atoms)
allocates a bit_field_t object
Definition bit_field.c:129
static bool nonempty_bit_field(const bit_field_t restrict b, size_t s)
Testing whether a bit_field is non-empty, i.e. if there is at least one bit set.
Definition bit_field.h:211
uint32_t counter_t
An unsigned integer used as a counter or iterator.
Definition bit_field.h:89