27ConcurrentBitset::ConcurrentBitset (bit_t nbits )
40ConcurrentBitset::ConcurrentBitset (
const ConcurrentBitset& other)
44 const Impl* otherImpl =
other.m_impl;
46 m_impl =
new (otherImpl->nbits()) Impl (*otherImpl);
61ConcurrentBitset::ConcurrentBitset (std::initializer_list<bit_t> l,
66 auto max_it = std::max_element (
l.begin(),
l.end());
67 if (max_it !=
l.end()) {
71 nbits = (nbits + BLOCKSIZE-1) & ~MASK;
73 m_impl =
new (nbits) Impl (nbits);
87ConcurrentBitset::ConcurrentBitset (ConcurrentBitset&& other)
91 other.m_impl =
nullptr;
99ConcurrentBitset::~ConcurrentBitset()
113ConcurrentBitset& ConcurrentBitset::operator= (
const ConcurrentBitset& other)
115 if (
this != &other) {
116 const Impl* otherImpl = other.m_impl;
117 expand (otherImpl->nbits());
118 (*m_impl).assign (*otherImpl);
133 if (
this != &other) {
135 other.emptyGarbage();
138 other.m_impl =
nullptr;
153void ConcurrentBitset::emptyGarbage()
167void ConcurrentBitset::expandOol (bit_t new_nbits)
172 bit_t nbits = (*m_impl).nbits();
173 if (new_nbits > nbits) {
194ConcurrentBitset::bit_t
195ConcurrentBitset::Impl::count()
const
198 for (bit_t i=0; i<m_nblocks; i++) {
199 n += std::popcount (m_data[i].load());
208bool ConcurrentBitset::Impl::none()
const
210 for (bit_t i = 0;
i < m_nblocks;
i++) {
211 if (m_data[i])
return false;
220bool ConcurrentBitset::Impl::all()
const
222 if (m_nblocks == 0) {
227 for (bit_t i = 0;
i < m_nblocks-1;
i++) {
228 if (m_data[i] != ~
static_cast<Block_t
>(0))
return false;
231 if (m_data[m_nblocks] !=
ones<Block_t> (m_nbits - (m_nblocks-1)*BLOCKSIZE)) {
244void ConcurrentBitset::Impl::set()
246 for (bit_t i=0;
i<m_nblocks;
i++) {
247 m_data[
i].store (~
static_cast<Block_t
>(0), std::memory_order_relaxed);
249 std::atomic_thread_fence (std::memory_order_seq_cst);
262void ConcurrentBitset::Impl::flip()
264 for (bit_t i=0;
i<m_nblocks;
i++) {
265 m_data[
i] ^= ~static_cast<Block_t>(0);
Variable-sized bitset allowing (mostly) concurrent access.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
consteval T ones(unsigned int n)
Return a bit mask with the lower n bits set.
std::unique_ptr< StringPoolImpl > m_impl
void emptyGarbage()
Clean up old versions of the set.
ConcurrentBitset(bit_t nbits=0)
Constructor.
mutex_t m_mutex
Mutex protecting the container.
std::lock_guard< mutex_t > lock_t
std::atomic< Impl * > m_impl
The current implementation object.
std::vector< Impl * > m_garbage
Old implementation objects, pending deletion.
l
Printing final latex table to .tex output file.