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

Dynamically sized bit set. More...

#include <dbitset.h>

Public Types

using iter = const_iterator< dbitset >
 Forward iterator over set bit indices.
 
using iter_inv = const_iterator_inverse< dbitset >
 Forward iterator over unset bit indices.
 
using iter_rev = const_reverse_iterator< dbitset >
 Reverse iterator over set bit indices.
 
using iter_rev_inv = const_reverse_inverse_iterator< dbitset >
 Reverse iterator over unset bit indices.
 

Public Member Functions

 dbitset ()
 Constructs a bit set with capacity for at least 128 bits and an initial size of one bit.
 
 dbitset (uint32_t reserveBits)
 Constructs a bit set with requested initial capacity and a size of one bit.
 
 dbitset (const dbitset &other)
 Copy-constructs a bit set.
 
dbitsetoperator= (const dbitset &other)
 Copy-assigns a bit set.
 
 dbitset (dbitset &&other) noexcept
 Move-constructs a bit set and leaves the source empty.
 
dbitsetoperator= (dbitset &&other) noexcept
 Move-assigns a bit set and leaves the source empty.
 
void reserve (uint32_t bitsWanted)
 Reserves storage without changing the current bit count.
 
void resize (uint32_t bitsWanted)
 Changes the number of addressable bits.
 
iter begin () const
 Returns an iterator to the first set bit.
 
iter end () const
 Returns the forward set-bit sentinel.
 
iter_rev rbegin () const
 Returns an iterator to the last set bit.
 
iter_rev rend () const
 Returns the reverse set-bit sentinel.
 
iter_inv ibegin () const
 Returns an iterator to the first unset bit.
 
iter_inv iend () const
 Returns the forward unset-bit sentinel.
 
iter_rev_inv ribegin () const
 Returns an iterator to the last unset bit.
 
iter_rev_inv riend () const
 Returns the reverse unset-bit sentinel.
 
GAIA_NODISCARD bool operator[] (uint32_t pos) const
 Tests a bit.
 
GAIA_NODISCARD bool operator== (const dbitset &other) const
 Compares two bit sets for equality.
 
GAIA_NODISCARD bool operator!= (const dbitset &other) const
 Compares two bit sets for inequality.
 
void set ()
 Sets all bits.
 
void set (uint32_t pos, bool value=true)
 Sets one bit, growing the bit set when needed.
 
void flip ()
 Flips all bits.
 
void flip (uint32_t pos)
 Flips one bit.
 
dbitsetflip (uint32_t bitFrom, uint32_t bitTo)
 Flips an inclusive range of bits.
 
void reset ()
 Unsets all bits.
 
void reset (uint32_t pos)
 Unsets one bit.
 
GAIA_NODISCARD bool test (uint32_t pos) const
 Returns the value of one bit.
 
GAIA_NODISCARD bool all () const
 Checks if all bits are set.
 
GAIA_NODISCARD bool any () const
 Checks if any bit is set.
 
GAIA_NODISCARD 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 dbitset holds.
 
GAIA_NODISCARD constexpr uint32_t capacity () const
 Returns the number of bits the dbitset can hold.
 

Detailed Description

template<typename Allocator = mem::DefaultAllocatorAdaptor>
class gaia::cnt::dbitset< Allocator >

Dynamically sized bit set.

Template Parameters
AllocatorAllocator adaptor used for backing-word storage.

Constructor & Destructor Documentation

◆ dbitset() [1/3]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
gaia::cnt::dbitset< Allocator >::dbitset ( uint32_t  reserveBits)
inline

Constructs a bit set with requested initial capacity and a size of one bit.

Parameters
reserveBitsMinimum requested capacity in bits.

◆ dbitset() [2/3]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
gaia::cnt::dbitset< Allocator >::dbitset ( const dbitset< Allocator > &  other)
inline

Copy-constructs a bit set.

Parameters
otherBit set to copy.

◆ dbitset() [3/3]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
gaia::cnt::dbitset< Allocator >::dbitset ( dbitset< Allocator > &&  other)
inlinenoexcept

Move-constructs a bit set and leaves the source empty.

Parameters
otherBit set whose storage is transferred.

Member Function Documentation

◆ all()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::all ( ) const
inline

Checks if all bits are set.

Returns
True when every bit is set. False otherwise.

◆ any()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::any ( ) const
inline

Checks if any bit is set.

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

◆ begin()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
iter gaia::cnt::dbitset< Allocator >::begin ( ) const
inline

Returns an iterator to the first set bit.

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

