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

A compact version of std::bitset. More...

#include <tsCompactBitSet.h>

Public Types

using int_t = typename smaller_unsigned< BITS >::type
 The underlying unsigned integer type to represent the bit set.
 

Public Member Functions

template<class CONTAINER >
requires std::integral<typename CONTAINER::value_type>
 CompactBitSet (const CONTAINER &values)
 Constructor from a container of integer values.
 
 CompactBitSet (int_t value=0)
 Constructor.
 
bool all () const
 Check if all labels are set.
 
bool any () const
 Check if at least one label is set.
 
void flip ()
 Flip all bits in the set.
 
bool none () const
 Check if no label is set.
 
CompactBitSet< BITS > operator& (const CompactBitSet< BITS > &p) const
 Binary and operator.
 
CompactBitSet< BITS > & operator&= (const CompactBitSet< BITS > &p)
 Assign with binary and operator.
 
bool operator== (const CompactBitSet< BITS > &p) const
 Equality operator.
 
CompactBitSet< BITS > operator| (const CompactBitSet< BITS > &p) const
 Binary or operator.
 
CompactBitSet< BITS > & operator|= (const CompactBitSet< BITS > &p)
 Assign with binary or operator.
 
CompactBitSet< BITS > operator~ () const
 Negation unary operator.
 
void reset ()
 Reset all labels.
 
void reset (size_t pos)
 Reset one label.
 
void set ()
 Set all labels.
 
void set (size_t pos, bool value=true)
 Set or reset one label.
 
size_t size () const
 Get the size in bits of the bit set.
 
bool test (size_t pos) const
 Test is a label is set.
 
int_t toInt () const
 Return the set of labels as a 32-bit integer.
 

Static Public Attributes

static constexpr int_t ALL = int_t(BITS == 8 * sizeof(int_t) ? ~int_t(0) : ~(~uint64_t(0) << BITS))
 The int_t value corresponding to all bits set.
 
static constexpr size_t MAX = BITS - 1
 Maximum value for bit position.
 
static constexpr size_t SIZE = BITS
 Number of bits in this set.
 

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.

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 label 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 label 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 label 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 label 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 labels are set.

Returns
True if all labels are set.

◆ any()

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

Check if at least one label is set.

Returns
True if at least one label is set.

◆ none()

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

Check if no label is set.

Returns
True if no label is set.

◆ set()

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

Set or reset one label.

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

◆ reset()

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

Reset one label.

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

◆ test()

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

Test is a label is set.

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

◆ toInt()

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

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

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

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