MeshLib C++ Docs
Loading...
Searching...
No Matches

#include <MRMesh/MRBitSet.h>

Inheritance diagram for MR::BitSet:

Public Types

using block_type = Uint64
using size_type = size_t
using IndexType = size_t

Public Member Functions

 BitSet () noexcept=default
 creates empty bitset
 BitSet (size_t numBits, bool fillValue=false)
 creates bitset of given size filled with given value
void reserve (size_type numBits)
void resize (size_type numBits, bool fillValue=false)
void clear ()
void shrink_to_fit ()
bool empty () const noexcept
size_type size () const noexcept
size_type num_blocks () const noexcept
size_type capacity () const noexcept
bool uncheckedTest (IndexType n) const
bool uncheckedTestSet (IndexType n, bool val=true)
bool test (IndexType n) const
 all bits after size() we silently consider as not-set
bool test_set (IndexType n, bool val=true)
 return n < size() && uncheckedTest( n ); was compiled with extra conditional jump inside uncheckedTest() by MSVC
BitSetset (IndexType n, size_type len, bool val)
BitSetset (IndexType n, bool val)
BitSetset (IndexType n)
 Not using a default argument for val to get better C bindings.
BitSetset ()
BitSetreset (IndexType n, size_type len)
BitSetreset (IndexType n)
BitSetreset ()
BitSetflip (IndexType n, size_type len)
BitSetflip (IndexType n)
BitSetflip ()
void reverse ()
 changes the order of bits on the opposite
void push_back (bool val)
 adds one more bit with the given value in the container, increasing its size on 1
void pop_back ()
 removes last bit from the container, decreasing its size on 1
const auto & bits () const
 read-only access to all bits stored as a vector of uint64 blocks
BitSetoperator&= (const BitSet &b)
BitSetoperator|= (const BitSet &b)
BitSetoperator^= (const BitSet &b)
BitSetoperator-= (const BitSet &b)
BitSetsubtract (const BitSet &b, int bShiftInBlocks)
 subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
bool all () const
 returns true if all bits in this container are set
bool any () const
 returns true if at least one bits in this container is set
bool none () const
 returns true if all bits in this container are reset
size_type count () const noexcept
 computes the number of set bits in the whole set
IndexType find_first () const
 return the smallest index i such that bit i is set, or npos if *this has no on bits.
IndexType find_next (IndexType n) const
 return the smallest index i>n such that bit i is set, or npos if *this has no on bits.
IndexType find_last () const
 return the highest index i such that bit i is set, or npos if *this has no on bits.
IndexType find_first_not_set () const
 return the smallest index i such that bit i is NOT set, or npos if *this has no off bits.
IndexType find_next_not_set (IndexType n) const
 return the smallest index i>n such that bit i is NOT set, or npos if *this has no off bits.
IndexType find_last_not_set () const
 return the highest index i such that bit i is NOT set, or npos if *this has no off bits.
size_t nthSetBit (size_t n) const
 returns the location of nth set bit (where the first bit corresponds to n=0) or npos if there are less bit set
bool is_subset_of (const BitSet &a) const
 returns true if, for every bit that is set in this bitset, the corresponding bit in bitset a is also set. Otherwise this function returns false.
bool intersects (const BitSet &a) const
 returns true if, there is a bit which is set in this bitset, such that the corresponding bit in bitset a is also set. Otherwise this function returns false.
void resizeWithReserve (size_t newSize)
 doubles reserved memory until resize(newSize) can be done without reallocation
void autoResizeSet (size_t pos, size_type len, bool val=true)
 sets elements [pos, pos+len) to given value, adjusting the size of the set to include new elements
void autoResizeSet (size_t pos, bool val=true)
bool autoResizeTestSet (size_t pos, bool val=true)
 same as autoResizeSet and returns previous value of pos-bit
size_t heapBytes () const
 returns the amount of memory this object occupies on heap
IndexType backId () const
 returns the identifier of the back() element
IndexType endId () const

Static Public Member Functions

static BitSet fromBlocks (std::vector< block_type > &&blocks)
 creates bitset from the given blocks of bits
static IndexType beginId ()
 [beginId(), endId()) is the range of all bits in the set

Static Public Attributes

static constexpr size_t bits_per_block = sizeof( block_type ) * 8
static constexpr size_t npos = (size_t)-1

