Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::cnt::bitset< NBits > Class Template Reference

Fixed-size bit set. More...

#include <bitset.h>

Public Types

using size_type = typename size_type_selector< BitsPerItem==32 >::type
 Unsigned backing-word type.
 
using iter = const_iterator< bitset >
 Forward iterator over set bit indices.
 
using iter_inv = const_iterator_inverse< bitset >
 Forward iterator over unset bit indices.
 
using iter_rev = const_reverse_iterator< bitset >
 Reverse iterator over set bit indices.
 
using iter_rev_inv = const_reverse_inverse_iterator< bitset >
 Reverse iterator over unset bit indices.
 

Public Member Functions

constexpr size_typedata ()
 Returns the mutable backing-word storage.
 
constexpr const size_typedata () const
 Returns the immutable backing-word storage.
 
GAIA_NODISCARD constexpr uint32_t items () const
 Returns the number of words used by the bitset internally.
 
constexpr iter begin () const
 Returns an iterator to the first set bit.
 
constexpr iter end () const
 Returns the forward set-bit sentinel.
 
constexpr iter_rev rbegin () const
 Returns an iterator to the last set bit.
 
constexpr iter_rev rend () const
 Returns the reverse set-bit sentinel.
 
constexpr iter_inv ibegin () const
 Returns an iterator to the first unset bit.
 
constexpr iter_inv iend () const
 Returns the forward unset-bit sentinel.
 
constexpr iter_rev_inv ribegin () const
 Returns an iterator to the last unset bit.
 
constexpr iter_rev_inv riend () const
 Returns the reverse unset-bit sentinel.
 
GAIA_NODISCARD constexpr bool operator[] (uint32_t pos) const
 Tests a bit.
 
GAIA_NODISCARD constexpr bool operator== (const bitset &other) const
 Compares two bit sets for equality.
 
GAIA_NODISCARD constexpr bool operator!= (const bitset &other) const
 Compares two bit sets for inequality.
 
constexpr void set ()
 Sets all bits.
 
constexpr void set (uint32_t pos, bool value=true)
 Sets the bit at the given position.
 
constexpr bitsetflip ()
 Flips all bits.
 
constexpr void flip (uint32_t pos)
 Flips one bit.
 
constexpr bitsetflip (uint32_t bitFrom, uint32_t bitTo)
 Flips an inclusive range of bits.
 
constexpr void reset ()
 Unsets all bits.
 
constexpr void reset (uint32_t pos)
 Unsets one bit.
 
GAIA_NODISCARD constexpr bool test (uint32_t pos) const
 Returns the value of one bit.
 
GAIA_NODISCARD constexpr bool all () const
 Checks if all bits are set.
 
GAIA_NODISCARD constexpr bool any () const
 Checks if any bit is set.
 
GAIA_NODISCARD constexpr bool none () const
 Checks if all bits are reset.
 
GAIA_NODISCARD uint32_t count () const
 Returns the number of set bits.
 
GAIA_NODISCARD constexpr uint32_t size () const
 Returns the number of bits the bitset can hold.
 

Static Public Attributes

static constexpr uint32_t BitCount = NBits
 Number of addressable bits.
 
static constexpr uint32_t BitsPerItem = (NBits / 64) > 0 ? 64 : 32
 Number of bits stored in each backing word.
 
static constexpr uint32_t Items = (NBits + BitsPerItem - 1) / BitsPerItem
 Number of backing words.
 

Detailed Description

template<uint32_t NBits>
class gaia::cnt::bitset< NBits >

Fixed-size bit set.

Template Parameters
NBitsNumber of addressable bits.

Member Function Documentation

◆ all()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::all ( ) const
inlineconstexpr

Checks if all bits are set.

Returns
True when every bit is set. False otherwise.

◆ any()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::any ( ) const
inlineconstexpr

Checks if any bit is set.

Returns
True when at least one bit is set. False otherwise.

◆ begin()

template<uint32_t NBits>
constexpr iter gaia::cnt::bitset< NBits >::begin ( ) const
inlineconstexpr

Returns an iterator to the first set bit.

Returns
Forward iterator to the first set bit, or end() when none is set.

◆ count()

template<uint32_t NBits>
GAIA_NODISCARD uint32_t gaia::cnt::bitset< NBits >::count ( ) const
inline

Returns the number of set bits.

Returns
Number of set bits.

◆ data() [1/2]

template<uint32_t NBits>
constexpr size_type * gaia::cnt::bitset< NBits >::data ( )
inlineconstexpr

Returns the mutable backing-word storage.

Returns
Pointer to the first backing word.

◆ data() [2/2]

template<uint32_t NBits>
constexpr const size_type * gaia::cnt::bitset< NBits >::data ( ) const
inlineconstexpr

Returns the immutable backing-word storage.

Returns
Pointer to the first backing word.

◆ end()

