Apparatus Version 1.23
ECS data-oriented workflow for Unreal Engine.
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
FBitMask Struct Reference

A memory-efficient bit mask. More...

#include <BitMask.h>

Classes

struct  ConstIterator
 The bit mask bit iterator. More...
 
struct  FBitAccessor
 A special adapter for setting individual bits. More...
 
struct  Iterator
 The bit mask bit iterator. More...
 

Public Types

enum  {
  GroupSizeBits = sizeof(GroupType) * 8 , GroupShift = 6 , GroupBitIndexMask = GroupSizeBits - 1 , bitsCountLUTSize = 256 ,
  InlineGroupsCount = 4
}
 
typedef uint64 GroupType
 The type of the bit group elements.
 

Public Member Functions

int32 GroupsNum () const
 Get the number of available bit groups.
 
int32 BitsNum () const
 Get the number of available (allocated) bits.
 
bool At (const int32 Index) const
 Get the bit flag at the specified index.
 
bool operator[] (const int32 Index) const
 Get a bit element by its index.
 
FBitAccessor operator[] (const int32 Index)
 Get a bit element by its index.
 
void SetAt (const int32 Index, const bool Value)
 Set a bit at a specific index.
 
bool IsNonZero () const
 Check if there are any non-zero bits in the mask.
 
bool operator== (const FBitMask &Other) const
 Compare two bit masks for equality.
 
bool operator!= (const FBitMask &Other) const
 Compare two bit masks for inequality.
 
bool Identical (const FBitMask *Other, uint32 PortFlags) const
 Compare two bit masks for equality.
 
EApparatusStatus Trim (const bool bAllowShrinking=true) const
 Trim the meaningless high-order groups.
 
bool IsAllZeroes () const
 Check if all of the bits in the mask are zeroes or none.
 
int32 CountNonZeroGroups () const
 Get the number of meaningful (non-zero) bit groups.
 
EApparatusStatus Set (FBitMask &&InBitMask)
 Move the bit mask to this bit mask.
 
template<EParadigm Paradigm = EParadigm::Default>
TOutcome< Paradigm > Set (const FBitMask &InBitMask)
 Set this bit mask equal to another bit mask.
 
FBitMaskoperator= (FBitMask &&InBitMask)
 Move the bit mask.
 
FBitMaskoperator= (const FBitMask &InBitMask)
 Set this bit mask equal to another bit mask.
 
int32 DifferencesCount (const FBitMask &BitMask) const
 Get the number of different bits in two masks.
 
int32 InclusionsCount (const FBitMask &BitMask) const
 Get the number of included bits in two masks.
 
bool Includes (const FBitMask &BitMask) const
 Does the mask has all of the bits set in the supplied mask.
 
bool IncludesPartially (const FBitMask &BitMask) const
 Check if the mask has any of the bits set in the supplied mask.
 
Iterator begin ()
 
ConstIterator begin () const
 
Iterator end ()
 
ConstIterator end () const
 
int32 IndexOf (const bool Bit, const int32 Offset=0) const
 Get the index of the first matching bit in the mask.
 
void EnsureGroupsNum (const int32 InGroupsCount)
 Ensure a bit group count.
 
void EnsureGroupsForBitAt (const int32 BitIndex)
 Ensure that there is enough bit groups for an index.
 
int32 GroupsMax () const
 Get the current maximum number of bit groups that can be stored without any additional allocations.
 
int32 BitsMax () const
 Get the current maximum number of bits that can be stored without any additional allocations.
 
void Reserve (const int32 BitCapacity)
 Reserve space for a given number of bits.
 
void Empty (const int32 Slack=0)
 Empties the array.
 
void Reset (const int32 NewSize=0)
 Same as empty, but doesn't change memory allocations, unless the new size is larger than the current array.
 
void SetMasked (const FBitMask &Mask, const bool State)
 Set the bits based on a mask.
 
void Insert (const int32 Index, const bool Bit)
 Insert a bit at the specified index.
 
void Remove (const bool Bit)
 Remove the first occurrence of the specified bit from the mask.
 
void RemoveAt (const int32 Index)
 Remove the bit at the specified index.
 
void Erase (const int32 Index)
 Remove an element at the specified index.
 