Friends

std::ostream & operator<< (std::ostream &s, const BitSet &bs)
std::istream & operator>> (std::istream &s, BitSet &bs)
MR_BIND_IGNORE_PY friend auto begin (const BitSet &a)
MR_BIND_IGNORE_PY friend auto end (const BitSet &)

Detailed Description

std::vector<bool> like container (random-access, size_t - index type, bool - value type) with all bits after size() considered off during testing

Member Typedef Documentation

◆ block_type

◆ IndexType

using MR::BitSet::IndexType = size_t

◆ size_type

using MR::BitSet::size_type = size_t

Constructor & Destructor Documentation

◆ BitSet() [1/2]

MR::BitSet::BitSet ( )
defaultnoexcept

creates empty bitset

◆ BitSet() [2/2]

MR::BitSet::BitSet ( size_t numBits,
bool fillValue = false )
inlineexplicit

creates bitset of given size filled with given value

Member Function Documentation

◆ all()

bool MR::BitSet::all ( ) const
nodiscard

returns true if all bits in this container are set

◆ any()

bool MR::BitSet::any ( ) const
nodiscard

returns true if at least one bits in this container is set

◆ autoResizeSet() [1/2]

void MR::BitSet::autoResizeSet ( size_t pos,
bool val = true )
inline

◆ autoResizeSet() [2/2]

void MR::BitSet::autoResizeSet ( size_t pos,
size_type len,
bool val = true )
inline

sets elements [pos, pos+len) to given value, adjusting the size of the set to include new elements

◆ autoResizeTestSet()

bool MR::BitSet::autoResizeTestSet ( size_t pos,
bool val = true )
inlinenodiscard

same as autoResizeSet and returns previous value of pos-bit

◆ backId()

IndexType MR::BitSet::backId ( ) const
inlinenodiscard

returns the identifier of the back() element

◆ beginId()

IndexType MR::BitSet::beginId ( )
inlinestaticnodiscard

[beginId(), endId()) is the range of all bits in the set

◆ bits()

const auto & MR::BitSet::bits ( ) const
inlinenodiscard

read-only access to all bits stored as a vector of uint64 blocks

◆ capacity()

size_type MR::BitSet::capacity ( ) const
inlinenodiscardnoexcept

◆ clear()

void MR::BitSet::clear ( )
inline

◆ count()

size_type MR::BitSet::count ( ) const
nodiscardnoexcept

computes the number of set bits in the whole set

◆ empty()

bool MR::BitSet::empty ( ) const
inlinenodiscardnoexcept

◆ endId()

IndexType MR::BitSet::endId ( ) const
inlinenodiscard

◆ find_first()

IndexType MR::BitSet::find_first ( ) const
inlinenodiscard

return the smallest index i such that bit i is set, or npos if *this has no on bits.

◆ find_first_not_set()

IndexType MR::BitSet::find_first_not_set ( ) const
inlinenodiscard

return the smallest index i such that bit i is NOT set, or npos if *this has no off bits.

◆ find_last()

IndexType MR::BitSet::find_last ( ) const
nodiscard

return the highest index i such that bit i is set, or npos if *this has no on bits.

◆ find_last_not_set()

IndexType MR::BitSet::find_last_not_set ( ) const
nodiscard

return the highest index i such that bit i is NOT set, or npos if *this has no off bits.

◆ find_next()

IndexType MR::BitSet::find_next ( IndexType n) const
inlinenodiscard

return the smallest index i>n such that bit i is set, or npos if *this has no on bits.

◆ find_next_not_set()

IndexType MR::BitSet::find_next_not_set ( IndexType n) const
inlinenodiscard

return the smallest index i>n such that bit i is NOT set, or npos if *this has no off bits.

◆ flip() [1/3]

BitSet & MR::BitSet::flip ( )

◆ flip() [2/3]

BitSet & MR::BitSet::flip ( IndexType n)
inline

◆ flip() [3/3]

BitSet & MR::BitSet::flip ( IndexType n,
size_type len )

◆ fromBlocks()

BitSet MR::BitSet::fromBlocks ( std::vector< block_type > && blocks)
inlinestatic

creates bitset from the given blocks of bits

◆ heapBytes()

size_t MR::BitSet::heapBytes ( ) const
inlinenodiscard

