Nebula
Loading...
Searching...
No Matches
Util::BitArray Class Reference

#include <bitarray.h>

Detailed Description

Implements a growable bit array (similar to std::vector<bool>).

Unlike BitField, which is sized at compile time, this grows when a bit outside it is set, which is what makes it usable for a flag per item when the number of items is not known in advance, for example a flag per entity or per instance of a runtime structure.

The storage is one 64 bit word per 64 bits, so a whole section can be skipped with a single word check before any bit is looked at.

Public Member Functions

 BitArray ()
 constructor
 ~BitArray ()
 destructor
void Resize (uint64_t numBits)
 resize to a number of bits. Growing keeps the bits which are already set, shrinking is not supported
void EnsureBit (uint64_t bitIndex)
 make a bit addressable, growing the array when it is outside
void SetBit (const uint64_t bitIndex)
 set a bit by index, growing the array when the index is outside it
void ClearBit (const uint64_t bitIndex)
 clear a bit by index. Does nothing when the index is outside the array
bool IsSet (const uint64_t bitIndex) const
 check a bit by index. False when the index is outside the array
void MoveBit (const uint64_t from, const uint64_t to)
 move a bit from one index to another. The source is cleared and the target gets the value
bool IsNull () const
 true when no bit is set
bool SectionIsNull (const uint64_t section) const
 true when a whole 64 bit section is empty
SizeT NumSections () const
 number of 64 bit sections which are allocated
IndexT FirstSetBitInSection (const uint64_t section) const
 the index of the first set bit in a section, or InvalidIndex when the section is empty
void Clear ()
 clear all bits. The allocated words are kept
void Reset ()
 clear all bits and release the storage

Private Attributes

Util::Array< uint64_t > words

Constructor & Destructor Documentation

◆ BitArray()

Util::BitArray::BitArray ( )
inline

constructor

◆ ~BitArray()

Util::BitArray::~BitArray ( )
inline

destructor

Member Function Documentation

◆ Clear()

void Util::BitArray::Clear ( )
inline

clear all bits. The allocated words are kept

◆ ClearBit()

void Util::BitArray::ClearBit ( const uint64_t bitIndex)
inline

clear a bit by index. Does nothing when the index is outside the array

◆ EnsureBit()

void Util::BitArray::EnsureBit ( uint64_t bitIndex)
inline

make a bit addressable, growing the array when it is outside

◆ FirstSetBitInSection()

IndexT Util::BitArray::FirstSetBitInSection ( const uint64_t section) const
inline

the index of the first set bit in a section, or InvalidIndex when the section is empty

◆ IsNull()

bool Util::BitArray::IsNull ( ) const
inline

true when no bit is set

◆ IsSet()

bool Util::BitArray::IsSet ( const uint64_t bitIndex) const
inline

check a bit by index. False when the index is outside the array

◆ MoveBit()

void Util::BitArray::MoveBit ( const uint64_t from,
const uint64_t to )
inline

move a bit from one index to another. The source is cleared and the target gets the value

◆ NumSections()

SizeT Util::BitArray::NumSections ( ) const
inline

number of 64 bit sections which are allocated

◆ Reset()

void Util::BitArray::Reset ( )
inline

clear all bits and release the storage

◆ Resize()

void Util::BitArray::Resize ( uint64_t numBits)
inline

resize to a number of bits. Growing keeps the bits which are already set, shrinking is not supported

◆ SectionIsNull()

bool Util::BitArray::SectionIsNull ( const uint64_t section) const
inline

true when a whole 64 bit section is empty

◆ SetBit()

void Util::BitArray::SetBit ( const uint64_t bitIndex)
inline

set a bit by index, growing the array when the index is outside it

Member Data Documentation

◆ words

Util::Array<uint64_t> Util::BitArray::words
private

The documentation for this class was generated from the following file:
  • /github/workspace/code/foundation/util/bitarray.h