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) {
134 Impl*
impl =
other.m_impl.exchange (
nullptr);
140 other.emptyGarbage();
154void ConcurrentBitset::emptyGarbage()
168void ConcurrentBitset::expandOol (bit_t new_nbits)
173 bit_t nbits = (*m_impl).nbits();
174 if (new_nbits > nbits) {
195ConcurrentBitset::bit_t
196ConcurrentBitset::Impl::count()
const
199 for (bit_t i=0; i<m_nblocks; i++) {
200 n += std::popcount (m_data[i].load());
209bool ConcurrentBitset::Impl::none()
const
211 for (bit_t i = 0;
i < m_nblocks;
i++) {
212 if (m_data[i])
return false;
221bool ConcurrentBitset::Impl::all()
const
223 if (m_nblocks == 0) {
228 for (bit_t i = 0;
i < m_nblocks-1;
i++) {
229 if (m_data[i] != ~
static_cast<Block_t
>(0))
return false;
232 if (m_data[m_nblocks] !=
ones<Block_t> (m_nbits - (m_nblocks-1)*BLOCKSIZE)) {
245void ConcurrentBitset::Impl::set()
247 for (bit_t i=0;
i<m_nblocks;
i++) {
248 m_data[
i].store (~
static_cast<Block_t
>(0), std::memory_order_relaxed);
250 std::atomic_thread_fence (std::memory_order_seq_cst);
263void ConcurrentBitset::Impl::flip()
265 for (bit_t i=0;
i<m_nblocks;
i++) {
266 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.
std::lock_guard< std::mutex > lock_t
l
Printing final latex table to .tex output file.