MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/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
23class BitSet
24{
25public:
27 inline static constexpr size_t bits_per_block = sizeof( block_type ) * 8;
28 inline static constexpr size_t npos = (size_t)-1;
29
30 using size_type = size_t;
31 using IndexType = size_t;
32
34 BitSet() noexcept = default;
35
37 explicit BitSet( size_t numBits, bool fillValue = false ) { resize( numBits, fillValue ); }
38
40 static BitSet fromBlocks( std::vector<block_type> && blocks )
41 {
42 BitSet res;
43 res.blocks_ = std::move( blocks );
44 res.numBits_ = res.blocks_.size() * bits_per_block;
45 return res;
46 }
47
48 void reserve( size_type numBits ) { blocks_.reserve( calcNumBlocks_( numBits ) ); }
49 MRMESH_API void resize( size_type numBits, bool fillValue = false );
50 void clear() { numBits_ = 0; blocks_.clear(); }
51 void shrink_to_fit() { blocks_.shrink_to_fit(); }
52
53 [[nodiscard]] bool empty() const noexcept { return numBits_ == 0; }
54 [[nodiscard]] size_type size() const noexcept { return numBits_; }
55 [[nodiscard]] size_type num_blocks() const noexcept { return blocks_.size(); }
56 [[nodiscard]] size_type capacity() const noexcept { return blocks_.capacity() * bits_per_block; }
57
58 [[nodiscard]] bool uncheckedTest( IndexType n ) const { assert( n < size() ); return blocks_[blockIndex_( n )] & bitMask_( n ); }
59 [[nodiscard]] bool uncheckedTestSet( IndexType n, bool val = true ) { assert( n < size() ); bool b = uncheckedTest( n ); if ( b != val ) set( n, val ); return b; }
60
61 // all bits after size() we silently consider as not-set
62 [[nodiscard]] bool test( IndexType n ) const { return n < size() && uncheckedTest( n ); }
63 [[nodiscard]] bool test_set( IndexType n, bool val = true ) { return ( val || n < size() ) ? uncheckedTestSet( n, val ) : false; }
64
65 MRMESH_API BitSet & set( IndexType n, size_type len, bool val );
66 BitSet & set( IndexType n, bool val ) { return val ? set( n ) : reset( n ); } // Not using a default argument for `val` to get better C bindings.
67 BitSet & set( IndexType n ) { assert( n < size() ); blocks_[blockIndex_( n )] |= bitMask_( n ); return * this; }
69
71 BitSet & reset( IndexType n ) { if ( n < size() ) blocks_[blockIndex_( n )] &= ~bitMask_( n ); return * this; }
73
75 BitSet & flip( IndexType n ) { assert( n < size() ); blocks_[blockIndex_( n )] ^= bitMask_( n ); return * this; }
77
80
82 void push_back( bool val ) { auto n = numBits_++; if ( bitIndex_( n ) == 0 ) blocks_.push_back( block_type{} ); set( n, val ); }
83
85 void pop_back() { assert( numBits_ > 0 ); { if ( bitIndex_( numBits_ ) == 1 ) blocks_.pop_back(); else reset( numBits_ - 1 ); } --numBits_; }
86
88 [[nodiscard]] const auto & bits() const { return blocks_; }
89
93
96 MRMESH_API BitSet & subtract( const BitSet & b, int bShiftInBlocks );
97
99 [[nodiscard]] MRMESH_API bool all() const;
100
102 [[nodiscard]] MRMESH_API bool any() const;
103
105 [[nodiscard]] bool none() const { return !any(); }
106
108 [[nodiscard]] MRMESH_API size_type count() const noexcept;
109
111 [[nodiscard]] IndexType find_first() const { return findSetBitAfter_( 0 ); }
112
114 [[nodiscard]] IndexType find_next( IndexType n ) const { return findSetBitAfter_( n + 1 ); }
115
117 [[nodiscard]] MRMESH_API IndexType find_last() const;
118
120 [[nodiscard]] MRMESH_API size_t nthSetBit( size_t n ) const;
121
123 [[nodiscard]] MRMESH_API bool is_subset_of( const BitSet& a ) const;
124
126 [[nodiscard]] MRMESH_API bool intersects( const BitSet & a ) const;
127
129 void resizeWithReserve( size_t newSize )
130 {
131 auto reserved = capacity();
132 if ( reserved > 0 && newSize > reserved )
133 {
134 while ( newSize > reserved )
135 reserved <<= 1;
136 reserve( reserved );
137 }
138 resize( newSize );
139 }
140
142 void autoResizeSet( size_t pos, size_type len, bool val = true )
143 {
144 if ( pos + len > size() )
145 resizeWithReserve( pos + len );
146 set( pos, len, val );
147 }
148 void autoResizeSet( size_t pos, bool val = true ) { autoResizeSet( pos, 1, val ); }
149
151 [[nodiscard]] bool autoResizeTestSet( size_t pos, bool val = true )
152 {
153 bool const b = test( pos );
154 if ( b != val )
155 autoResizeSet( pos, val );
156 return b;
157 }
158
160 [[nodiscard]] size_t heapBytes() const { return capacity() / 8; }
161
163 [[nodiscard]] IndexType backId() const { assert( !empty() ); return IndexType{ size() - 1 }; }
164
166 [[nodiscard]] static IndexType beginId() { return IndexType{ 0 }; }
167 [[nodiscard]] IndexType endId() const { return IndexType{ size() }; }
168
169private:
171 [[nodiscard]] static size_type calcNumBlocks_( size_type numBits ) noexcept { return ( numBits + bits_per_block - 1 ) / bits_per_block; }
172
174 [[nodiscard]] static size_type blockIndex_( IndexType n ) noexcept { return n / bits_per_block; }
175
177 [[nodiscard]] static size_type bitIndex_( IndexType n ) noexcept { return n % bits_per_block; }
178
180 [[nodiscard]] static block_type bitMask_( IndexType n ) noexcept { return block_type( 1 ) << bitIndex_( n ); }
181
183 [[nodiscard]] static block_type bitMask_( IndexType firstBit, IndexType lastBit ) noexcept
184 {
185 return ( ( block_type( 1 ) << firstBit ) - 1 ) // set all bits in [0, firstBit)
186 ^ //xor
187 ( lastBit == bits_per_block ? ~block_type{} : ( ( block_type( 1 ) << lastBit ) - 1 ) ); // set all bits in [0, lastBit)
188 }
189
191 MRMESH_API void setUnusedBits_();
192
194 MRMESH_API void resetUnusedBits_();
195
199 template<class FullBlock, class PartialBlock>
200 BitSet & rangeOp_( IndexType n, size_type len, FullBlock&&, PartialBlock&& );
201
203 MRMESH_API IndexType findSetBitAfter_( IndexType n ) const;
204
205 MRMESH_API friend std::ostream& operator<<( std::ostream& s, const BitSet & bs );
206 MRMESH_API friend std::istream& operator>>( std::istream& s, BitSet & bs );
207
208private:
209 std::vector<block_type> blocks_;
210 size_type numBits_ = 0;
211};
212
215template <typename I>
216class TypedBitSet : public BitSet
217{
218 using base = BitSet;
219public:
220 using base::base;
221 using IndexType = I;
222
224 explicit TypedBitSet( const BitSet & src ) : BitSet( src ) {}
225
227 explicit TypedBitSet( BitSet && src ) : BitSet( std::move( src ) ) {}
228
229 TypedBitSet & set( IndexType n, size_type len, bool val ) { base::set( n, len, val ); return * this; }
230 TypedBitSet & set( IndexType n, bool val ) { base::set( n, val ); return * this; } // Not using a default argument for `val` to get better C bindings.
231 TypedBitSet & set( IndexType n ) { base::set( n ); return * this; }
232 TypedBitSet & set() { base::set(); return * this; }
233 TypedBitSet & reset( IndexType n, size_type len ) { base::reset( n, len ); return * this; }
234 TypedBitSet & reset( IndexType n ) { base::reset( n ); return * this; }
235 TypedBitSet & reset() { base::reset(); return * this; }
236 TypedBitSet & flip( IndexType n, size_type len ) { base::flip( n, len ); return * this; }
237 TypedBitSet & flip( IndexType n ) { base::flip( n ); return * this; }
238 TypedBitSet & flip() { base::flip(); return * this; }
239 [[nodiscard]] bool test( IndexType n ) const { return base::test( n ); }
240 [[nodiscard]] bool test_set( IndexType n, bool val = true ) { return base::test_set( n, val ); }
241
242 [[nodiscard]] IndexType find_first() const { return IndexType( base::find_first() ); }
243 [[nodiscard]] IndexType find_next( IndexType pos ) const { return IndexType( base::find_next( pos ) ); }
244 [[nodiscard]] IndexType find_last() const { return IndexType( base::find_last() ); }
246 [[nodiscard]] IndexType nthSetBit( size_t n ) const { return IndexType( base::nthSetBit( n ) ); }
247
248 TypedBitSet & operator &= ( const TypedBitSet & b ) { base::operator &= ( b ); return * this; }
249 TypedBitSet & operator |= ( const TypedBitSet & b ) { base::operator |= ( b ); return * this; }
250 TypedBitSet & operator ^= ( const TypedBitSet & b ) { base::operator ^= ( b ); return * this; }
251 TypedBitSet & operator -= ( const TypedBitSet & b ) { base::operator -= ( b ); return * this; }
252
253 [[nodiscard]] friend TypedBitSet operator & ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res &= b; return res; }
254 [[nodiscard]] friend TypedBitSet operator | ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res |= b; return res; }
255 [[nodiscard]] friend TypedBitSet operator ^ ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res ^= b; return res; }
256 [[nodiscard]] friend TypedBitSet operator - ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res -= b; return res; }
257
259 TypedBitSet & subtract( const TypedBitSet & b, int bShiftInBlocks ) { base::subtract( b, bShiftInBlocks ); return * this; }
260
262 [[nodiscard]] bool is_subset_of( const TypedBitSet& a ) const { return base::is_subset_of( a ); }
263
265 [[nodiscard]] bool intersects( const TypedBitSet & a ) const { return base::intersects( a ); }
266
267 void autoResizeSet( IndexType pos, size_type len, bool val = true ) { base::autoResizeSet( pos, len, val ); }
268 void autoResizeSet( IndexType pos, bool val = true ) { base::autoResizeSet( pos, val ); }
269 [[nodiscard]] bool autoResizeTestSet( IndexType pos, bool val = true ) { return base::autoResizeTestSet( pos, val ); }
270
272 template <typename M>
273 [[nodiscard]] TypedBitSet getMapping( const M & map ) const;
274 [[nodiscard]] TypedBitSet getMapping( const Vector<IndexType, IndexType> & map ) const
275 { return getMapping( [&map]( IndexType i ) { return map[i]; } ); }
276 [[nodiscard]] TypedBitSet getMapping( const BMap<IndexType, IndexType> & map ) const
277 { return getMapping( [&map]( IndexType i ) { return map.b[i]; }, map.tsize ); }
278 [[nodiscard]] TypedBitSet getMapping( const HashMap<IndexType, IndexType> & map ) const
279 { return getMapping( [&map]( IndexType i ) { return getAt( map, i ); } ); }
281 template <typename M>
282 [[nodiscard]] TypedBitSet getMapping( const M & map, size_t resSize ) const;
283 [[nodiscard]] TypedBitSet getMapping( const Vector<IndexType, IndexType> & map, size_t resSize ) const
284 { return getMapping( [&map]( IndexType i ) { return map[i]; }, resSize ); }
285 [[nodiscard]] TypedBitSet getMapping( const HashMap<IndexType, IndexType> & map, size_t resSize ) const
286 { return getMapping( [&map]( IndexType i ) { return getAt( map, i ); }, resSize ); }
287
289 [[nodiscard]] IndexType backId() const { assert( !empty() ); return IndexType{ size() - 1 }; }
290
292 [[nodiscard]] static IndexType beginId() { return IndexType{ size_t( 0 ) }; }
293 [[nodiscard]] IndexType endId() const { return IndexType{ size() }; }
294};
295
296
298[[nodiscard]] inline size_t heapBytes( const BitSet& bs )
299{
300 return bs.heapBytes();
301}
302
304[[nodiscard]] MRMESH_API bool operator == ( const BitSet & a, const BitSet & b );
305template <typename I>
306[[nodiscard]] inline bool operator == ( const TypedBitSet<I> & a, const TypedBitSet<I> & b )
307 { return static_cast<const BitSet &>( a ) == static_cast<const BitSet &>( b ); }
309template <typename T, typename U>
310void operator == ( const TypedBitSet<T> & a, const TypedBitSet<U> & b ) = delete;
311
312template <typename I>
313[[nodiscard]] inline std::function<bool( I )> makePredicate( const TypedBitSet<I> * bitset )
314{
315 std::function<bool( I )> res;
316 if ( bitset )
317 res = [bitset]( I id ) { return bitset->test( id ); };
318 return res;
319}
320
321template <typename I>
322[[nodiscard]] inline std::function<bool( I )> makePredicate( const TypedBitSet<I> & bitset )
323 { return makePredicate( &bitset ); }
324
325template <typename I>
326[[nodiscard]] inline bool contains( const TypedBitSet<I> * bitset, I id )
327{
328 return id.valid() && ( !bitset || bitset->test( id ) );
329}
330
331template <typename I>
332[[nodiscard]] inline bool contains( const TypedBitSet<I> & bitset, I id )
333{
334 return id.valid() && bitset.test( id );
335}
336
338template <typename T>
340{
341public:
342 using IndexType = typename T::IndexType;
343
344 using iterator_category = std::forward_iterator_tag;
346 using difference_type = std::ptrdiff_t;
347 using reference = const IndexType;
348 using pointer = const IndexType *;
349
351 SetBitIteratorT() = default;
353 SetBitIteratorT( const T & bitset )
354 : bitset_( &bitset ), index_( bitset.find_first() )
355 {
356 }
358 {
359 index_ = bitset_->find_next( index_ );
360 return * this;
361 }
362 [[nodiscard]] SetBitIteratorT operator++( int )
363 {
364 SetBitIteratorT ret = *this;
365 operator++();
366 return ret;
367 }
368
369 [[nodiscard]] const T * bitset() const { return bitset_; }
370 [[nodiscard]] reference operator *() const { return index_; }
371
372 [[nodiscard]] friend bool operator ==( const SetBitIteratorT<T> & a, const SetBitIteratorT<T> & b ) { return *a == *b; }
373
374private:
375 const T * bitset_ = nullptr;
376 IndexType index_ = IndexType( ~size_t( 0 ) );
377};
378
379
380[[nodiscard]] MR_BIND_IGNORE inline auto begin( const BitSet & a )
381 { return SetBitIteratorT<BitSet>(a); }
382[[nodiscard]] MR_BIND_IGNORE inline auto end( const BitSet & )
383 { return SetBitIteratorT<BitSet>(); }
384
385template <typename I>
386[[nodiscard]] MR_BIND_IGNORE inline auto begin( const TypedBitSet<I> & a )
387 { return SetBitIteratorT<TypedBitSet<I>>(a); }
388template <typename I>
389[[nodiscard]] MR_BIND_IGNORE inline auto end( const TypedBitSet<I> & )
390 { return SetBitIteratorT<TypedBitSet<I>>(); }
391
393template <typename I>
395{
396 Vector<int, I> res( bs.size(), -1 );
397 int n = 0;
398 for ( auto v : bs )
399 res[v] = n++;
400 return res;
401}
402
404template <typename I>
406{
407 HashMap<I, int> res;
408 int n = 0;
409 for ( auto v : bs )
410 res[v] = n++;
411 return res;
412}
413
414template <typename I>
415template <typename M>
416[[nodiscard]] TypedBitSet<I> TypedBitSet<I>::getMapping( const M & map ) const
417{
418 TypedBitSet<I> res;
419 for ( auto b : *this )
420 if ( auto mapped = map( b ) )
421 res.autoResizeSet( mapped );
422 return res;
423}
424
425template <typename I>
426template <typename M>
427[[nodiscard]] TypedBitSet<I> TypedBitSet<I>::getMapping( const M & map, size_t resSize ) const
428{
429 TypedBitSet<I> res;
430 if ( !any() )
431 return res;
432 res.resize( resSize );
433 for ( auto b : *this )
434 if ( auto mapped = map( b ) )
435 res.set( mapped );
436 return res;
437}
438
439[[nodiscard]] inline BitSet operator & ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res &= b; return res; }
440[[nodiscard]] inline BitSet operator | ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res |= b; return res; }
441[[nodiscard]] inline BitSet operator ^ ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res ^= b; return res; }
442[[nodiscard]] inline BitSet operator - ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res -= b; return res; }
443
445
446} // namespace MR
#define MRMESH_API
Definition MRMeshFwd.h:80
#define M(T)
Definition MRMesh/MRBitSet.h:24
size_t size_type
Definition MRMesh/MRBitSet.h:30
size_t IndexType
Definition MRMesh/MRBitSet.h:31
MRMESH_API BitSet & flip(IndexType n, size_type len)
MRMESH_API size_type count() const noexcept
computes the number of set bits in the whole set
static constexpr size_t bits_per_block
Definition MRMesh/MRBitSet.h:27
IndexType endId() const
Definition MRMesh/MRBitSet.h:167
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:166
MRMESH_API IndexType find_last() const
return the highest index i such that bit i is set, or npos if *this has no on bits.
MRMESH_API 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...
MRMESH_API BitSet & subtract(const BitSet &b, int bShiftInBlocks)
subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
MRMESH_API BitSet & operator-=(const BitSet &b)
Uint64 block_type
Definition MRMesh/MRBitSet.h:26
void reserve(size_type numBits)
Definition MRMesh/MRBitSet.h:48
MRMESH_API void resize(size_type numBits, bool fillValue=false)
BitSet() noexcept=default
creates empty bitset
bool empty() const noexcept
Definition MRMesh/MRBitSet.h:53
BitSet & set(IndexType n)
Definition MRMesh/MRBitSet.h:67
void autoResizeSet(size_t pos, bool val=true)
Definition MRMesh/MRBitSet.h:148
MRMESH_API BitSet & reset()
MRMESH_API BitSet & flip()
bool autoResizeTestSet(size_t pos, bool val=true)
same as autoResizeSet and returns previous value of pos-bit
Definition MRMesh/MRBitSet.h:151
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:63
bool uncheckedTest(IndexType n) const
Definition MRMesh/MRBitSet.h:58
MRMESH_API friend std::istream & operator>>(std::istream &s, BitSet &bs)
static BitSet fromBlocks(std::vector< block_type > &&blocks)
creates bitset from the given blocks of bits
Definition MRMesh/MRBitSet.h:40
MRMESH_API BitSet & set()
void clear()
Definition MRMesh/MRBitSet.h:50
MRMESH_API friend std::ostream & operator<<(std::ostream &s, const BitSet &bs)
size_type size() const noexcept
Definition MRMesh/MRBitSet.h:54
bool uncheckedTestSet(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:59
BitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:71
MRMESH_API bool all() const
returns true if all bits in this container are set
MRMESH_API void reverse()
changes the order of bits on the opposite
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:62
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 MRMesh/MRBitSet.h:114
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 MRMesh/MRBitSet.h:142
size_type num_blocks() const noexcept
Definition MRMesh/MRBitSet.h:55
BitSet & set(IndexType n, bool val)
Definition MRMesh/MRBitSet.h:66
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:163
MRMESH_API 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...
MRMESH_API BitSet & set(IndexType n, size_type len, bool val)
void resizeWithReserve(size_t newSize)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRBitSet.h:129
IndexType find_first() const
return the smallest index i such that bit i is set, or npos if *this has no on bits.
Definition MRMesh/MRBitSet.h:111
void push_back(bool val)
adds one more bit with the given value in the container, increasing its size on 1
Definition MRMesh/MRBitSet.h:82
MRMESH_API 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 ...
size_type capacity() const noexcept
Definition MRMesh/MRBitSet.h:56
MRMESH_API BitSet & reset(IndexType n, size_type len)
const auto & bits() const
read-only access to all bits stored as a vector of uint64 blocks
Definition MRMesh/MRBitSet.h:88
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRBitSet.h:160
MRMESH_API BitSet & operator|=(const BitSet &b)
bool none() const
returns true if all bits in this container are reset
Definition MRMesh/MRBitSet.h:105
MRMESH_API BitSet & operator^=(const BitSet &b)
static constexpr size_t npos
Definition MRMesh/MRBitSet.h:28
MRMESH_API bool any() const
returns true if at least one bits in this container is set
MRMESH_API BitSet & operator&=(const BitSet &b)
void pop_back()
removes last bit from the container, decreasing its size on 1
Definition MRMesh/MRBitSet.h:85
BitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:75
void shrink_to_fit()
Definition MRMesh/MRBitSet.h:51
iterator to enumerate all indices with set bits in BitSet class or its derivatives
Definition MRMesh/MRBitSet.h:340
SetBitIteratorT operator++(int)
Definition MRMesh/MRBitSet.h:362
const IndexType * pointer
Definition MRMesh/MRBitSet.h:348
SetBitIteratorT()=default
constructs end iterator
std::forward_iterator_tag iterator_category
Definition MRMesh/MRBitSet.h:344
const T * bitset() const
Definition MRMesh/MRBitSet.h:369
IndexType value_type
Definition MRMesh/MRBitSet.h:345
const IndexType reference
intentionally not a reference
Definition MRMesh/MRBitSet.h:347
typename T::IndexType IndexType
Definition MRMesh/MRBitSet.h:342
SetBitIteratorT & operator++()
Definition MRMesh/MRBitSet.h:357
SetBitIteratorT(const T &bitset)
constructs begin iterator
Definition MRMesh/MRBitSet.h:353
std::ptrdiff_t difference_type
Definition MRMesh/MRBitSet.h:346
Definition MRMesh/MRBitSet.h:217
IndexType find_last() const
Definition MRMesh/MRBitSet.h:244
TypedBitSet & operator|=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:249
bool intersects(const TypedBitSet &a) const
returns true if, there is a bit which is set in this bitset, such that the corresponding bit in bitse...
Definition MRMesh/MRBitSet.h:265
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:240
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:278
friend TypedBitSet operator|(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:254
friend TypedBitSet operator&(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:253
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:292
TypedBitSet(const BitSet &src)
copies all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRMesh/MRBitSet.h:224
TypedBitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:237
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:289
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:285
TypedBitSet & operator-=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:251
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:229
bool is_subset_of(const TypedBitSet &a) const
returns true if, for every bit that is set in this bitset, the corresponding bit in bitset a is also ...
Definition MRMesh/MRBitSet.h:262
TypedBitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:233
friend TypedBitSet operator-(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:256
TypedBitSet & operator^=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:250
TypedBitSet & set()
Definition MRMesh/MRBitSet.h:232
void autoResizeSet(IndexType pos, size_type len, bool val=true)
Definition MRMesh/MRBitSet.h:267
IndexType endId() const
Definition MRMesh/MRBitSet.h:293
I IndexType
Definition MRMesh/MRBitSet.h:221
TypedBitSet & flip()
Definition MRMesh/MRBitSet.h:238
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:283
IndexType find_first() const
Definition MRMesh/MRBitSet.h:242
friend TypedBitSet operator^(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:255
TypedBitSet & set(IndexType n, bool val)
Definition MRMesh/MRBitSet.h:230
TypedBitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:236
TypedBitSet & operator&=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:248
TypedBitSet getMapping(const M &map, size_t resSize) const
this is a faster version if the result size is known beforehand
void autoResizeSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:268
IndexType find_next(IndexType pos) const
Definition MRMesh/MRBitSet.h:243
TypedBitSet & reset()
Definition MRMesh/MRBitSet.h:235
bool autoResizeTestSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:269
TypedBitSet(BitSet &&src)
moves all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRMesh/MRBitSet.h:227
TypedBitSet & set(IndexType n)
Definition MRMesh/MRBitSet.h:231
TypedBitSet & subtract(const TypedBitSet &b, int bShiftInBlocks)
subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
Definition MRMesh/MRBitSet.h:259
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:274
TypedBitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:234
TypedBitSet getMapping(const M &map) const
constructs another bit set from this where every set bit index is transformed using given map
IndexType nthSetBit(size_t n) const
returns the location of nth set bit (where the first bit corresponds to n=0) or IndexType(npos) if th...
Definition MRMesh/MRBitSet.h:246
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:239
TypedBitSet getMapping(const BMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:276
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:19
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:442
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:380
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 MRMesh/MRBitSet.h:405
MRMESH_API 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...
BitSet operator&(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:439
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 MRMesh/MRBitSet.h:394
bool contains(const TypedBitSet< I > *bitset, I id)
Definition MRMesh/MRBitSet.h:326
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:440
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:382
std::function< bool(I)> makePredicate(const TypedBitSet< I > *bitset)
Definition MRMesh/MRBitSet.h:313
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:441
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRMesh/MRBitSet.h:298
Definition MRCameraOrientationPlugin.h:8
T getAt(const Buffer< T, I > &bmap, 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:119
std::uint64_t Uint64
Definition MRMeshFwd.h:198
Color operator*(float a, const Color &b)
Definition MRMesh/MRColor.h:116
I
Definition MRMeshFwd.h:134
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:10
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMeshFwd.h:602
flat map: I -> T
Definition MRBuffer.h:143
Buffer< T, I > b
Definition MRBuffer.h:144
size_t tsize
target size, all values inside b must be less than this value
Definition MRBuffer.h:145