template<EParadigm Paradigm = EParadigm::Default>
TOutcome< Paradigm > Intersect (const FBitMask &InMask)
 Logically-and the bitmask with a given mask.
 
FBitMaskoperator&= (const FBitMask &InMask)
 Conjunct the bitmask with a given mask.
 
template<EParadigm Paradigm = EParadigm::Default>
TOutcome< Paradigm > Include (const FBitMask &InMask)
 Logical-or the bitmask with a an another mask.
 
FBitMaskoperator|= (const FBitMask &InMask)
 Disjunct the bitmask with a given mask.
 
FString ToString () const
 Convert the bit mask to a string representation.
 
uint32 CalcHash () const
 Calculate the bit mask hash.
 
bool Serialize (FArchive &Archive)
 Serialize the bit mask.
 
Initialization
 FBitMask ()
 Construct a new empty bit mask.
 
 FBitMask (const FBitMask &InBitMask)
 Copy-construct the bit mask.
 
 FBitMask (FBitMask &&InBitMask)
 Move-construct the bit mask.
 
 FBitMask (const int32 Capacity)
 Initialize a new instance of a mask with a certain bit capacity.
 
 FBitMask (std::initializer_list< bool > list)
 Construct a new bit mask with an initializer list.
 

Static Public Attributes

static const GroupType ZeroGroup {0}
 A group of all one bits set.
 
static const GroupType FirstOneGroup {1}
 A group with the first bit set.
 
static const GroupType LastOneGroup {(((GroupType)1) << (GroupSizeBits - 1))}
 A group with the last bit set.
 
static const GroupType AllOnesGroup {TNumericLimits<GroupType>::Max()}
 A group of all one bits set.
 

Friends

class StaticConstructor
 
uint32 GetTypeHash (const FBitMask &bm)
 
FBitMask operator& (const FBitMask &MaskA, const FBitMask &MaskB)
 Logically-conjunct the bits in masks.
 
FBitMask operator| (const FBitMask &MaskA, const FBitMask &MaskB)
 Logically-disjunct the bits in masks.
 

Detailed Description

A memory-efficient bit mask.

Please, note that this is not a usual bit array and serves some different purposes.

Member Typedef Documentation

◆ GroupType

typedef uint64 FBitMask::GroupType

The type of the bit group elements.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
GroupSizeBits 

The size of the group type in bits.

GroupShift 

A number of bits to shift (right) for getting a group index from a bit index.

GroupBitIndexMask 

A mask for the group to get an index of the bit from.

bitsCountLUTSize 

The number of entries in the bits count LUT.

InlineGroupsCount 

The number of inline-allocated groups.

Constructor & Destructor Documentation

◆ FBitMask() [1/5]

FBitMask::FBitMask ( )
inline

Construct a new empty bit mask.

◆ FBitMask() [2/5]

FBitMask::FBitMask ( const FBitMask InBitMask)
inline

Copy-construct the bit mask.

◆ FBitMask() [3/5]

FBitMask::FBitMask ( FBitMask &&  InBitMask)
inline

Move-construct the bit mask.

◆ FBitMask() [4/5]

FBitMask::FBitMask ( const int32  Capacity)
inline

Initialize a new instance of a mask with a certain bit capacity.

◆ FBitMask() [5/5]

FBitMask::FBitMask ( std::initializer_list< bool list)
inline

Construct a new bit mask with an initializer list.

Member Function Documentation

◆ At()

bool FBitMask::At ( const int32  Index) const
inline

Get the bit flag at the specified index.

Parameters
IndexThe index of the bit to get. If it's out of the number of elements, false is returned.
Returns
The state of the bit at the specified index.

◆ begin() [1/2]

Iterator FBitMask::begin ( )
inline

◆ begin() [2/2]

ConstIterator FBitMask::begin ( ) const
inline

◆ BitsMax()

int32 FBitMask::BitsMax ( ) const
inline

Get the current maximum number of bits that can be stored without any additional allocations.

◆ BitsNum()

int32 FBitMask::BitsNum ( ) const
inline

Get the number of available (allocated) bits.

◆ CalcHash()

uint32 FBitMask::CalcHash ( ) const
inline