◆ capacity()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD constexpr uint32_t gaia::cnt::dbitset< Allocator >::capacity ( ) const
inlineconstexpr

Returns the number of bits the dbitset can hold.

Returns
Current capacity in bits.

◆ count()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD uint32_t gaia::cnt::dbitset< Allocator >::count ( ) const
inline

Returns the number of set bits.

Returns
Number of set bits.

◆ end()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
iter gaia::cnt::dbitset< Allocator >::end ( ) const
inline

Returns the forward set-bit sentinel.

Returns
Sentinel following the last set bit.

◆ flip() [1/2]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
dbitset & gaia::cnt::dbitset< Allocator >::flip ( uint32_t  bitFrom,
uint32_t  bitTo 
)
inline

Flips an inclusive range of bits.

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

◆ flip() [2/2]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
void gaia::cnt::dbitset< Allocator >::flip ( uint32_t  pos)
inline

Flips one bit.

Parameters
posZero-based bit position, which must be less than size().

◆ ibegin()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
iter_inv gaia::cnt::dbitset< Allocator >::ibegin ( ) const
inline

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<typename Allocator = mem::DefaultAllocatorAdaptor>
iter_inv gaia::cnt::dbitset< Allocator >::iend ( ) const
inline

Returns the forward unset-bit sentinel.

Returns
Sentinel following the last unset bit.

◆ none()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::none ( ) const
inline

Checks if all bits are reset.

Returns
True when no bit is set. False otherwise.

◆ operator!=()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::operator!= ( const dbitset< Allocator > &  other) const
inline

Compares two bit sets for inequality.

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

◆ operator=() [1/2]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
dbitset & gaia::cnt::dbitset< Allocator >::operator= ( const dbitset< Allocator > &  other)
inline

Copy-assigns a bit set.

Parameters
otherBit set to copy.
Returns
This bit set.

◆ operator=() [2/2]

template<typename Allocator = mem::DefaultAllocatorAdaptor>
dbitset & gaia::cnt::dbitset< Allocator >::operator= ( dbitset< Allocator > &&  other)
inlinenoexcept

Move-assigns a bit set and leaves the source empty.

Parameters
otherBit set whose storage is transferred.
Returns
This bit set.

◆ operator==()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::operator== ( const dbitset< Allocator > &  other) const
inline

Compares two bit sets for equality.

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

◆ operator[]()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::operator[] ( uint32_t  pos) const
inline

Tests a bit.

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

◆ rbegin()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
iter_rev gaia::cnt::dbitset< Allocator >::rbegin ( ) const
inline

Returns an iterator to the last set bit.

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

◆ rend()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
iter_rev gaia::cnt::dbitset< Allocator >::rend ( ) const
inline

Returns the reverse set-bit sentinel.

Returns
Sentinel preceding the first set bit.

◆ reserve()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
void gaia::cnt::dbitset< Allocator >::reserve ( uint32_t  bitsWanted)
inline

Reserves storage without changing the current bit count.

Parameters
bitsWantedMinimum requested capacity in bits.

◆ reset()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
void gaia::cnt::dbitset< Allocator >::reset ( uint32_t  pos)
inline

Unsets one bit.

Parameters
posZero-based bit position, which must be less than size().

◆ resize()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
void gaia::cnt::dbitset< Allocator >::resize ( uint32_t  bitsWanted)
inline

Changes the number of addressable bits.

Parameters
bitsWantedRequested size in bits. Values below one are clamped to one.

◆ ribegin()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
iter_rev_inv gaia::cnt::dbitset< Allocator >::ribegin ( ) const
inline

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<typename Allocator = mem::DefaultAllocatorAdaptor>
iter_rev_inv gaia::cnt::dbitset< Allocator >::riend ( ) const
inline

Returns the reverse unset-bit sentinel.

Returns
Sentinel preceding the first unset bit.

◆ set()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
void gaia::cnt::dbitset< Allocator >::set ( uint32_t  pos,
bool  value = true 
)
inline

Sets one bit, growing the bit set when needed.

Parameters
posZero-based bit position.
valueValue assigned to the bit.

◆ size()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD constexpr uint32_t gaia::cnt::dbitset< Allocator >::size ( ) const
inlineconstexpr

Returns the number of bits the dbitset holds.

Returns
Current number of addressable bits.

◆ test()

template<typename Allocator = mem::DefaultAllocatorAdaptor>
GAIA_NODISCARD bool gaia::cnt::dbitset< Allocator >::test ( uint32_t  pos) const
inline

Returns the value of one bit.

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

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