7#include "MRPch/MRBindingMacros.h"
45 index_ = bitset_->find_next( index_ );
56 [[nodiscard]]
const T *
bitset()
const {
return bitset_; }
62 const T * bitset_ =
nullptr;
63 IndexType index_ = IndexType( ~
size_t( 0 ) );
73 inline static constexpr size_t npos = (size_t)-1;
82 explicit
BitSet(
size_t numBits,
bool fillValue = false ) {
resize( numBits, fillValue ); }
88 res.blocks_ = std::move( blocks );
95 void clear() { numBits_ = 0; blocks_.clear(); }
98 [[nodiscard]]
bool empty() const noexcept {
return numBits_ == 0; }
127 void push_back(
bool val ) {
auto n = numBits_++;
if ( bitIndex_( n ) == 0 ) blocks_.push_back(
block_type{} );
set( n, val ); }
130 void pop_back() { assert( numBits_ > 0 ); {
if ( bitIndex_( numBits_ ) == 1 ) blocks_.pop_back();
else reset( numBits_ - 1 ); } --numBits_; }
133 [[nodiscard]]
const auto &
bits()
const {
return blocks_; }
150 [[nodiscard]]
bool none()
const {
return !
any(); }
186 if ( reserved > 0 && newSize > reserved )
188 while ( newSize > reserved )
198 if ( pos + len >
size() )
200 set( pos, len, val );
207 bool const b =
test( pos );
239 return ( (
block_type( 1 ) << firstBit ) - 1 )
253 template<
class FullBlock,
class PartialBlock>
269 std::vector<block_type> blocks_;
335 template <
typename M>
344 template <
typename M>
373 {
return static_cast<const BitSet &
>( a ) ==
static_cast<const BitSet &
>( b ); }
375template <
typename T,
typename U>
381 std::function<bool(
I )> res;
383 res = [bitset](
I id ) {
return bitset->
test(
id ); };
394 return id.valid() && ( !bitset || bitset->
test(
id ) );
400 return id.valid() && bitset.
test(
id );
438 for (
auto b : *
this )
439 if (
auto mapped = map( b ) )
452 for (
auto b : *
this )
453 if (
auto mapped = map( b ) )
constexpr bool operator==(ImVec2 a, ImVec2 b)
Definition MRImGuiVectorOperators.h:117
constexpr auto operator*(A a, B b)
Definition MRImGuiVectorOperators.h:107
#define MRMESH_API
Definition MRMeshFwd.h:80
size_t size_type
Definition MRBitSet.h:75
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.
Definition MRBitSet.h:165
size_t IndexType
Definition MRBitSet.h:76
bool all() const
returns true if all bits in this container are set
static constexpr size_t bits_per_block
Definition MRBitSet.h:72
IndexType endId() const
Definition MRBitSet.h:221
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRBitSet.h:220
Uint64 block_type
Definition MRBitSet.h:71
void reserve(size_type numBits)
Definition MRBitSet.h:93
BitSet() noexcept=default
creates empty bitset
bool any() const
returns true if at least one bits in this container is set
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.
Definition MRBitSet.h:168
IndexType find_last() const
return the highest index i such that bit i is set, or npos if *this has no on bits.
BitSet & set(IndexType n, size_type len, bool val)
BitSet & operator|=(const BitSet &b)
bool empty() const noexcept
Definition MRBitSet.h:98
friend std::ostream & operator<<(std::ostream &s, const BitSet &bs)
MR_BIND_IGNORE_PY friend auto end(const BitSet &)
Definition MRBitSet.h:266
BitSet & set(IndexType n)
Not using a default argument for val to get better C bindings.
Definition MRBitSet.h:112
void autoResizeSet(size_t pos, bool val=true)
Definition MRBitSet.h:202
BitSet & reset(IndexType n, size_type len)
BitSet & operator-=(const BitSet &b)
bool autoResizeTestSet(size_t pos, bool val=true)
same as autoResizeSet and returns previous value of pos-bit
Definition MRBitSet.h:205
bool test_set(IndexType n, bool val=true)
return n < size() && uncheckedTest( n ); was compiled with extra conditional jump inside uncheckedTes...
Definition MRBitSet.h:108
bool uncheckedTest(IndexType n) const
Definition MRBitSet.h:103
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 bitse...
static BitSet fromBlocks(std::vector< block_type > &&blocks)
creates bitset from the given blocks of bits
Definition MRBitSet.h:85
void clear()
Definition MRBitSet.h:95
BitSet & flip(IndexType n, size_type len)
void resize(size_type numBits, bool fillValue=false)
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_type size() const noexcept
Definition MRBitSet.h:99
bool uncheckedTestSet(IndexType n, bool val=true)
Definition MRBitSet.h:104
BitSet & reset(IndexType n)
Definition MRBitSet.h:116
bool test(IndexType n) const
all bits after size() we silently consider as not-set
Definition MRBitSet.h:107
friend std::istream & operator>>(std::istream &s, BitSet &bs)
void reverse()
changes the order of bits on the opposite
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.
Definition MRBitSet.h:159
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
Definition MRBitSet.h:196
size_type num_blocks() const noexcept
Definition MRBitSet.h:100
BitSet & set(IndexType n, bool val)
Definition MRBitSet.h:111
IndexType backId() const
returns the identifier of the back() element
Definition MRBitSet.h:217
void resizeWithReserve(size_t newSize)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRBitSet.h:183
IndexType find_first() const
return the smallest index i such that bit i is set, or npos if *this has no on bits.
Definition MRBitSet.h:156
void push_back(bool val)
adds one more bit with the given value in the container, increasing its size on 1
Definition MRBitSet.h:127
MR_BIND_IGNORE_PY friend auto begin(const BitSet &a)
Definition MRBitSet.h:265
size_type capacity() const noexcept
Definition MRBitSet.h:101
BitSet & subtract(const BitSet &b, int bShiftInBlocks)
subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
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 les...
const auto & bits() const
read-only access to all bits stored as a vector of uint64 blocks
Definition MRBitSet.h:133
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRBitSet.h:214
bool none() const
returns true if all bits in this container are reset
Definition MRBitSet.h:150
BitSet & operator&=(const BitSet &b)
static constexpr size_t npos
Definition MRBitSet.h:73
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 ...
void pop_back()
removes last bit from the container, decreasing its size on 1
Definition MRBitSet.h:130
BitSet & flip(IndexType n)
Definition MRBitSet.h:120
void shrink_to_fit()
Definition MRBitSet.h:96
size_type count() const noexcept
computes the number of set bits in the whole set
BitSet & operator^=(const BitSet &b)
SetBitIteratorT operator++(int)
Definition MRBitSet.h:49
const IndexType * pointer
Definition MRBitSet.h:32
SetBitIteratorT()=default
constructs end iterator
std::forward_iterator_tag iterator_category
Definition MRBitSet.h:28
const T * bitset() const
Definition MRBitSet.h:56
IndexType value_type
Definition MRBitSet.h:29
typename T::IndexType IndexType
Definition MRBitSet.h:26
SetBitIteratorT & operator++()
Definition MRBitSet.h:43
SetBitIteratorT(const T &bitset)
constructs begin iterator
Definition MRBitSet.h:38
IndexType reference
intentionally not a reference
Definition MRBitSet.h:31
std::ptrdiff_t difference_type
Definition MRBitSet.h:30
Definition MRBitSet.h:277
IndexType find_last() const
Definition MRBitSet.h:304
TypedBitSet & operator|=(const TypedBitSet &b)
Definition MRBitSet.h:312
bool intersects(const TypedBitSet &a) const
Definition MRBitSet.h:328
bool test_set(IndexType n, bool val=true)
Definition MRBitSet.h:300
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map) const
Definition MRBitSet.h:341
friend TypedBitSet operator|(const TypedBitSet &a, const TypedBitSet &b)
Definition MRBitSet.h:317
friend TypedBitSet operator&(const TypedBitSet &a, const TypedBitSet &b)
Definition MRBitSet.h:316
static IndexType beginId()
Definition MRBitSet.h:355
TypedBitSet(const BitSet &src)
copies all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRBitSet.h:284
TypedBitSet & flip(IndexType n)
Definition MRBitSet.h:297
IndexType backId() const
Definition MRBitSet.h:352
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map, size_t resSize) const
Definition MRBitSet.h:348
TypedBitSet & operator-=(const TypedBitSet &b)
Definition MRBitSet.h:314
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRBitSet.h:289
MR_BIND_IGNORE_PY friend auto end(const TypedBitSet &)
Definition MRBitSet.h:359
bool is_subset_of(const TypedBitSet &a) const
Definition MRBitSet.h:325
TypedBitSet & reset(IndexType n, size_type len)
Definition MRBitSet.h:293
friend TypedBitSet operator-(const TypedBitSet &a, const TypedBitSet &b)
Definition MRBitSet.h:319
TypedBitSet & operator^=(const TypedBitSet &b)
Definition MRBitSet.h:313
TypedBitSet & set()
Definition MRBitSet.h:292
void autoResizeSet(IndexType pos, size_type len, bool val=true)
Definition MRBitSet.h:330
IndexType endId() const
Definition MRBitSet.h:356
MR_BIND_IGNORE_PY friend auto begin(const TypedBitSet &a)
Definition MRBitSet.h:358
I IndexType
Definition MRBitSet.h:281
TypedBitSet & flip()
Definition MRBitSet.h:298
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map, size_t resSize) const
Definition MRBitSet.h:346
IndexType find_first_not_set() const
Definition MRBitSet.h:305
IndexType find_first() const
Definition MRBitSet.h:302
friend TypedBitSet operator^(const TypedBitSet &a, const TypedBitSet &b)
Definition MRBitSet.h:318
IndexType find_next_not_set(IndexType pos) const
Definition MRBitSet.h:306
TypedBitSet & set(IndexType n, bool val)
Definition MRBitSet.h:290
TypedBitSet & flip(IndexType n, size_type len)
Definition MRBitSet.h:296
TypedBitSet & operator&=(const TypedBitSet &b)
Definition MRBitSet.h:311
TypedBitSet getMapping(const M &map, size_t resSize) const
void autoResizeSet(IndexType pos, bool val=true)
Definition MRBitSet.h:331
IndexType find_next(IndexType pos) const
Definition MRBitSet.h:303
TypedBitSet & reset()
Definition MRBitSet.h:295
bool autoResizeTestSet(IndexType pos, bool val=true)
Definition MRBitSet.h:332
IndexType find_last_not_set() const
Definition MRBitSet.h:307
TypedBitSet(BitSet &&src)
Definition MRBitSet.h:287
TypedBitSet & set(IndexType n)
Definition MRBitSet.h:291
TypedBitSet & subtract(const TypedBitSet &b, int bShiftInBlocks)
Definition MRBitSet.h:322
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map) const
Definition MRBitSet.h:337
TypedBitSet & reset(IndexType n)
Definition MRBitSet.h:294
TypedBitSet getMapping(const M &map) const
IndexType nthSetBit(size_t n) const
Definition MRBitSet.h:309
bool test(IndexType n) const
Definition MRBitSet.h:299
TypedBitSet getMapping(const BMap< IndexType, IndexType > &map) const
Definition MRBitSet.h:339
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:461
HashMap< I, int > makeHashMapWithSeqNums(const TypedBitSet< I > &bs)
creates a HashMap where for each set bit of input bitset its sequential number starting from 0 is ret...
Definition MRBitSet.h:424
BitSet operator&(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:458
bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
Vector< int, I > makeVectorWithSeqNums(const TypedBitSet< I > &bs)
creates a Vector where for each set bit of input bitset its sequential number starting from 0 is retu...
Definition MRBitSet.h:415
bool contains(const TypedBitSet< I > *bitset, I id)
Definition MRBitSet.h:392
void fillVectorWithSeqNums(const TypedBitSet< I > &bs, Vector< int, I > &vec)
for each set bit of input bitset, writes its sequential number starting from 0 in the given vector th...
Definition MRBitSet.h:406
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:459
std::function< bool(I)> makePredicate(const TypedBitSet< I > *bitset)
Definition MRBitSet.h:379
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:460
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRBitSet.h:364
Buffer< T, I > b
Definition MRBuffer.h:137
std::uint64_t Uint64
Definition MRMeshFwd.h:201
class MRMESH_CLASS SetBitIteratorT(SetBitIterator, SetBitIteratorT< BitSet >)(FaceSetBitIterator
T getAt(const Buffer< T, I > &bmap MR_LIFETIMEBOUND_NESTED, I key, T def={})
given some buffer map and a key, returns the value associated with the key, or default value if key i...
Definition MRBuffer.h:128
class MRMESH_CLASS I
Definition MRMeshFwd.h:137
size_t tsize
target size, all values inside b must be less than this value
Definition MRBuffer.h:138
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMeshFwd.h:606
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
flat map: I -> T
Definition MRBuffer.h:136