TSDuck v3.46-4965
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::CompactBitSet< BITS > Class Template Referencefinal

#include <tsCompactBitSet.h>

Public Types

using int_t = typename smaller_unsigned<BITS>::type

Public Member Functions

template<class CONTAINER>
requires std::integral<typename CONTAINER::value_type>
 CompactBitSet (const CONTAINER &values)
 CompactBitSet (int_t value=0)
bool all () const
bool any () const
void flip ()
bool none () const
CompactBitSet< BITS > operator& (const CompactBitSet< BITS > &p) const
CompactBitSet< BITS > & operator&= (const CompactBitSet< BITS > &p)
bool operator== (const CompactBitSet< BITS > &p) const
CompactBitSet< BITS > operator| (const CompactBitSet< BITS > &p) const
CompactBitSet< BITS > & operator|= (const CompactBitSet< BITS > &p)
CompactBitSet< BITS > operator~ () const
void reset ()
void reset (size_t pos)
void set ()
void set (size_t pos, bool value=true)
size_t size () const
bool test (size_t pos) const
int_t toInt () const

Static Public Attributes

static constexpr int_t ALL = int_t(BITS == 8 * sizeof(int_t) ? ~int_t(0) : ~(~uint64_t(0) << BITS))
static constexpr size_t MAX = BITS - 1
static constexpr size_t SIZE = BITS

Detailed Description

template<const size_t BITS>
requires (BITS > 0 && BITS <= 64)
class ts::CompactBitSet< BITS >

A compact version of std::bitset.

This class is more efficient than std::bitset for small sizes, typically 32 bits or less.

Differences with std::bitset:

  • CompactBitSet is crafted to use the smallest possible size for a bit set. In contrast, std::bitset may use up to 64 bits, even for small numbers of bits, depending on the platform.
  • CompactBitSet is limited to 64 bits while std::bitset can be used with any number of bits.
  • With CompactBitSet, operations on a given bit such as test() or set() do not fail when the bit is out of range. The bit is simply considered as non existent. The same operation with std::bitset throws an exception.
Template Parameters
BITSNumber of bits. Must be in the range 0 to 64.

Member Typedef Documentation

◆ int_t

template<const size_t BITS>
using ts::CompactBitSet< BITS >::int_t = typename smaller_unsigned<BITS>::type

The underlying unsigned integer type to represent the bit set.

Constructor & Destructor Documentation

◆ CompactBitSet() [1/2]

template<const size_t BITS>
ts::CompactBitSet< BITS >::CompactBitSet ( int_t value = 0)
inline

Constructor.

Parameters
[in]valueInitial value as a bit mask. Bits are numbered from LSB to MSB.

◆ CompactBitSet() [2/2]

template<const size_t BITS>
template<class CONTAINER>
requires std::integral<typename CONTAINER::value_type>
ts::CompactBitSet< BITS >::CompactBitSet ( const CONTAINER & values)
inline

Constructor from a container of integer values.

Template Parameters
CONTAINERA container type of integer values.
Parameters
[in]valuesInitial bit values to set. Bits are numbered from LSB to MSB.

Member Function Documentation

◆ operator==()

template<const size_t BITS>
bool ts::CompactBitSet< BITS >::operator== ( const CompactBitSet< BITS > & p) const
inline

Equality operator.

Parameters
[in]pOther instance to compare.
Returns
True if this object is equal to p.

◆ size()

template<const size_t BITS>
size_t ts::CompactBitSet< BITS >::size ( ) const
inline

Get the size in bits of the bit set.

Returns
The size in bits of the bit set.

◆ operator~()

template<const size_t BITS>
CompactBitSet< BITS > ts::CompactBitSet< BITS >::operator~ ( ) const
inline

Negation unary operator.

Returns
A new bit set.

◆ operator|()

template<const size_t BITS>
CompactBitSet< BITS > ts::CompactBitSet< BITS >::operator| ( const CompactBitSet< BITS > & p) const
inline

Binary or operator.

Parameters
[in]pOther instance to compare.
Returns
A new bit set.

◆ operator&()

template<const size_t BITS>
CompactBitSet< BITS > ts::CompactBitSet< BITS >::operator& ( const CompactBitSet< BITS > & p) const
inline

Binary and operator.

Parameters
[in]pOther instance to compare.
Returns
A new bit set.

◆ operator|=()

template<const size_t BITS>
CompactBitSet< BITS > & ts::CompactBitSet< BITS >::operator|= ( const CompactBitSet< BITS > & p)
inline

Assign with binary or operator.

Parameters
[in]pOther instance to compare.
Returns
A reference to this object.

◆ operator&=()

template<const size_t BITS>
CompactBitSet< BITS > & ts::CompactBitSet< BITS >::operator&= ( const CompactBitSet< BITS > & p)
inline

Assign with binary and operator.

Parameters
[in]pOther instance to compare.
Returns
A reference to this object.

◆ all()

template<const size_t BITS>
bool ts::CompactBitSet< BITS >::all ( ) const
inline

Check if all bits are set.

Returns
True if all bits are set.

◆ any()

template<const size_t BITS>
bool ts::CompactBitSet< BITS >::any ( ) const
inline

Check if at least one bit is set.

Returns
True if at least one bit is set.

◆ none()

template<const size_t BITS>
bool ts::CompactBitSet< BITS >::none ( ) const
inline

Check if no bit is set.

Returns
True if no bit is set.

◆ flip()

template<const size_t BITS>
void ts::CompactBitSet< BITS >::flip ( )
inline

Flip all bits in the set.

◆ set() [1/2]

template<const size_t BITS>
void ts::CompactBitSet< BITS >::set ( )
inline

Set all bits.

◆ set() [2/2]

template<const size_t BITS>
void ts::CompactBitSet< BITS >::set ( size_t pos,
bool value = true )
inline

Set or reset one bit.

Parameters
[in]posBit to alter, 0 to 31.
[in]valueOptional bit value to set, true by default.

◆ reset() [1/2]

template<const size_t BITS>
void ts::CompactBitSet< BITS >::reset ( )
inline

Reset all bits.

◆ reset() [2/2]

template<const size_t BITS>
void ts::CompactBitSet< BITS >::reset ( size_t pos)
inline

Reset one bit.

Parameters
[in]posBit to reset, 0 to 31.

◆ test()

template<const size_t BITS>
bool ts::CompactBitSet< BITS >::test ( size_t pos) const
inline

Test is a bit is set.

Parameters
[in]posbit to test, 0 to 31.
Returns
True if the specified bit is set.

◆ toInt()

template<const size_t BITS>
int_t ts::CompactBitSet< BITS >::toInt ( ) const
inline

Return the set of bits as a 32-bit integer.

Returns
The set of bits as a 32-bit integer.

Member Data Documentation

◆ SIZE

template<const size_t BITS>
size_t ts::CompactBitSet< BITS >::SIZE = BITS
staticconstexpr

Number of bits in this set.

◆ MAX

template<const size_t BITS>
size_t ts::CompactBitSet< BITS >::MAX = BITS - 1
staticconstexpr

Maximum value for bit position.

◆ ALL

template<const size_t BITS>
int_t ts::CompactBitSet< BITS >::ALL = int_t(BITS == 8 * sizeof(int_t) ? ~int_t(0) : ~(~uint64_t(0) << BITS))
staticconstexpr

The int_t value corresponding to all bits set.


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