17#ifndef __misc_bitset_h__
18#define __misc_bitset_h__
52 operator bool()
const {
return d.
test (p); }
57 friend std::ostream&
operator<< (std::ostream& stream,
const Value& V) { stream << (bool(V) ?
'1' :
'0');
return stream; }
65 operator bool()
const {
return d.
test (p); }
67 friend std::ostream&
operator<< (std::ostream& stream,
const ConstValue& V) { stream << (bool(V) ?
'1' :
'0');
return stream; }
78 BitSet (
const size_t,
const bool allocator =
false);
96 void resize (
const size_t,
const bool allocator =
false);
102 void clear (
const bool allocator =
false);
206 return (data[
index>>3] & masks[
index&
size_t(7)]);
212 std::atomic<uint8_t>* at =
reinterpret_cast<std::atomic<uint8_t>*
> (((uint8_t*) data) + (
index>>3));
213 uint8_t prev = *at, new_value;
214 do { new_value = prev | masks[
index&size_t(7)]; }
while (!at->compare_exchange_weak (prev, new_value));
220 std::atomic<uint8_t>* at =
reinterpret_cast<std::atomic<uint8_t>*
> (((uint8_t*) data) + (
index>>3));
221 uint8_t prev = *at, new_value;
222 do { new_value = prev & ~masks[
index&size_t(7)]; }
while (!at->compare_exchange_weak (prev, new_value));
229 static const uint8_t masks[8];
ConstValue(const BitSet &master, const size_t offset)
friend std::ostream & operator<<(std::ostream &stream, const ConstValue &V)
bool operator==(const bool i) const
friend std::ostream & operator<<(std::ostream &stream, const Value &V)
Value & operator|=(const bool i)
Value(BitSet &master, const size_t offset)
bool operator==(const bool i) const
Value & operator&=(const bool i)
bool operator=(const bool i)
a class for storing bitwise information
uint8_t excess_bit_mask() const
BitSet & operator^=(const BitSet &)
size_t count() const
count the number of true entries in the set
void set(const size_t index)
bool have_excess_bits() const
BitSet operator^(const BitSet &) const
bool empty() const
whether or not the bitset is 'empty' i.e. all elements are false
void clear(const bool allocator=false)
clear the data
size_t size() const
the number of boolean elements in the set
BitSet operator&(const BitSet &) const
BitSet(const BitSet &)
copy-construct a bitset, with explicit copying of data into the new instance
size_t excess_bits() const
const uint8_t * get_data_ptr() const
BitSet & operator&=(const BitSet &)
BitSet operator|(const BitSet &) const
friend std::ostream & operator<<(std::ostream &, const BitSet &)
bool operator!=(const BitSet &) const
BitSet & operator=(const BitSet &)
convenience functions for performing boolean operations
bool operator==(const BitSet &) const
void reset(const size_t index)
bool test(const size_t index) const
bool full() const
whether or not the bitset is 'full' i.e. all elements are true
BitSet & operator|=(const BitSet &)
void resize(const size_t, const bool allocator=false)
resize the bitset, retaining existing data
BitSet(const size_t, const bool allocator=false)
create a new bitset with the desired size.
ConstValue operator[](const size_t i) const
access boolean value at a given index