File view_vector_bit.hpp

Typedefs

using AllocatedBitVector = BitVectorAllocator<BitView>

Allocates the memory, a BitView provides access to.

class BitView : public Vector<uint32>
#include <view_vector_bit.hpp>

A one-dimensional view that provides access to binary values stored in a pre-allocated array in a space-efficient way (see https://en.wikipedia.org/wiki/Bit_array).

Public Types

using bit_const_iterator = ConstIterator

An iterator that provides read-only access to the binary values in the vector.

Public Functions

inline BitView(uint32 *array, uint32 numBits)
Parameters:
  • array – A pointer to an array of type uint32 that stores the values, the view should provide access to

  • numBits – The number of bits in the view

inline BitView(const BitView &other)
Parameters:

other – A const reference to an object of type BitView that should be copied

inline BitView(BitView &&other)
Parameters:

other – A reference to an object of type BitView that should be moved

inline virtual ~BitView() override
inline bit_const_iterator bits_cbegin() const

Returns a bit_const_iterator to the beginning of the binary values in the vector.

Returns:

A bit_const_iterator to the beginning

inline bit_const_iterator bits_cend() const

Returns a bit_const_iterator to the end of the binary values in the vector.

Returns:

A bit_const_iterator to the end

inline bool get(uint32 pos) const

Returns whether the bit at a specific position is set or unset.

Parameters:

pos – The position of the bit

Returns:

True, if the bit is set, false, if it is unset

inline void set(uint32 pos, bool set)

Sets or unsets the bit at a specific position.

Parameters:
  • pos – The position of the bit

  • set – True, if the bit should be set, false, if it should be unset

Public Members

const uint32 numBits

The number of bits in the view.

Public Static Attributes

static uint32 BITS_PER_ELEMENT = static_cast<uint32>(CHAR_BIT * sizeof(uint32))

The number of bits that can be stored per individual element in the array this view is backed by.

Private Static Functions

static inline uint32 calculateNumElements(uint32 numBits)
static inline uint32 calculateOffset(uint32 pos)
static inline uint32 createBitMask(uint32 pos)
class ConstIterator
#include <view_vector_bit.hpp>

An iterator that provides random read-only access to the binary values in a BitView.

Public Types

using difference_type = int

The type that is used to represent the difference between two iterators.

using value_type = const bool

The type of the elements, the iterator provides access to.

using pointer = const bool*

The type of a pointer to an element, the iterator provides access to.

using reference = const bool&

The type of a reference to an element, the iterator provides access to.

using iterator_category = std::random_access_iterator_tag

The tag that specifies the capabilities of the iterator.

Public Functions

inline ConstIterator(const BitView &view, uint32 startIndex = 0)
Parameters:
  • view – A reference to an object of type BitView, the iterator should provide access to

  • startIndex – The index to start at

inline value_type operator[](uint32 index) const

Returns whether the bit at a specific index is set or unset.

Parameters:

index – The index of the element to be returned

Returns:

True if the bit at the given index is set, false, if it is unset

inline value_type operator*()

Returns the element, the iterator currently refers to.

Returns:

The element, the iterator currently refers to

inline ConstIterator &operator++()

Returns an iterator to the next element.

Returns:

A reference to an iterator that refers to the next element

inline ConstIterator &operator++(int n)

Returns an iterator to the next element.

Returns:

A reference to an iterator that refers to the next element

inline ConstIterator &operator--()

Returns an iterator to the previous element.

Returns:

A reference to an iterator that refers to the previous element

inline ConstIterator &operator--(int n)

Returns an iterator to the previous element.

Returns:

A reference to an iterator that refers to the previous element

inline bool operator!=(const ConstIterator &rhs) const

Returns whether this iterator and another one refer to the same element.

Parameters:

rhs – A reference to another iterator

Returns:

True, if the iterators do not refer to the same element, false otherwise

inline bool operator==(const ConstIterator &rhs) const

Returns whether this iterator and another one refer to the same element.

Parameters:

rhs – A reference to another iterator

Returns:

True, if the iterators refer to the same element, false otherwise

inline difference_type operator-(const ConstIterator &rhs) const

Returns the difference between this iterator and another one.

Parameters:

rhs – A reference to another iterator

Returns:

The difference between the iterators

Private Members

const BitView &view_
uint32 index_
template<typename View>
class BitVectorAllocator : public Allocator<View>
#include <view_vector_bit.hpp>

Allocates the memory, a BitView provides access to.

Template Parameters:

View – The type of the view

Public Functions

inline explicit BitVectorAllocator(uint32 numBits, bool init = false)
Parameters:
  • numBits – The number of bits in the vector

  • init – True, if all elements in the view should be value-initialized, false otherwise

inline BitVectorAllocator(const BitVectorAllocator<View> &other)
Parameters:

other – A reference to an object of type BitVectorAllocator that should be copied

inline BitVectorAllocator(BitVectorAllocator<View> &&other)
Parameters:

other – A reference to an object of type BitVectorAllocator that should be moved

inline virtual ~BitVectorAllocator() override
template<typename View>
class BitVectorDecorator : public ViewDecorator<View>
#include <view_vector_bit.hpp>

A vector that stores binary values in a BitView.

Template Parameters:

View – The type of the BitView, the vector is backed by

Public Functions

inline explicit BitVectorDecorator(View &&view)
Parameters:

view – The view, the vector should be backed by

inline virtual ~BitVectorDecorator() override
inline uint32 getNumElements() const

Returns the number of bits in the vector.

Returns:

The number of bits in the vector

template<typename BitVector>
class IndexableBitVectorDecorator : public BitVector
#include <view_vector_bit.hpp>

Provides random read and write access to values stored in a bit vector.

Template Parameters:

View – The type of view, the vector is backed by

Public Functions

inline explicit IndexableBitVectorDecorator(typename BitVector::view_type &&view)
Parameters:

view – The view, the vector should be backed by

inline virtual ~IndexableBitVectorDecorator() override
inline bool operator[](uint32 pos) const

Returns whether the bit at a specific position is set or unset.

Parameters:

pos – The position of the bit

Returns:

True, if the bit is set, false, if it is unset

inline void set(uint32 pos, bool set)

Sets or unsets the bit at a specific position.

Parameters:
  • pos – The position of the bit

  • set – True, if the bit should be set, false, if it should be unset