...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::compute::dynamic_bitset — The dynamic_bitset class contains a resizable bit array.
// In header: <boost/compute/container/dynamic_bitset.hpp> template<typename Block = ulong_, typename Alloc = buffer_allocator<Block> > class dynamic_bitset { public: // types typedef Block block_type; typedef Alloc allocator_type; typedef vector< Block, Alloc > container_type; typedef container_type::size_type size_type; // construct/copy/destruct dynamic_bitset(size_type, command_queue &); dynamic_bitset(const dynamic_bitset &); dynamic_bitset & operator=(const dynamic_bitset &); ~dynamic_bitset(); // public member functions BOOST_STATIC_CONSTANT(size_type, bits_per_block = sizeof(block_type)*CHAR_BIT); BOOST_STATIC_CONSTANT(size_type, npos = static_cast< size_type >(-1)); size_type size() const; size_type num_blocks() const; size_type max_size() const; bool empty() const; size_type count(command_queue &) const; void resize(size_type, command_queue &); void set(size_type, command_queue &); void set(size_type, bool, command_queue &); bool test(size_type, command_queue &); void flip(size_type, command_queue &); bool any(command_queue &) const; bool none(command_queue &) const; void reset(command_queue &); void reset(size_type, command_queue &); void clear(); allocator_type get_allocator() const; };
For example, to create a dynamic-bitset with space for 1000 bits on the device:
boost::compute::dynamic_bitset<> bits(1000, queue);
The Boost.Compute dynamic_bitset
class provides a STL-like API and is modeled after the boost::dynamic_bitset
class from Boost.
See Also:
dynamic_bitset
public
construct/copy/destructdynamic_bitset(size_type size, command_queue & queue);
Creates a new dynamic bitset with storage for size
bits. Initializes all bits to zero.
dynamic_bitset(const dynamic_bitset & other);Creates a new dynamic bitset as a copy of
other
. dynamic_bitset & operator=(const dynamic_bitset & other);Copies the data from
other
to *this
. ~dynamic_bitset();Destroys the dynamic bitset.
dynamic_bitset
public member functionsBOOST_STATIC_CONSTANT(size_type, bits_per_block = sizeof(block_type)*CHAR_BIT);
BOOST_STATIC_CONSTANT(size_type, npos = static_cast< size_type >(-1));
size_type size() const;Returns the size of the dynamic bitset.
size_type num_blocks() const;Returns the number of blocks to store the bits in the dynamic bitset.
size_type max_size() const;Returns the maximum possible size for the dynamic bitset.
bool empty() const;Returns
true
if the dynamic bitset is empty (i.e. size()
== 0
). size_type count(command_queue & queue) const;Returns the number of set bits (i.e. '1') in the bitset.
void resize(size_type num_bits, command_queue & queue);
Resizes the bitset to contain num_bits
. If the new size is greater than the current size the new bits are set to zero.
void set(size_type n, command_queue & queue);Sets the bit at position
n
to true
. void set(size_type n, bool value, command_queue & queue);Sets the bit at position
n
to value
. bool test(size_type n, command_queue & queue);Returns
true
if the bit at position n
is set (i.e. '1'). void flip(size_type n, command_queue & queue);Flips the value of the bit at position
n
. bool any(command_queue & queue) const;Returns
true
if any bit in the bitset is set (i.e. '1'). bool none(command_queue & queue) const;Returns
true
if all of the bits in the bitset are set to zero. void reset(command_queue & queue);Sets all of the bits in the bitset to zero.
void reset(size_type n, command_queue & queue);Sets the bit at position
n
to zero. void clear();Empties the bitset (e.g.
resize(0)
). allocator_type get_allocator() const;Returns the allocator used to allocate storage for the bitset.