1 #ifndef DYNAMICBITSET_H
2 #define DYNAMICBITSET_H
17 static_assert(std::is_integral<T>::value,
"T has to be an integral type");
39 void set(
size_t position,
bool value);
44 unsigned long long count();
54 numberOfBits(numberOfBits),
55 sizeOfT(sizeof(T) * 8),
56 bitvector(numberOfBits / sizeOfT + (numberOfBits % sizeOfT == 0 ? 0 : 1))
62 size_t index = position / sizeOfT;
63 int offset = position % sizeOfT;
64 return (bitvector[index] >> offset) & 1;
69 size_t index = position / sizeOfT;
70 int offset = position % sizeOfT;
72 bitvector[index] |= T(1) << offset;
74 bitvector[index] &= ~(T(1) << offset);
80 unsigned long long setBits = 0;
81 for(
unsigned long long i = 0; i < numberOfBits; i++)
bool operator[](size_t position) const
Read access to the (position+1)-th bit.
unsigned long long count()
Number of set bits.
DynamicBitset(unsigned long long numberOfBits)
Constructs a bitset which maintains numberOfBits bits.
const unsigned long long numberOfBits
Dynamic bitset similiar to boost::dynamic_bitset.
void set(size_t position, bool value)
Write access to the (position+1)-th bit.
std::vector< T > bitvector