Calculate the bit mask hash.

◆ CountNonZeroGroups()

int32 FBitMask::CountNonZeroGroups ( ) const
inline

Get the number of meaningful (non-zero) bit groups.

◆ DifferencesCount()

int32 FBitMask::DifferencesCount ( const FBitMask BitMask) const

Get the number of different bits in two masks.

◆ Empty()

void FBitMask::Empty ( const int32  Slack = 0)
inline

Empties the array.

It calls the destructors on held flags if needed.

Parameters
SlackThe expected usage size in bits after empty operation.

◆ end() [1/2]

Iterator FBitMask::end ( )
inline

◆ end() [2/2]

ConstIterator FBitMask::end ( ) const
inline

◆ EnsureGroupsForBitAt()

void FBitMask::EnsureGroupsForBitAt ( const int32  BitIndex)
inline

Ensure that there is enough bit groups for an index.

◆ EnsureGroupsNum()

void FBitMask::EnsureGroupsNum ( const int32  InGroupsCount)
inline

Ensure a bit group count.

◆ Erase()

void FBitMask::Erase ( const int32  Index)
inline

Remove an element at the specified index.

Parameters
IndexAn index of the element to erase.

◆ GroupsMax()

int32 FBitMask::GroupsMax ( ) const
inline

Get the current maximum number of bit groups that can be stored without any additional allocations.

◆ GroupsNum()

int32 FBitMask::GroupsNum ( ) const
inline

Get the number of available bit groups.

◆ Identical()

bool FBitMask::Identical ( const FBitMask Other,
uint32  PortFlags 
) const
inline

Compare two bit masks for equality.

Editor-friendly method.

Parameters
OtherThe other bit mask to compare to.
PortFlagsThe contextual port flags.
Returns
The state of examination.

◆ Include()

template<EParadigm Paradigm = EParadigm::Default>
TOutcome< Paradigm > FBitMask::Include ( const FBitMask InMask)
inline

Logical-or the bitmask with a an another mask.

This can actually be slower than FBitMask::operator|= since it provides a status.

Template Parameters
ParadigmThe paradigm to work on.
Parameters
InMaskThe mask to include.
Returns
The status of the operation.

◆ Includes()

bool FBitMask::Includes ( const FBitMask BitMask) const
inline

Does the mask has all of the bits set in the supplied mask.

The same as a bitwise A & B == B.

◆ IncludesPartially()

bool FBitMask::IncludesPartially ( const FBitMask BitMask) const
inline

Check if the mask has any of the bits set in the supplied mask.

The same as a bitwise A & B != 0.

◆ InclusionsCount()

int32 FBitMask::InclusionsCount ( const FBitMask BitMask) const

Get the number of included bits in two masks.

◆ IndexOf()

int32 FBitMask::IndexOf ( const bool  Bit,
const int32  Offset = 0 
) const

Get the index of the first matching bit in the mask.

The mask is considered to be zero-limitless, so a falsy bit is always found in the end.

Parameters
BitThe bit state to find.
OffsetThe offset index to start with.
Returns
The index of the bit in question or INDEX_NONE, if the bit couldn't be found.

◆ Insert()

void FBitMask::Insert ( const int32  Index,
const bool  Bit 
)

Insert a bit at the specified index.

◆ Intersect()

template<EParadigm Paradigm = EParadigm::Default>
TOutcome< Paradigm > FBitMask::Intersect ( const FBitMask InMask)
inline

Logically-and the bitmask with a given mask.

Template Parameters
ParadigmThe paradigm to work under.
Parameters
InMaskThe mask to intersect with.
Returns
The status of the operation.

◆ IsAllZeroes()

bool FBitMask::IsAllZeroes ( ) const
inline

Check if all of the bits in the mask are zeroes or none.

◆ IsNonZero()

bool FBitMask::IsNonZero ( ) const
inline

Check if there are any non-zero bits in the mask.

◆ operator!=()

bool FBitMask::operator!= ( const FBitMask Other) const
inline

Compare two bit masks for inequality.

◆ operator&=()

FBitMask & FBitMask::operator&= ( const FBitMask InMask)
inline

Conjunct the bitmask with a given mask.

◆ operator=() [1/2]