template<uint32_t NBits>
constexpr iter gaia::cnt::bitset< NBits >::end ( ) const
inlineconstexpr

Returns the forward set-bit sentinel.

Returns
Sentinel following the last set bit.

◆ flip() [1/3]

template<uint32_t NBits>
constexpr bitset & gaia::cnt::bitset< NBits >::flip ( )
inlineconstexpr

Flips all bits.

Returns
This bit set.

◆ flip() [2/3]

template<uint32_t NBits>
constexpr bitset & gaia::cnt::bitset< NBits >::flip ( uint32_t  bitFrom,
uint32_t  bitTo 
)
inlineconstexpr

Flips an inclusive range of bits.

Parameters
bitFromFirst bit position to flip.
bitToLast bit position to flip, inclusive.
Returns
This bit set.

◆ flip() [3/3]

template<uint32_t NBits>
constexpr void gaia::cnt::bitset< NBits >::flip ( uint32_t  pos)
inlineconstexpr

Flips one bit.

Parameters
posZero-based bit position, which must be less than NBits.

◆ ibegin()

template<uint32_t NBits>
constexpr iter_inv gaia::cnt::bitset< NBits >::ibegin ( ) const
inlineconstexpr

Returns an iterator to the first unset bit.

Returns
Forward iterator to the first unset bit, or iend() when all bits are set.

◆ iend()

template<uint32_t NBits>
constexpr iter_inv gaia::cnt::bitset< NBits >::iend ( ) const
inlineconstexpr

Returns the forward unset-bit sentinel.

Returns
Sentinel following the last unset bit.

◆ items()

template<uint32_t NBits>
GAIA_NODISCARD constexpr uint32_t gaia::cnt::bitset< NBits >::items ( ) const
inlineconstexpr

Returns the number of words used by the bitset internally.

Returns
Number of backing words.

◆ none()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::none ( ) const
inlineconstexpr

Checks if all bits are reset.

Returns
True when no bit is set. False otherwise.

◆ operator!=()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::operator!= ( const bitset< NBits > &  other) const
inlineconstexpr

Compares two bit sets for inequality.

Parameters
otherBit set to compare with.
Returns
True when every compared backing word differs. False otherwise.

◆ operator==()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::operator== ( const bitset< NBits > &  other) const
inlineconstexpr

Compares two bit sets for equality.

Parameters
otherBit set to compare with.
Returns
True when all backing words are equal. False otherwise.

◆ operator[]()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::operator[] ( uint32_t  pos) const
inlineconstexpr

Tests a bit.

Parameters
posZero-based bit position, which must be less than NBits.
Returns
True when the bit is set. False otherwise.

◆ rbegin()

template<uint32_t NBits>
constexpr iter_rev gaia::cnt::bitset< NBits >::rbegin ( ) const
inlineconstexpr

Returns an iterator to the last set bit.

Returns
Reverse iterator to the last set bit, or rend() when none is set.

◆ rend()

template<uint32_t NBits>
constexpr iter_rev gaia::cnt::bitset< NBits >::rend ( ) const
inlineconstexpr

Returns the reverse set-bit sentinel.

Returns
Sentinel preceding the first set bit.

◆ reset()

template<uint32_t NBits>
constexpr void gaia::cnt::bitset< NBits >::reset ( uint32_t  pos)
inlineconstexpr

Unsets one bit.

Parameters
posZero-based bit position, which must be less than NBits.

◆ ribegin()

template<uint32_t NBits>
constexpr iter_rev_inv gaia::cnt::bitset< NBits >::ribegin ( ) const
inlineconstexpr

Returns an iterator to the last unset bit.

Returns
Reverse iterator to the last unset bit, or riend() when all bits are set.

◆ riend()

template<uint32_t NBits>
constexpr iter_rev_inv gaia::cnt::bitset< NBits >::riend ( ) const
inlineconstexpr

Returns the reverse unset-bit sentinel.

Returns
Sentinel preceding the first unset bit.

◆ set()

template<uint32_t NBits>
constexpr void gaia::cnt::bitset< NBits >::set ( uint32_t  pos,
bool  value = true 
)
inlineconstexpr

Sets the bit at the given position.

Parameters
posBit position to set (0-based, must be < NBits)
valueValue to set the bit to. Defaults to true.

◆ size()

template<uint32_t NBits>
GAIA_NODISCARD constexpr uint32_t gaia::cnt::bitset< NBits >::size ( ) const
inlineconstexpr

Returns the number of bits the bitset can hold.

Returns
NBits.

◆ test()

template<uint32_t NBits>
GAIA_NODISCARD constexpr bool gaia::cnt::bitset< NBits >::test ( uint32_t  pos) const
inlineconstexpr

Returns the value of one bit.

Parameters
posZero-based bit position, which must be less than NBits.
Returns
True when the bit is set. False otherwise.

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