26 #ifndef _GALOIS_DYNAMIC_BIT_SET_
27 #define _GALOIS_DYNAMIC_BIT_SET_
33 #include <boost/iterator/counting_iterator.hpp>
34 #include <boost/mpl/has_xxx.hpp>
36 #include "galois/config.h"
51 static constexpr uint32_t
bits_uint64 =
sizeof(uint64_t) * CHAR_BIT;
118 void reset(
size_t begin,
size_t end) {
143 if (vec_begin < vec_end) {
144 std::fill(
bitvec.begin() + vec_begin,
bitvec.begin() + vec_end, 0);
152 if (vec_begin > vec_end) {
154 if (begin < vec_begin) {
155 size_t diff = vec_begin - begin;
157 uint64_t mask = ((uint64_t)1 << (64 - diff)) - 1;
159 size_t end_diff = end - vec_end + 1;
160 uint64_t or_mask = ((uint64_t)1 << end_diff) - 1;
164 bitvec[bit_index] &= mask;
167 if (begin < vec_begin) {
168 size_t diff = vec_begin - begin;
170 uint64_t mask = ((uint64_t)1 << (64 - diff)) - 1;
172 bitvec[bit_index] &= mask;
174 if (end >= vec_end) {
175 size_t diff = end - vec_end + 1;
177 uint64_t mask = ((uint64_t)1 << diff) - 1;
179 bitvec[bit_index] &= ~mask;
192 bool test(
size_t index)
const {
194 uint64_t bit_offset = 1;
196 return ((
bitvec[bit_index].load(std::memory_order_relaxed) & bit_offset) !=
208 uint64_t bit_offset = 1;
210 uint64_t old_val =
bitvec[bit_index];
213 while (((old_val & bit_offset) == 0) &&
214 !
bitvec[bit_index].compare_exchange_weak(
215 old_val, old_val | bit_offset, std::memory_order_relaxed))
217 return (old_val & bit_offset);
228 uint64_t bit_offset = 1;
230 uint64_t old_val =
bitvec[bit_index];
233 while (((old_val & bit_offset) != 0) &&
234 !
bitvec[bit_index].compare_exchange_weak(
235 old_val, old_val & ~bit_offset, std::memory_order_relaxed))
237 return (old_val & bit_offset);
243 auto& other_bitvec = other.
get_vec();
258 auto& other_bitvec = other.
get_vec();
274 auto& other_bitvec1 = other1.
get_vec();
275 auto& other_bitvec2 = other2.
get_vec();
279 [&](
size_t i) {
bitvec[i] = other_bitvec1[i] & other_bitvec2[i]; },
290 auto& other_bitvec = other.
get_vec();
306 auto& other_bitvec1 = other1.
get_vec();
307 auto& other_bitvec2 = other2.
get_vec();
311 [&](
size_t i) {
bitvec[i] = other_bitvec1[i] ^ other_bitvec2[i]; },
326 ret += __builtin_popcountll(n);
328 n = n - ((n >> 1) & 0x5555555555555555UL);
329 n = (n & 0x3333333333333333UL) + ((n >> 2) & 0x3333333333333333UL);
331 (((n + (n >> 4)) & 0xF0F0F0F0F0F0F0FUL) * 0x101010101010101UL) >>
349 std::vector<unsigned int> tPrefixBitCounts(activeThreads);
355 std::tie(start, end) =
358 unsigned int count = 0;
359 for (
unsigned int i = start; i < end; ++i) {
364 tPrefixBitCounts[tid] =
count;
369 tPrefixBitCounts[i] += tPrefixBitCounts[i - 1];
373 uint64_t bitsetCount = tPrefixBitCounts[activeThreads - 1];
374 std::vector<uint32_t> offsets;
378 if (bitsetCount > 0) {
379 offsets.resize(bitsetCount);
383 std::tie(start, end) =
385 unsigned int count = 0;
386 unsigned int tPrefixBitCount;
390 tPrefixBitCount = tPrefixBitCounts[tid - 1];
393 for (
unsigned int i = start; i < end; ++i) {
395 offsets[tPrefixBitCount +
count] = i;
void bitwise_and(const DynamicBitSet &other)
Does an IN-PLACE bitwise and of this bitset and another bitset.
Definition: libgalois/include/galois/DynamicBitset.h:256
void reserve(uint64_t n)
Reserves capacity for the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:90
auto & get_vec()
Returns the underlying bitset representation to the user.
Definition: libgalois/include/galois/DynamicBitset.h:71
unsigned int getActiveThreads() noexcept
Returns the number of threads in use.
Definition: Threads.cpp:37
DynamicBitSet()
Constructor which initializes to an empty bitset.
Definition: libgalois/include/galois/DynamicBitset.h:55
std::pair< IterTy, IterTy > block_range(IterTy b, IterTy e, unsigned id, unsigned num)
Returns a continuous block from the range based on the number of divisions and the id of the block re...
Definition: gstl.h:244
void bitwise_or(const DynamicBitSet &other)
Definition: libgalois/include/galois/DynamicBitset.h:241
std::vector< uint32_t > getOffsets() const
Returns a vector containing the set bits in this bitset in order from left to right.
Definition: libgalois/include/galois/DynamicBitset.h:347
Concurrent dynamically allocated bitset.
Definition: libgalois/include/galois/DynamicBitset.h:47
static constexpr bool is_vector_bitset()
Returns false as this is an empty bitset.
Definition: libgalois/include/galois/DynamicBitset.h:415
static constexpr bool is_valid()
Returns false as this is an empty bitset (invalid)
Definition: libgalois/include/galois/DynamicBitset.h:418
bool test(size_t index) const
Check a bit to see if it is currently set.
Definition: libgalois/include/galois/DynamicBitset.h:192
void reset(size_t begin, size_t end)
Unset a range of bits given an inclusive range.
Definition: libgalois/include/galois/DynamicBitset.h:118
uint64_t count() const
Count how many bits are set in the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:320
int tt_is_copyable
this is defined to
Definition: libgalois/include/galois/DynamicBitset.h:406
void resize(uint64_t n)
Resizes the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:78
void reset()
Gets the space taken by the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:110
static constexpr uint32_t bits_uint64
Definition: libgalois/include/galois/DynamicBitset.h:51
unsigned int activeThreads
Definition: Threads.cpp:26
size_t size() const
Gets the size of the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:99
A structure representing an empty bitset.
Definition: libgalois/include/galois/DynamicBitset.h:413
bool reset(size_t index)
Reset a bit in the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:226
void do_all(const RangeFunc &rangeMaker, FunctionTy &&fn, const Args &...args)
Standard do-all loop.
Definition: Loops.h:71
bool set(size_t index)
Set a bit in the bitset.
Definition: libgalois/include/galois/DynamicBitset.h:206
void on_each(FunctionTy &&fn, const Args &...args)
Low-level parallel loop.
Definition: Loops.h:86
T & reduce()
Returns the final reduction value.
Definition: Reduction.h:102
Contains a copyable atomics class.
void bitwise_and(const DynamicBitSet &other1, const DynamicBitSet &other2)
Does an IN-PLACE bitwise and of 2 passed in bitsets and saves to this bitset.
Definition: libgalois/include/galois/DynamicBitset.h:271
static void reset_range(size_t, size_t)
No-op since it's an empty bitset.
Definition: libgalois/include/galois/DynamicBitset.h:424
galois::PODResizeableArray< galois::CopyableAtomic< uint64_t > > bitvec
Definition: libgalois/include/galois/DynamicBitset.h:49
size_t num_bits
Definition: libgalois/include/galois/DynamicBitset.h:50
auto iterate(C &cont)
Definition: Range.h:323
This is a container that encapsulates a resizeable array of plain-old-datatype (POD) elements...
Definition: PODResizeableArray.h:40
const auto & get_vec() const
Returns the underlying bitset representation to the user.
Definition: libgalois/include/galois/DynamicBitset.h:63
void bitwise_xor(const DynamicBitSet &other1, const DynamicBitSet &other2)
Does an IN-PLACE bitwise and of 2 passed in bitsets and saves to this bitset.
Definition: libgalois/include/galois/DynamicBitset.h:303
void bitwise_xor(const DynamicBitSet &other)
Does an IN-PLACE bitwise xor of this bitset and another bitset.
Definition: libgalois/include/galois/DynamicBitset.h:288