MeshLib C++ Docs
Loading...
Searching...
No Matches
MRBitSet.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRId.h"
5#include "MRphmap.h"
6#include "MRVector.h"
7#include "MRPch/MRBindingMacros.h"
8#include <functional>
9#include <iosfwd>
10#include <iterator>
11
12namespace MR
13{
14
20
22template <typename T>
23class MR_BIND_IGNORE_PY SetBitIteratorT
24{
25public:
26 using IndexType = typename T::IndexType;
27
28 using iterator_category = std::forward_iterator_tag;
30 using difference_type = std::ptrdiff_t;
32 using pointer = const IndexType *;
33
35 SetBitIteratorT() = default;
36
39 : bitset_( &bitset ), index_( bitset.find_first() )
40 {
41 }
42
44 {
45 index_ = bitset_->find_next( index_ );
46 return * this;
47 }
48
49 [[nodiscard]] SetBitIteratorT operator++( int )
50 {
51 SetBitIteratorT ret = *this;
52 operator++();
53 return ret;
54 }
55
56 [[nodiscard]] const T * bitset() const { return bitset_; }
57 [[nodiscard]] reference operator *() const { return index_; }
58
59 [[nodiscard]] friend bool operator ==( const SetBitIteratorT<T> & a, const SetBitIteratorT<T> & b ) { return *a == *b; }
60
61private:
62 const T * bitset_ = nullptr;
63 IndexType index_ = IndexType( ~size_t( 0 ) );
64};
65
68class BitSet
69{
70public:
72 inline static constexpr size_t bits_per_block = sizeof( block_type ) * 8;
73 inline static constexpr size_t npos = (size_t)-1;
74
75 using size_type = size_t;
76 using IndexType = size_t;
77
79 BitSet() noexcept = default;
80
82 explicit BitSet( size_t numBits, bool fillValue = false ) { resize( numBits, fillValue ); }
83
85 static BitSet fromBlocks( std::vector<block_type> && blocks )
86 {
87 BitSet res;
88 res.blocks_ = std::move( blocks );
89 res.numBits_ = res.blocks_.size() * bits_per_block;
90 return res;
91 }
92
93 void reserve( size_type numBits ) { blocks_.reserve( calcNumBlocks_( numBits ) ); }
94 MRMESH_API void resize( size_type numBits, bool fillValue = false );
95 void clear() { numBits_ = 0; blocks_.clear(); }
96 void shrink_to_fit() { blocks_.shrink_to_fit(); }
97
98 [[nodiscard]] bool empty() const noexcept { return numBits_ == 0; }
99 [[nodiscard]] size_type size() const noexcept { return numBits_; }
100 [[nodiscard]] size_type num_blocks() const noexcept { return blocks_.size(); }
101 [[nodiscard]] size_type capacity() const noexcept { return blocks_.capacity() * bits_per_block; }
102
103 [[nodiscard]] bool uncheckedTest( IndexType n ) const { assert( n < size() ); return blocks_[blockIndex_( n )] & bitMask_( n ); }
104 [[nodiscard]] bool uncheckedTestSet( IndexType n, bool val = true ) { assert( n < size() ); bool b = uncheckedTest( n ); if ( b != val ) set( n, val ); return b; }
105
107 [[nodiscard]] bool test( IndexType n ) const { return n < size() ? uncheckedTest( n ) : false; }
108 [[nodiscard]] bool test_set( IndexType n, bool val = true ) { return ( val || n < size() ) ? uncheckedTestSet( n, val ) : false; }
109
110 MRMESH_API BitSet & set( IndexType n, size_type len, bool val );
111 BitSet & set( IndexType n, bool val ) { return val ? set( n ) : reset( n ); }
112 BitSet & set( IndexType n ) { assert( n < size() ); blocks_[blockIndex_( n )] |= bitMask_( n ); return * this; }
114
116 BitSet & reset( IndexType n ) { if ( n < size() ) blocks_[blockIndex_( n )] &= ~bitMask_( n ); return * this; }
118
120 BitSet & flip( IndexType n ) { assert( n < size() ); blocks_[blockIndex_( n )] ^= bitMask_( n ); return * this; }
122
125
127 void push_back( bool val ) { auto n = numBits_++; if ( bitIndex_( n ) == 0 ) blocks_.push_back( block_type{} ); set( n, val ); }
128
130 void pop_back() { assert( numBits_ > 0 ); { if ( bitIndex_( numBits_ ) == 1 ) blocks_.pop_back(); else reset( numBits_ - 1 ); } --numBits_; }
131
133 [[nodiscard]] const auto & bits() const { return blocks_; }
134
138
141 MRMESH_API BitSet & subtract( const BitSet & b, int bShiftInBlocks );
142
144 [[nodiscard]] MRMESH_API bool all() const;
145
147 [[nodiscard]] MRMESH_API bool any() const;
148
150 [[nodiscard]] bool none() const { return !any(); }
151
153 [[nodiscard]] MRMESH_API size_type count() const noexcept;
154
156 [[nodiscard]] IndexType find_first() const { return findSetBitAfter_( 0 ); }
157
159 [[nodiscard]] IndexType find_next( IndexType n ) const { return findSetBitAfter_( n + 1 ); }
160
162 [[nodiscard]] MRMESH_API IndexType find_last() const;
163
165 [[nodiscard]] IndexType find_first_not_set() const { return findNonSetBitAfter_( 0 ); }
166
168 [[nodiscard]] IndexType find_next_not_set( IndexType n ) const { return findNonSetBitAfter_( n + 1 ); }
169
172
174 [[nodiscard]] MRMESH_API size_t nthSetBit( size_t n ) const;
175
177 [[nodiscard]] MRMESH_API bool is_subset_of( const BitSet& a ) const;
178
180 [[nodiscard]] MRMESH_API bool intersects( const BitSet & a ) const;
181
183 void resizeWithReserve( size_t newSize )
184 {
185 auto reserved = capacity();
186 if ( reserved > 0 && newSize > reserved )
187 {
188 while ( newSize > reserved )
189 reserved <<= 1;
190 reserve( reserved );
191 }
192 resize( newSize );
193 }
194
196 void autoResizeSet( size_t pos, size_type len, bool val = true )
197 {
198 if ( pos + len > size() )
199 resizeWithReserve( pos + len );
200 set( pos, len, val );
201 }
202 void autoResizeSet( size_t pos, bool val = true ) { autoResizeSet( pos, 1, val ); }
203
205 [[nodiscard]] bool autoResizeTestSet( size_t pos, bool val = true )
206 {
207 bool const b = test( pos );
208 if ( b != val )
209 autoResizeSet( pos, val );
210 return b;
211 }
212
214 [[nodiscard]] size_t heapBytes() const { return capacity() / 8; }
215
217 [[nodiscard]] IndexType backId() const { assert( !empty() ); return IndexType{ size() - 1 }; }
218
220 [[nodiscard]] static IndexType beginId() { return IndexType{ 0 }; }
221 [[nodiscard]] IndexType endId() const { return IndexType{ size() }; }
222
223private:
225 [[nodiscard]] static size_type calcNumBlocks_( size_type numBits ) noexcept { return ( numBits + bits_per_block - 1 ) / bits_per_block; }
226
228 [[nodiscard]] static size_type blockIndex_( IndexType n ) noexcept { return n / bits_per_block; }
229
231 [[nodiscard]] static size_type bitIndex_( IndexType n ) noexcept { return n % bits_per_block; }
232
234 [[nodiscard]] static block_type bitMask_( IndexType n ) noexcept { return block_type( 1 ) << bitIndex_( n ); }
235
237 [[nodiscard]] static block_type bitMask_( IndexType firstBit, IndexType lastBit ) noexcept
238 {
239 return ( ( block_type( 1 ) << firstBit ) - 1 )
240 ^
241 ( lastBit == bits_per_block ? ~block_type{} : ( ( block_type( 1 ) << lastBit ) - 1 ) );
242 }
243
245 MRMESH_API void setUnusedBits_();
246
248 MRMESH_API void resetUnusedBits_();
249
253 template<class FullBlock, class PartialBlock>
254 BitSet & rangeOp_( IndexType n, size_type len, FullBlock&&, PartialBlock&& );
255
257 MRMESH_API IndexType findSetBitAfter_( IndexType n ) const;
258
260 MRMESH_API IndexType findNonSetBitAfter_( IndexType n ) const;
261
262 MRMESH_API friend std::ostream& operator<<( std::ostream& s, const BitSet & bs );
263 MRMESH_API friend std::istream& operator>>( std::istream& s, BitSet & bs );
264
265 [[nodiscard]] MR_BIND_IGNORE_PY friend auto begin( const BitSet & a ) { return SetBitIteratorT<BitSet>(a); }
266 [[nodiscard]] MR_BIND_IGNORE_PY friend auto end( const BitSet & ) { return SetBitIteratorT<BitSet>(); }
267
268private:
269 std::vector<block_type> blocks_;
270 size_type numBits_ = 0;
271};
272
275template <typename I>
276class TypedBitSet : public BitSet
277{
278 using base = BitSet;
279public:
280 using base::base;
281 using IndexType = I;
282
284 explicit TypedBitSet( const BitSet & src ) : BitSet( src ) {}
285
287 explicit TypedBitSet( BitSet && src ) : BitSet( std::move( src ) ) {}
288
289 TypedBitSet & set( IndexType n, size_type len, bool val ) { base::set( n, len, val ); return * this; }
290 TypedBitSet & set( IndexType n, bool val ) { base::set( n, val ); return * this; }
291 TypedBitSet & set( IndexType n ) { base::set( n ); return * this; }
292 TypedBitSet & set() { base::set(); return * this; }
293 TypedBitSet & reset( IndexType n, size_type len ) { base::reset( n, len ); return * this; }
294 TypedBitSet & reset( IndexType n ) { base::reset( n ); return * this; }
295 TypedBitSet & reset() { base::reset(); return * this; }
296 TypedBitSet & flip( IndexType n, size_type len ) { base::flip( n, len ); return * this; }
297 TypedBitSet & flip( IndexType n ) { base::flip( n ); return * this; }
298 TypedBitSet & flip() { base::flip(); return * this; }
299 [[nodiscard]] bool test( IndexType n ) const { return base::test( n ); }
300 [[nodiscard]] bool test_set( IndexType n, bool val = true ) { return base::test_set( n, val ); }
301
302 [[nodiscard]] IndexType find_first() const { return IndexType( base::find_first() ); }
303 [[nodiscard]] IndexType find_next( IndexType pos ) const { return IndexType( base::find_next( pos ) ); }
304 [[nodiscard]] IndexType find_last() const { return IndexType( base::find_last() ); }
305 [[nodiscard]] IndexType find_first_not_set() const { return IndexType( base::find_first_not_set() ); }
306 [[nodiscard]] IndexType find_next_not_set( IndexType pos ) const { return IndexType( base::find_next_not_set( pos ) ); }
307 [[nodiscard]] IndexType find_last_not_set() const { return IndexType( base::find_last_not_set() ); }
309 [[nodiscard]] IndexType nthSetBit( size_t n ) const { return IndexType( base::nthSetBit( n ) ); }
310
311 TypedBitSet & operator &= ( const TypedBitSet & b ) { base::operator &= ( b ); return * this; }
312 TypedBitSet & operator |= ( const TypedBitSet & b ) { base::operator |= ( b ); return * this; }
313 TypedBitSet & operator ^= ( const TypedBitSet & b ) { base::operator ^= ( b ); return * this; }
314 TypedBitSet & operator -= ( const TypedBitSet & b ) { base::operator -= ( b ); return * this; }
315
316 [[nodiscard]] friend TypedBitSet operator & ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res &= b; return res; }
317 [[nodiscard]] friend TypedBitSet operator | ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res |= b; return res; }
318 [[nodiscard]] friend TypedBitSet operator ^ ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res ^= b; return res; }
319 [[nodiscard]] friend TypedBitSet operator - ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res -= b; return res; }
320
322 TypedBitSet & subtract( const TypedBitSet & b, int bShiftInBlocks ) { base::subtract( b, bShiftInBlocks ); return * this; }
323
325 [[nodiscard]] bool is_subset_of( const TypedBitSet& a ) const { return base::is_subset_of( a ); }
326
328 [[nodiscard]] bool intersects( const TypedBitSet & a ) const { return base::intersects( a ); }
329
330 void autoResizeSet( IndexType pos, size_type len, bool val = true ) { base::autoResizeSet( pos, len, val ); }
331 void autoResizeSet( IndexType pos, bool val = true ) { base::autoResizeSet( pos, val ); }
332 [[nodiscard]] bool autoResizeTestSet( IndexType pos, bool val = true ) { return base::autoResizeTestSet( pos, val ); }
333
335 template <typename M>
336 [[nodiscard]] TypedBitSet getMapping( const M & map ) const;
337 [[nodiscard]] TypedBitSet getMapping( const Vector<IndexType, IndexType> & map ) const
338 { return getMapping( [&map]( IndexType i ) { return map[i]; } ); }
339 [[nodiscard]] TypedBitSet getMapping( const BMap<IndexType, IndexType> & map ) const
340 { return getMapping( [&map]( IndexType i ) { return map.b[i]; }, map.tsize ); }
341 [[nodiscard]] TypedBitSet getMapping( const HashMap<IndexType, IndexType> & map ) const
342 { return getMapping( [&map]( IndexType i ) { return getAt( map, i ); } ); }
343
344 template <typename M>
345 [[nodiscard]] TypedBitSet getMapping( const M & map, size_t resSize ) const;
346 [[nodiscard]] TypedBitSet getMapping( const Vector<IndexType, IndexType> & map, size_t resSize ) const
347 { return getMapping( [&map]( IndexType i ) { return map[i]; }, resSize ); }
348 [[nodiscard]] TypedBitSet getMapping( const HashMap<IndexType, IndexType> & map, size_t resSize ) const
349 { return getMapping( [&map]( IndexType i ) { return getAt( map, i ); }, resSize ); }
350
352 [[nodiscard]] IndexType backId() const { assert( !empty() ); return IndexType{ size() - 1 }; }
353
355 [[nodiscard]] static IndexType beginId() { return IndexType{ size_t( 0 ) }; }
356 [[nodiscard]] IndexType endId() const { return IndexType{ size() }; }
357
358 [[nodiscard]] MR_BIND_IGNORE_PY friend auto begin( const TypedBitSet & a ) { return SetBitIteratorT<TypedBitSet>(a); }
359 [[nodiscard]] MR_BIND_IGNORE_PY friend auto end( const TypedBitSet & ) { return SetBitIteratorT<TypedBitSet>(); }
360};
361
362
364[[nodiscard]] inline size_t heapBytes( const BitSet& bs )
365{
366 return bs.heapBytes();
367}
368
370[[nodiscard]] MRMESH_API bool operator == ( const BitSet & a, const BitSet & b );
371template <typename I>
372[[nodiscard]] inline bool operator == ( const TypedBitSet<I> & a, const TypedBitSet<I> & b )
373 { return static_cast<const BitSet &>( a ) == static_cast<const BitSet &>( b ); }
374
375template <typename T, typename U>
376void operator == ( const TypedBitSet<T> & a, const TypedBitSet<U> & b ) = delete;
377
378template <typename I>
379[[nodiscard]] inline std::function<bool( I )> makePredicate( const TypedBitSet<I> * bitset )
380{
381 std::function<bool( I )> res;
382 if ( bitset )
383 res = [bitset]( I id ) { return bitset->test( id ); };
384 return res;
385}
386
387template <typename I>
388[[nodiscard]] inline std::function<bool( I )> makePredicate( const TypedBitSet<I> & bitset )
389 { return makePredicate( &bitset ); }
390
391template <typename I>
392[[nodiscard]] inline bool contains( const TypedBitSet<I> * bitset, I id )
393{
394 return id.valid() && ( !bitset || bitset->test( id ) );
395}
396
397template <typename I>
398[[nodiscard]] inline bool contains( const TypedBitSet<I> & bitset, I id )
399{
400 return id.valid() && bitset.test( id );
401}
402
403
405template <typename I>
407{
408 int n = 0;
409 for ( auto v : bs )
410 vec[v] = n++;
411}
412
414template <typename I>
416{
417 Vector<int, I> res( bs.size(), -1 );
418 fillVectorWithSeqNums( bs, res );
419 return res;
420}
421
423template <typename I>
425{
426 HashMap<I, int> res;
427 int n = 0;
428 for ( auto v : bs )
429 res[v] = n++;
430 return res;
431}
432
433template <typename I>
434template <typename M>
435[[nodiscard]] TypedBitSet<I> TypedBitSet<I>::getMapping( const M & map ) const
436{
437 TypedBitSet<I> res;
438 for ( auto b : *this )
439 if ( auto mapped = map( b ) )
440 res.autoResizeSet( mapped );
441 return res;
442}
443
444template <typename I>
445template <typename M>
446[[nodiscard]] TypedBitSet<I> TypedBitSet<I>::getMapping( const M & map, size_t resSize ) const
447{
448 TypedBitSet<I> res;
449 if ( !any() )
450 return res;
451 res.resize( resSize );
452 for ( auto b : *this )
453 if ( auto mapped = map( b ) )
454 res.set( mapped );
455 return res;
456}
457
458[[nodiscard]] inline BitSet operator & ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res &= b; return res; }
459[[nodiscard]] inline BitSet operator | ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res |= b; return res; }
460[[nodiscard]] inline BitSet operator ^ ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res ^= b; return res; }
461[[nodiscard]] inline BitSet operator - ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res -= b; return res; }
462
464
465}
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
#define M(T)
Definition MRBitSet.h:69
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
BitSet & reset()
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)
BitSet & set()
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
BitSet & flip()
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