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. More...
 
void set (size_t pos)
 Set the (single) bit at position 'pos' to '1'. More...
 
void setPosN (size_t pos, size_t n)
 Starting from position 'pos', set the 'n' following bits to '1'. More...
 
void setRange (size_t begin, size_t end)
 Set all bits in the half-open range [begin, end) to '1'. More...
 
template<typename Operation >
void foreachSetBit (Operation op) const
 Execute the given operation 'op' for all '1' bits. More...
 

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 28 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 43 of file IterableBitSet.hh.

References ranges::all_of().

Referenced by TEST_CASE().

◆ foreachSetBit()

template<size_t N>
template<typename Operation >
void IterableBitSet< N >::foreachSetBit ( Operation  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 116 of file IterableBitSet.hh.

References Math::countTrailingZeros(), and 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 50 of file IterableBitSet.hh.

References openmsx::N.

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 64 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 71 of file IterableBitSet.hh.

References begin(), end(), openmsx::mask, and openmsx::N.

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


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