44 const Impl* otherImpl = other.m_impl;
66 auto max_it = std::max_element (l.begin(), l.end());
67 if (max_it != l.end()) {
91 other.m_impl =
nullptr;
115 if (
this != &other) {
116 const Impl* otherImpl = other.m_impl;
118 (*m_impl).assign (*otherImpl);
133 if (
this != &other) {
135 other.emptyGarbage();
138 other.m_impl =
nullptr;
172 bit_t nbits = (*m_impl).nbits();
173 if (new_nbits > nbits) {
199 n += std::popcount (
m_data[i].load());
211 if (
m_data[i])
return false;
247 m_data[i].store (~
static_cast<Block_t>(0), std::memory_order_relaxed);
249 std::atomic_thread_fence (std::memory_order_seq_cst);
265 m_data[i] ^= ~static_cast<Block_t>(0);
Variable-sized bitset allowing (mostly) concurrent access.
bit_t nbits() const
Return the number of bits in the set.
std::atomic< size_t > m_hwm
High-water mark: index of last block with a 1 bit.
void set()
Turn on all bits in the set.
bool all() const
Return true if all bits in the set are 1.
bit_t count() const
Count the number of 1 bits in the set.
void flip()
Flip the state of all bits in the set.
size_t m_nbits
Number of bits in the container.
bool none() const
Return true if there are no 1 bits in the set.
size_t m_nblocks
Number of blocks in the container.
std::atomic< Block_t > m_data[1]
The set data.
void emptyGarbage()
Clean up old versions of the set.
void expandOol(bit_t new_nbits)
Expand the container: out-of-line portion.
std::lock_guard< mutex_t > lock_t
unsigned long Block_t
Internal type used to hold the bitset data.
~ConcurrentBitset()
Destructor.
ConcurrentBitset(bit_t nbits=0)
Constructor.
size_t bit_t
A bit number.
void expand(bit_t new_nbits)
Expand the container.
static const size_t BLOCKSIZE
Size, in bits, of Block_t.
std::atomic< Impl * > m_impl
The current implementation object.
ConcurrentBitset & set()
Turn on all bits in the set.
std::vector< Impl * > m_garbage
Old implementation objects, pending deletion.
ConcurrentBitset & operator=(const ConcurrentBitset &other)
Assignment.
static const size_t MASK
Mask to select out the bit offset within one Block_t.
constexpr T ones(unsigned int n)
Return a bit mask with the lower n bits set.