returns the amount of memory this object occupies on heap

◆ intersects()

bool MR::BitSet::intersects ( const BitSet & a) const
nodiscard

returns true if, there is a bit which is set in this bitset, such that the corresponding bit in bitset a is also set. Otherwise this function returns false.

◆ is_subset_of()

bool MR::BitSet::is_subset_of ( const BitSet & a) const
nodiscard

returns true if, for every bit that is set in this bitset, the corresponding bit in bitset a is also set. Otherwise this function returns false.

◆ none()

bool MR::BitSet::none ( ) const
inlinenodiscard

returns true if all bits in this container are reset

◆ nthSetBit()

size_t MR::BitSet::nthSetBit ( size_t n) const
nodiscard

returns the location of nth set bit (where the first bit corresponds to n=0) or npos if there are less bit set

◆ num_blocks()

size_type MR::BitSet::num_blocks ( ) const
inlinenodiscardnoexcept

◆ operator&=()

BitSet & MR::BitSet::operator&= ( const BitSet & b)

◆ operator-=()

BitSet & MR::BitSet::operator-= ( const BitSet & b)

◆ operator^=()

BitSet & MR::BitSet::operator^= ( const BitSet & b)

◆ operator|=()

BitSet & MR::BitSet::operator|= ( const BitSet & b)

◆ pop_back()

void MR::BitSet::pop_back ( )
inline

removes last bit from the container, decreasing its size on 1

◆ push_back()

void MR::BitSet::push_back ( bool val)
inline

adds one more bit with the given value in the container, increasing its size on 1

◆ reserve()

void MR::BitSet::reserve ( size_type numBits)
inline

◆ reset() [1/3]

BitSet & MR::BitSet::reset ( )

◆ reset() [2/3]

BitSet & MR::BitSet::reset ( IndexType n)
inline

◆ reset() [3/3]

BitSet & MR::BitSet::reset ( IndexType n,
size_type len )

◆ resize()

void MR::BitSet::resize ( size_type numBits,
bool fillValue = false )

◆ resizeWithReserve()

void MR::BitSet::resizeWithReserve ( size_t newSize)
inline

doubles reserved memory until resize(newSize) can be done without reallocation

◆ reverse()

void MR::BitSet::reverse ( )

changes the order of bits on the opposite

◆ set() [1/4]

BitSet & MR::BitSet::set ( )

◆ set() [2/4]

BitSet & MR::BitSet::set ( IndexType n)
inline

Not using a default argument for val to get better C bindings.

◆ set() [3/4]

BitSet & MR::BitSet::set ( IndexType n,
bool val )
inline

◆ set() [4/4]

BitSet & MR::BitSet::set ( IndexType n,
size_type len,
bool val )

◆ shrink_to_fit()

void MR::BitSet::shrink_to_fit ( )
inline

◆ size()

size_type MR::BitSet::size ( ) const
inlinenodiscardnoexcept

◆ subtract()

BitSet & MR::BitSet::subtract ( const BitSet & b,
int bShiftInBlocks )

subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block

◆ test()

bool MR::BitSet::test ( IndexType n) const
inlinenodiscard

all bits after size() we silently consider as not-set

◆ test_set()

bool MR::BitSet::test_set ( IndexType n,
bool val = true )
inlinenodiscard

return n < size() && uncheckedTest( n ); was compiled with extra conditional jump inside uncheckedTest() by MSVC

◆ uncheckedTest()

bool MR::BitSet::uncheckedTest ( IndexType n) const
inlinenodiscard

◆ uncheckedTestSet()

bool MR::BitSet::uncheckedTestSet ( IndexType n,
bool val = true )
inlinenodiscard

◆ begin

MR_BIND_IGNORE_PY friend auto begin ( const BitSet & a)
friend

◆ end

MR_BIND_IGNORE_PY friend auto end ( const BitSet & )
friend

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const BitSet & bs )
friend

◆ operator>>

std::istream & operator>> ( std::istream & s,
BitSet & bs )
friend

Member Data Documentation

◆ bits_per_block

size_t MR::BitSet::bits_per_block = sizeof( block_type ) * 8
inlinestaticconstexpr

◆ npos

size_t MR::BitSet::npos = (size_t)-1
inlinestaticconstexpr

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