FBitMask & FBitMask::operator= ( const FBitMask InBitMask)
inline

Set this bit mask equal to another bit mask.

◆ operator=() [2/2]

FBitMask & FBitMask::operator= ( FBitMask &&  InBitMask)
inline

Move the bit mask.

◆ operator==()

bool FBitMask::operator== ( const FBitMask Other) const
inline

Compare two bit masks for equality.

◆ operator[]() [1/2]

FBitAccessor FBitMask::operator[] ( const int32  Index)
inline

Get a bit element by its index.

◆ operator[]() [2/2]

bool FBitMask::operator[] ( const int32  Index) const
inline

Get a bit element by its index.

Constant version.

◆ operator|=()

FBitMask & FBitMask::operator|= ( const FBitMask InMask)
inline

Disjunct the bitmask with a given mask.

◆ Remove()

void FBitMask::Remove ( const bool  Bit)

Remove the first occurrence of the specified bit from the mask.

◆ RemoveAt()

void FBitMask::RemoveAt ( const int32  Index)

Remove the bit at the specified index.

Parameters
IndexThe index of the bit to remove.

◆ Reserve()

void FBitMask::Reserve ( const int32  BitCapacity)
inline

Reserve space for a given number of bits.

◆ Reset()

void FBitMask::Reset ( const int32  NewSize = 0)
inline

Same as empty, but doesn't change memory allocations, unless the new size is larger than the current array.

Parameters
NewSizeThe expected usage size in bits after calling this function.

◆ Serialize()

bool FBitMask::Serialize ( FArchive &  Archive)
inline

Serialize the bit mask.

◆ Set() [1/2]

template<EParadigm Paradigm = EParadigm::Default>
TOutcome< Paradigm > FBitMask::Set ( const FBitMask InBitMask)
inline

Set this bit mask equal to another bit mask.

Template Parameters
ParadigmThe paradigm to work under.
Parameters
InBitMaskThe bit mask to set to.
Returns
The outcome of the operation.

◆ Set() [2/2]

EApparatusStatus FBitMask::Set ( FBitMask &&  InBitMask)
inline

Move the bit mask to this bit mask.

◆ SetAt()

void FBitMask::SetAt ( const int32  Index,
const bool  Value 
)
inline

Set a bit at a specific index.

◆ SetMasked()

void FBitMask::SetMasked ( const FBitMask Mask,
const bool  State 
)
inline

Set the bits based on a mask.

Parameters
MaskThe mask to use while setting the bits.
StateThe state to set.

◆ ToString()

FString FBitMask::ToString ( ) const
inline

Convert the bit mask to a string representation.

◆ Trim()

EApparatusStatus FBitMask::Trim ( const bool  bAllowShrinking = true) const
inline

Trim the meaningless high-order groups.

Parameters
bAllowShrinkingIs physical array size allowed to shrunk?

Friends And Related Function Documentation

◆ GetTypeHash

uint32 GetTypeHash ( const FBitMask bm)
friend

◆ operator&

FBitMask operator& ( const FBitMask MaskA,
const FBitMask MaskB 
)
friend

Logically-conjunct the bits in masks.

Parameters
MaskAThe first mask to conjunct.
MaskBThe second mask to conjunct.
Returns
The resulting conjunct mask.

◆ operator|

FBitMask operator| ( const FBitMask MaskA,
const FBitMask MaskB 
)
friend

Logically-disjunct the bits in masks.

Parameters
MaskAThe first mask to disjunct.
MaskBThe second mask to disjunct.
Returns
The resulting disjunct mask.

◆ StaticConstructor

friend class StaticConstructor
friend

Member Data Documentation

◆ AllOnesGroup

const GroupType FBitMask::AllOnesGroup {TNumericLimits<GroupType>::Max()}
static

A group of all one bits set.

◆ FirstOneGroup

const GroupType FBitMask::FirstOneGroup {1}
static

A group with the first bit set.

◆ LastOneGroup

const GroupType FBitMask::LastOneGroup {(((GroupType)1) << (GroupSizeBits - 1))}
static

A group with the last bit set.

◆ ZeroGroup

const GroupType FBitMask::ZeroGroup {0}
static

A group of all one bits set.


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