| Home | Libraries | People | FAQ | More

## Class template dynamic_bitset

boost::compute::dynamic_bitset — The dynamic_bitset class contains a resizable bit array.

## Synopsis

    // 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;
    };

## Description

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:

vector<T>

### `dynamic_bitset` public construct/copy/destruct

1.     dynamic_bitset(size_type size, command_queue & queue);

   Creates a new dynamic bitset with storage for `size` bits. Initializes all bits to zero.

2.     dynamic_bitset(const dynamic_bitset & other);

   Creates a new dynamic bitset as a copy of `other`.

3.     dynamic_bitset & operator=(const dynamic_bitset & other);

   Copies the data from `other` to `*this`.

4.     ~dynamic_bitset();

   Destroys the dynamic bitset.

### `dynamic_bitset` public member functions

1.      BOOST_STATIC_CONSTANT(size_type,
                              bits_per_block = sizeof(block_type) *CHAR_BIT);

2.      BOOST_STATIC_CONSTANT(size_type, npos = static_cast< size_type >(-1));

3.     size_type size() const;

   Returns the size of the dynamic bitset.

4.     size_type num_blocks() const;

   Returns the number of blocks to store the bits in the dynamic bitset.

5.     size_type max_size() const;

   Returns the maximum possible size for the dynamic bitset.

6.     bool empty() const;

   Returns `true` if the dynamic bitset is empty (i.e. `size()` == `0`).

7.     size_type count(command_queue & queue) const;

   Returns the number of set bits (i.e. '1') in the bitset.

8.     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.

9.     void set(size_type n, command_queue & queue);

   Sets the bit at position `n` to `true`.

10.     void set(size_type n, bool value, command_queue & queue);

    Sets the bit at position `n` to `value`.

11.     bool test(size_type n, command_queue & queue);

    Returns `true` if the bit at position `n` is set (i.e. '1').

12.     void flip(size_type n, command_queue & queue);

    Flips the value of the bit at position `n`.

13.     bool any(command_queue & queue) const;

    Returns `true` if any bit in the bitset is set (i.e. '1').

14.     bool none(command_queue & queue) const;

    Returns `true` if all of the bits in the bitset are set to zero.

15.     void reset(command_queue & queue);

    Sets all of the bits in the bitset to zero.

16.     void reset(size_type n, command_queue & queue);

    Sets the bit at position `n` to zero.

17.     void clear();

    Empties the bitset (e.g. `resize(0)`).

18.     allocator_type get_allocator() const;

    Returns the allocator used to allocate storage for the bitset.