openMSX
Public Member Functions | List of all members
IterableBitSet< N > Class Template Reference

IterableBitSet. More...

#include <IterableBitSet.hh>

Inheritance diagram for IterableBitSet< N >:
Inheritance graph
[legend]

Public Member Functions

bool empty () const
 (Implicit) default constructor.
 
void set (size_t pos)
 Set the (single) bit at position 'pos' to '1'.
 
void setPosN (size_t pos, size_t n)
 Starting from position 'pos', set the 'n' following bits to '1'.
 
void setRange (size_t begin, size_t end)
 Set all bits in the half-open range [begin, end) to '1'.
 
void foreachSetBit (std::invocable< size_t > auto op) const
 Execute the given operation 'op' for all '1' bits.
 

Detailed Description

template<size_t N>
class IterableBitSet< N >

IterableBitSet.

A collection of N bits, with N a compile-time constant.

The main difference with std::bitset is that this implementation allows to efficiently:

This implementation is well suited for bitsets of size up to hundreds or even a few thousand bits. For much larger bitsets and/or for bitsets with specific patterns (e.g. very sparse, or large bursts), other implementations might be better suited.

The interface of this class is (intentionally) minimal. If/when needed we can easily extend it.

Definition at line 30 of file IterableBitSet.hh.

Member Function Documentation

◆ empty()

template<size_t N>
bool IterableBitSet< N >::empty ( ) const
inline

(Implicit) default constructor.

Sets all bits to '0'. Returns true iff none of the bits are set.

Definition at line 45 of file IterableBitSet.hh.

References ranges::all_of().

Referenced by TEST_CASE().

◆ foreachSetBit()

template<size_t N>
void IterableBitSet< N >::foreachSetBit ( std::invocable< size_t > auto  op) const
inline

Execute the given operation 'op' for all '1' bits.

The operation is called with the index of the bit as parameter. The bits are visited in ascending order.

Definition at line 117 of file IterableBitSet.hh.

References xrange().

Referenced by expect().

◆ set()

template<size_t N>
void IterableBitSet< N >::set ( size_t  pos)
inline

Set the (single) bit at position 'pos' to '1'.

Definition at line 52 of file IterableBitSet.hh.

Referenced by TEST_CASE().

◆ setPosN()

template<size_t N>
void IterableBitSet< N >::setPosN ( size_t  pos,
size_t  n 
)
inline

Starting from position 'pos', set the 'n' following bits to '1'.

Definition at line 66 of file IterableBitSet.hh.

References IterableBitSet< N >::setRange().

Referenced by test().

◆ setRange()

template<size_t N>
void IterableBitSet< N >::setRange ( size_t  begin,
size_t  end 
)
inline

Set all bits in the half-open range [begin, end) to '1'.

Definition at line 73 of file IterableBitSet.hh.

References begin(), and end().

Referenced by IterableBitSet< N >::setPosN(), and test().


The documentation for this class was generated from the following file: