BaseBitSet< ALLOCATOR > Class Template Reference

#include <basebitset.h>

Detailed Description

template<typename ALLOCATOR = DefaultAllocator>
class maxon::BaseBitSet< ALLOCATOR >

BaseBitSet documentation.

Public Types

using IntType = UInt
 

Public Member Functions

 BaseBitSet ()=default
 
 BaseBitSet (BaseBitSet &&rhs)
 
BaseBitSetoperator= (BaseBitSet &&rhs)
 
Bool IsSet (UInt index) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsSetUnchecked (UInt index) const
 
MAXON_ATTRIBUTE_FORCE_INLINE void ClearUnchecked (UInt index)
 
Result< void > Set (UInt index, Bool &isSet)
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
Result< void > Set (UInt index)
 
void SetUnchecked (UInt index)
 
Bool SetAndCheckUnchecked (UInt index)
 
Result< void > SetRange (UInt first, UInt last)
 
void SetRangeUnchecked (UInt first, UInt last)
 
void Clear (UInt index, Bool &cleared)
 
void Clear (UInt index)
 
void Reset ()
 
HashInt GetHashCode () const
 
Bool operator== (const BaseBitSet< ALLOCATOR > &rhs) const
 
BaseBitSet< ALLOCATOR > & operator|= (const BaseBitSet< ALLOCATOR > &rhs)
 
BaseBitSet< ALLOCATOR > & operator&= (const BaseBitSet< ALLOCATOR > &rhs)
 
Result< void > CopyFrom (const BaseBitSet< ALLOCATOR > &src)
 
Result< void > MergeOr (const BaseBitSet< ALLOCATOR > &src)
 
Result< void > MergeOrNot (const BaseBitSet< ALLOCATOR > &src)
 
Result< void > MergeAnd (const BaseBitSet< ALLOCATOR > &src)
 
Result< void > MergeAndNot (const BaseBitSet< ALLOCATOR > &src)
 
Result< void > MergeXOr (const BaseBitSet< ALLOCATOR > &src)
 
void Invert ()
 
Result< void > Init (UInt count, Bool clearValue)
 
Int CountBits (UInt first=0, UInt last=(UInt) -1) const
 
Int GetNextSet (Int index) const
 
Int GetNextCleared (Int index) const
 
Int GetCapacity () const
 
const Block< const IntType > & GetRawData () const
 

Static Public Member Functions

static Result< void > DescribeIO (const DataSerializeInterface &stream)
 
static Bool IsSet (const Block< const IntType > &raw, Int index)
 

Private Member Functions

 MAXON_DISALLOW_COPY_AND_ASSIGN (BaseBitSet)
 
void RemoveTrailingZeroes ()
 
Int CountBitsInWord (IntType word) const
 

Private Attributes

BaseArray< IntType, BASEARRAY_DEFAULT_CHUNK_SIZE, BASEARRAYFLAGS::MOVEANDCOPYOBJECTS, ALLOCATOR > _bits
 

Static Private Attributes

static const UInt INT_WIDTH_EXPONENT
 
static const IntType INT_MASK
 
static const IntType INT_WIDTH
 

Member Typedef Documentation

◆ IntType

using IntType = UInt

Constructor & Destructor Documentation

◆ BaseBitSet() [1/2]

BaseBitSet ( )
default

Default constructor.

◆ BaseBitSet() [2/2]

BaseBitSet ( BaseBitSet< ALLOCATOR > &&  rhs)

Move constructor

Parameters
[in]rhsThe bitset which is moved.

Member Function Documentation

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( BaseBitSet< ALLOCATOR >  )
private

◆ operator=()

BaseBitSet& operator= ( BaseBitSet< ALLOCATOR > &&  rhs)

Move assignment operator

Parameters
[in]rhsThe bitset which is moved.
Returns
A reference to this bitset.

◆ IsSet() [1/2]

Bool IsSet ( UInt  index) const

Checks if a bit is set in the bitset.

Parameters
[in]indexInput index of the bit which should be set.
Returns
True if the bit at index is set, otherwise false.

◆ IsSetUnchecked()

MAXON_ATTRIBUTE_FORCE_INLINE Bool IsSetUnchecked ( UInt  index) const

Checks if a bit is set in the bitset. It does not check if the underlying array is big enough to contain a bit at this index.

Parameters
[in]indexInput index of the bit which should be set.
Returns
True if the bit at @index index is set, otherwise false.

◆ ClearUnchecked()

MAXON_ATTRIBUTE_FORCE_INLINE void ClearUnchecked ( UInt  index)

Clears a bit in the bitset. It does not check if the underlying array is big enough to contain a bit at this index.

Parameters
[in]indexInput index of the bit which should be set.

◆ Set() [1/2]

Result<void> Set ( UInt  index,
Bool isSet 
)

Sets the bit at a given index and returns if it was actually set.

Parameters
[in]indexInput index of the bit which should be set.
[out]isSetThis will be set to true if the bit is actually set, otherwise to false.
Returns
OK on success.

◆ IsEmpty()

Bool IsEmpty ( ) const

Check if the bitset is empty.

Returns
True if no bit is set, otherwise false.

◆ IsPopulated()

Bool IsPopulated ( void  ) const

Check if the bitset contains at least one element.

Returns
False if no bit is set, otherwise true.

◆ Set() [2/2]

Result<void> Set ( UInt  index)

Sets the bit at a given index.

Parameters
[in]indexInput index of the bit which should be set.
Returns
OK on success.

◆ SetUnchecked()

void SetUnchecked ( UInt  index)

Sets the bit at a given index. It does not check if the underlying array is big enough to contain a bit at this index.

Parameters
[in]indexInput index of the bit which should be set.

◆ SetAndCheckUnchecked()

Bool SetAndCheckUnchecked ( UInt  index)

Sets the bit at a given index. It does not check if the underlying array is big enough to contain a bit at this index.

Parameters
[in]indexInput index of the bit which should be set.
Returns
true, if the bit was already set.

◆ SetRange()

Result<void> SetRange ( UInt  first,
UInt  last 
)

Sets all bits in the given range. first must be smaller or equal to last.

Parameters
[in]firstFirst element to set.
[in]lastLast element to set.
Returns
OK on success.

◆ SetRangeUnchecked()

void SetRangeUnchecked ( UInt  first,
UInt  last 
)

Sets all bits in the given range. first must be smaller or equal to last.

Parameters
[in]firstFirst element to set.
[in]lastLast element to set.

◆ Clear() [1/2]

void Clear ( UInt  index,
Bool cleared 
)

Clears the bit at a given index and returns if it was actually cleared.

Parameters
[in]indexInput index of the bit which should be cleared.
[out]clearedThis will be set to true if the bit is actually cleared, otherwise to false.

◆ Clear() [2/2]

void Clear ( UInt  index)

Clears the bit at a given index.

Parameters
[in]indexInput index of the bit which should be cleared.

◆ Reset()

void Reset ( void  )

Resets the bitset.

◆ GetHashCode()

HashInt GetHashCode ( ) const

Gets the hash code for the bitset, using GetHashCode() of the underlying BaseArray.

Returns
The bitset's hash code.

◆ operator==()

Bool operator== ( const BaseBitSet< ALLOCATOR > &  rhs) const

Compares two bitsets, using the compare operator of the underlying BaseArray.

Parameters
[in]rhsInput bitset rhs.
Returns
The component-by-component result of this == rhs.

◆ operator|=()

BaseBitSet<ALLOCATOR>& operator|= ( const BaseBitSet< ALLOCATOR > &  rhs)

Calculates the bitwise OR of this bitset and another bitset.

Parameters
[in]rhsInput bitset rhs.
Returns
A reference to this bitset.

◆ operator&=()

BaseBitSet<ALLOCATOR>& operator&= ( const BaseBitSet< ALLOCATOR > &  rhs)

Calculates the bitwise AND of this bitset and another bitset.

Parameters
[in]rhsInput bitset rhs.
Returns
A reference to this bitset.

◆ CopyFrom()

Result<void> CopyFrom ( const BaseBitSet< ALLOCATOR > &  src)

Copies the data from another bitset, using CopyFrom() of the underlying BaseArray

Parameters
[in]srcSource from which the data is taken
Returns
OK on success.

◆ MergeOr()

Result<void> MergeOr ( const BaseBitSet< ALLOCATOR > &  src)

Merges the data from another bitset with logical OR. If the other bitset is larger it will resize this one.

Parameters
[in]srcSource from which the data is merged.
Returns
OK on success.

◆ MergeOrNot()

Result<void> MergeOrNot ( const BaseBitSet< ALLOCATOR > &  src)

Merges the data from another bitset with logical OR NOT. If the other bitset is larger it will resize this one.

Parameters
[in]srcSource from which the data is merged.
Returns
OK on success.

◆ MergeAnd()

Result<void> MergeAnd ( const BaseBitSet< ALLOCATOR > &  src)

Merges the data from another bitset with logical AND. If the other bitset is larger it will resize this one.

Parameters
[in]srcSource from which the data is merged.
Returns
OK on success.

◆ MergeAndNot()

Result<void> MergeAndNot ( const BaseBitSet< ALLOCATOR > &  src)

Merges the data from another bitset with logical AND NOT. If the other bitset is larger it will resize this one.

Parameters
[in]srcSource from which the data is merged.
Returns
OK on success.

◆ MergeXOr()

Result<void> MergeXOr ( const BaseBitSet< ALLOCATOR > &  src)

Merges the data from another bitset with logical XOR. If the other bitset is larger it will resize this one.

Parameters
[in]srcSource from which the data is merged.
Returns
OK on success.

◆ Invert()

void Invert ( )

Inverts all bits of the BaseBitSet.

◆ Init()

Result<void> Init ( UInt  count,
Bool  clearValue 
)

Initializes the array to have at least as much space to contain a certain amount of bits.

Parameters
[in]countNumber of bits.

◆ CountBits()

Int CountBits ( UInt  first = 0,
UInt  last = (UInt)-1 
) const

Counts the bits in the selection

Parameters
[in]firstIndex from which conting starts.
[in]lastIndex where counting ends.
Returns
Number of set bits.

◆ GetNextSet()

Int GetNextSet ( Int  index) const

◆ GetNextCleared()

Int GetNextCleared ( Int  index) const

◆ GetCapacity()

Int GetCapacity ( ) const

Get The maximum capacity of the BitSet

Returns
Number maximum bits.

◆ DescribeIO()

static Result<void> DescribeIO ( const DataSerializeInterface stream)
static

Describe all elements of this class for I/O operations.

Parameters
[in]streamThe stream that is used to register the class members.
Returns
OK on success.

◆ GetRawData()

const Block<const IntType>& GetRawData ( ) const

◆ IsSet() [2/2]

static Bool IsSet ( const Block< const IntType > &  raw,
Int  index 
)
static

◆ RemoveTrailingZeroes()

void RemoveTrailingZeroes ( )
private

Removes trailing zero bits in the underlying BaseArray

◆ CountBitsInWord()

Int CountBitsInWord ( IntType  word) const
private

Counts the bits of a word.

Parameters
[in]wordWord in which the bits have to be counted.
Returns
Number of set bits in the word.

Member Data Documentation

◆ INT_WIDTH_EXPONENT

const UInt INT_WIDTH_EXPONENT
staticprivate

◆ INT_MASK

const IntType INT_MASK
staticprivate

◆ INT_WIDTH

const IntType INT_WIDTH
staticprivate

◆ _bits