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 <iterator>
9#include <functional>
10
11namespace MR
12{
13
22class BitSet
23{
24public:
26 inline static constexpr size_t bits_per_block = sizeof( block_type ) * 8;
27 inline static constexpr size_t npos = (size_t)-1;
28
29 using size_type = size_t;
30 using IndexType = size_t;
31
33 BitSet() noexcept = default;
34
36 explicit BitSet( size_t numBits, bool fillValue = false ) { resize( numBits, fillValue ); }
37
39 static BitSet fromBlocks( std::vector<block_type> && blocks )
40 {
41 BitSet res;
42 res.blocks_ = std::move( blocks );
43 res.numBits_ = res.blocks_.size() * bits_per_block;
44 return res;
45 }
46
47 void reserve( size_type numBits ) { blocks_.reserve( calcNumBlocks_( numBits ) ); }
48 MRMESH_API void resize( size_type numBits, bool fillValue = false );
49 void clear() { numBits_ = 0; blocks_.clear(); }
50 void shrink_to_fit() { blocks_.shrink_to_fit(); }
51
52 [[nodiscard]] bool empty() const noexcept { return numBits_ == 0; }
53 [[nodiscard]] size_type size() const noexcept { return numBits_; }
54 [[nodiscard]] size_type num_blocks() const noexcept { return blocks_.size(); }
55 [[nodiscard]] size_type capacity() const noexcept { return blocks_.capacity() * bits_per_block; }
56
57 [[nodiscard]] bool uncheckedTest( IndexType n ) const { assert( n < size() ); return blocks_[blockIndex_( n )] & bitMask_( n ); }
58 [[nodiscard]] bool uncheckedTestSet( IndexType n, bool val = true ) { assert( n < size() ); bool b = uncheckedTest( n ); if ( b != val ) set( n, val ); return b; }
59
60 // all bits after size() we silently consider as not-set
61 [[nodiscard]] bool test( IndexType n ) const { return n < size() && uncheckedTest( n ); }
62 [[nodiscard]] bool test_set( IndexType n, bool val = true ) { return ( val || n < size() ) ? uncheckedTestSet( n, val ) : false; }
63
64 MRMESH_API BitSet & set( IndexType n, size_type len, bool val );
65 BitSet & set( IndexType n, bool val ) { return val ? set( n ) : reset( n ); } // Not using a default argument for `val` to get better C bindings.
66 BitSet & set( IndexType n ) { assert( n < size() ); blocks_[blockIndex_( n )] |= bitMask_( n ); return * this; }
68
70 BitSet & reset( IndexType n ) { if ( n < size() ) blocks_[blockIndex_( n )] &= ~bitMask_( n ); return * this; }
72
74 BitSet & flip( IndexType n ) { assert( n < size() ); blocks_[blockIndex_( n )] ^= bitMask_( n ); return * this; }
76
79
81 void push_back( bool val ) { auto n = numBits_++; if ( bitIndex_( n ) == 0 ) blocks_.push_back( block_type{} ); set( n, val ); }
82
84 void pop_back() { assert( numBits_ > 0 ); { if ( bitIndex_( numBits_ ) == 1 ) blocks_.pop_back(); else reset( numBits_ - 1 ); } --numBits_; }
85
87 [[nodiscard]] const auto & bits() const { return blocks_; }
88
92
95 MRMESH_API BitSet & subtract( const BitSet & b, int bShiftInBlocks );
96
98 [[nodiscard]] MRMESH_API bool all() const;
99
101 [[nodiscard]] MRMESH_API bool any() const;
102
104 [[nodiscard]] bool none() const { return !any(); }
105
107 [[nodiscard]] MRMESH_API size_type count() const noexcept;
108
110 [[nodiscard]] IndexType find_first() const { return findSetBitAfter_( 0 ); }
111
113 [[nodiscard]] IndexType find_next( IndexType n ) const { return findSetBitAfter_( n + 1 ); }
114
116 [[nodiscard]] MRMESH_API IndexType find_last() const;
117
119 [[nodiscard]] MRMESH_API size_t nthSetBit( size_t n ) const;
120
122 [[nodiscard]] MRMESH_API bool is_subset_of( const BitSet& a ) const;
123
125 [[nodiscard]] MRMESH_API bool intersects( const BitSet & a ) const;
126
128 void resizeWithReserve( size_t newSize )
129 {
130 auto reserved = capacity();
131 if ( reserved > 0 && newSize > reserved )
132 {
133 while ( newSize > reserved )
134 reserved <<= 1;
135 reserve( reserved );
136 }
137 resize( newSize );
138 }
139
141 void autoResizeSet( size_t pos, size_type len, bool val = true )
142 {
143 if ( pos + len > size() )
144 resizeWithReserve( pos + len );
145 set( pos, len, val );
146 }
147 void autoResizeSet( size_t pos, bool val = true ) { autoResizeSet( pos, 1, val ); }
148
150 [[nodiscard]] bool autoResizeTestSet( size_t pos, bool val = true )
151 {
152 bool const b = test( pos );
153 if ( b != val )
154 autoResizeSet( pos, val );
155 return b;
156 }
157
159 [[nodiscard]] size_t heapBytes() const { return capacity() / 8; }
160
162 [[nodiscard]] IndexType backId() const { assert( !empty() ); return IndexType{ size() - 1 }; }
163
165 [[nodiscard]] static IndexType beginId() { return IndexType{ 0 }; }
166 [[nodiscard]] IndexType endId() const { return IndexType{ size() }; }
167
168private:
170 [[nodiscard]] static size_type calcNumBlocks_( size_type numBits ) noexcept { return ( numBits + bits_per_block - 1 ) / bits_per_block; }
171
173 [[nodiscard]] static size_type blockIndex_( IndexType n ) noexcept { return n / bits_per_block; }
174
176 [[nodiscard]] static size_type bitIndex_( IndexType n ) noexcept { return n % bits_per_block; }
177
179 [[nodiscard]] static block_type bitMask_( IndexType n ) noexcept { return block_type( 1 ) << bitIndex_( n ); }
180
182 [[nodiscard]] static block_type bitMask_( IndexType firstBit, IndexType lastBit ) noexcept
183 {
184 return ( ( block_type( 1 ) << firstBit ) - 1 ) // set all bits in [0, firstBit)
185 ^ //xor
186 ( lastBit == bits_per_block ? ~block_type{} : ( ( block_type( 1 ) << lastBit ) - 1 ) ); // set all bits in [0, lastBit)
187 }
188
190 MRMESH_API void setUnusedBits_();
191
193 MRMESH_API void resetUnusedBits_();
194
198 template<class FullBlock, class PartialBlock>
199 BitSet & rangeOp_( IndexType n, size_type len, FullBlock&&, PartialBlock&& );
200
202 MRMESH_API IndexType findSetBitAfter_( IndexType n ) const;
203
204private:
205 std::vector<block_type> blocks_;
206 size_type numBits_ = 0;
207};
208
211template <typename I>
212class TypedBitSet : public BitSet
213{
214 using base = BitSet;
215public:
216 using base::base;
217 using IndexType = I;
218
220 explicit TypedBitSet( const BitSet & src ) : BitSet( src ) {}
221
223 explicit TypedBitSet( BitSet && src ) : BitSet( std::move( src ) ) {}
224
225 TypedBitSet & set( IndexType n, size_type len, bool val ) { base::set( n, len, val ); return * this; }
226 TypedBitSet & set( IndexType n, bool val ) { base::set( n, val ); return * this; } // Not using a default argument for `val` to get better C bindings.
227 TypedBitSet & set( IndexType n ) { base::set( n ); return * this; }
228 TypedBitSet & set() { base::set(); return * this; }
229 TypedBitSet & reset( IndexType n, size_type len ) { base::reset( n, len ); return * this; }
230 TypedBitSet & reset( IndexType n ) { base::reset( n ); return * this; }
231 TypedBitSet & reset() { base::reset(); return * this; }
232 TypedBitSet & flip( IndexType n, size_type len ) { base::flip( n, len ); return * this; }
233 TypedBitSet & flip( IndexType n ) { base::flip( n ); return * this; }
234 TypedBitSet & flip() { base::flip(); return * this; }
235 [[nodiscard]] bool test( IndexType n ) const { return base::test( n ); }
236 [[nodiscard]] bool test_set( IndexType n, bool val = true ) { return base::test_set( n, val ); }
237
238 [[nodiscard]] IndexType find_first() const { return IndexType( base::find_first() ); }
239 [[nodiscard]] IndexType find_next( IndexType pos ) const { return IndexType( base::find_next( pos ) ); }
240 [[nodiscard]] IndexType find_last() const { return IndexType( base::find_last() ); }
242 [[nodiscard]] IndexType nthSetBit( size_t n ) const { return IndexType( base::nthSetBit( n ) ); }
243
244 TypedBitSet & operator &= ( const TypedBitSet & b ) { base::operator &= ( b ); return * this; }
245 TypedBitSet & operator |= ( const TypedBitSet & b ) { base::operator |= ( b ); return * this; }
246 TypedBitSet & operator ^= ( const TypedBitSet & b ) { base::operator ^= ( b ); return * this; }
247 TypedBitSet & operator -= ( const TypedBitSet & b ) { base::operator -= ( b ); return * this; }
248
249 [[nodiscard]] friend TypedBitSet operator & ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res &= b; return res; }
250 [[nodiscard]] friend TypedBitSet operator | ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res |= b; return res; }
251 [[nodiscard]] friend TypedBitSet operator ^ ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res ^= b; return res; }
252 [[nodiscard]] friend TypedBitSet operator - ( const TypedBitSet & a, const TypedBitSet & b ) { auto res{ a }; res -= b; return res; }
253
255 TypedBitSet & subtract( const TypedBitSet & b, int bShiftInBlocks ) { base::subtract( b, bShiftInBlocks ); return * this; }
256
258 [[nodiscard]] bool is_subset_of( const TypedBitSet& a ) const { return base::is_subset_of( a ); }
259
261 [[nodiscard]] bool intersects( const TypedBitSet & a ) const { return base::intersects( a ); }
262
263 void autoResizeSet( IndexType pos, size_type len, bool val = true ) { base::autoResizeSet( pos, len, val ); }
264 void autoResizeSet( IndexType pos, bool val = true ) { base::autoResizeSet( pos, val ); }
265 [[nodiscard]] bool autoResizeTestSet( IndexType pos, bool val = true ) { return base::autoResizeTestSet( pos, val ); }
266
268 template <typename M>
269 [[nodiscard]] TypedBitSet getMapping( const M & map ) const;
270 [[nodiscard]] TypedBitSet getMapping( const Vector<IndexType, IndexType> & map ) const
271 { return getMapping( [&map]( IndexType i ) { return map[i]; } ); }
272 [[nodiscard]] TypedBitSet getMapping( const BMap<IndexType, IndexType> & map ) const
273 { return getMapping( [&map]( IndexType i ) { return map.b[i]; }, map.tsize ); }
274 [[nodiscard]] TypedBitSet getMapping( const HashMap<IndexType, IndexType> & map ) const
275 { return getMapping( [&map]( IndexType i ) { return getAt( map, i ); } ); }
277 template <typename M>
278 [[nodiscard]] TypedBitSet getMapping( const M & map, size_t resSize ) const;
279 [[nodiscard]] TypedBitSet getMapping( const Vector<IndexType, IndexType> & map, size_t resSize ) const
280 { return getMapping( [&map]( IndexType i ) { return map[i]; }, resSize ); }
281 [[nodiscard]] TypedBitSet getMapping( const HashMap<IndexType, IndexType> & map, size_t resSize ) const
282 { return getMapping( [&map]( IndexType i ) { return getAt( map, i ); }, resSize ); }
283
285 [[nodiscard]] IndexType backId() const { assert( !empty() ); return IndexType{ size() - 1 }; }
286
288 [[nodiscard]] static IndexType beginId() { return IndexType{ size_t( 0 ) }; }
289 [[nodiscard]] IndexType endId() const { return IndexType{ size() }; }
290};
291
292
294[[nodiscard]] inline size_t heapBytes( const BitSet& bs )
295{
296 return bs.heapBytes();
297}
298
300[[nodiscard]] MRMESH_API bool operator == ( const BitSet & a, const BitSet & b );
301template <typename I>
302[[nodiscard]] inline bool operator == ( const TypedBitSet<I> & a, const TypedBitSet<I> & b )
303 { return static_cast<const BitSet &>( a ) == static_cast<const BitSet &>( b ); }
305template <typename T, typename U>
306void operator == ( const TypedBitSet<T> & a, const TypedBitSet<U> & b ) = delete;
307
308template <typename I>
309[[nodiscard]] inline std::function<bool( I )> makePredicate( const TypedBitSet<I> * bitset )
310{
311 std::function<bool( I )> res;
312 if ( bitset )
313 res = [bitset]( I id ) { return bitset->test( id ); };
314 return res;
315}
316
317template <typename I>
318[[nodiscard]] inline std::function<bool( I )> makePredicate( const TypedBitSet<I> & bitset )
319 { return makePredicate( &bitset ); }
320
321template <typename I>
322[[nodiscard]] inline bool contains( const TypedBitSet<I> * bitset, I id )
323{
324 return id.valid() && ( !bitset || bitset->test( id ) );
325}
326
327template <typename I>
328[[nodiscard]] inline bool contains( const TypedBitSet<I> & bitset, I id )
329{
330 return id.valid() && bitset.test( id );
331}
332
334template <typename T>
336{
337public:
338 using IndexType = typename T::IndexType;
339
340 using iterator_category = std::forward_iterator_tag;
342 using difference_type = std::ptrdiff_t;
343 using reference = const IndexType;
344 using pointer = const IndexType *;
345
347 SetBitIteratorT() = default;
349 SetBitIteratorT( const T & bitset )
350 : bitset_( &bitset ), index_( bitset.find_first() )
351 {
352 }
354 {
355 index_ = bitset_->find_next( index_ );
356 return * this;
357 }
358 [[nodiscard]] SetBitIteratorT operator++( int )
359 {
360 SetBitIteratorT ret = *this;
361 operator++();
362 return ret;
363 }
364
365 [[nodiscard]] const T * bitset() const { return bitset_; }
366 [[nodiscard]] reference operator *() const { return index_; }
367
368 [[nodiscard]] friend bool operator ==( const SetBitIteratorT<T> & a, const SetBitIteratorT<T> & b ) { return *a == *b; }
369
370private:
371 const T * bitset_ = nullptr;
372 IndexType index_ = IndexType( ~size_t( 0 ) );
373};
374
375
376[[nodiscard]] MR_BIND_IGNORE inline auto begin( const BitSet & a )
377 { return SetBitIteratorT<BitSet>(a); }
378[[nodiscard]] MR_BIND_IGNORE inline auto end( const BitSet & )
379 { return SetBitIteratorT<BitSet>(); }
380
381template <typename I>
382[[nodiscard]] MR_BIND_IGNORE inline auto begin( const TypedBitSet<I> & a )
383 { return SetBitIteratorT<TypedBitSet<I>>(a); }
384template <typename I>
385[[nodiscard]] MR_BIND_IGNORE inline auto end( const TypedBitSet<I> & )
386 { return SetBitIteratorT<TypedBitSet<I>>(); }
387
389template <typename I>
391{
392 Vector<int, I> res( bs.size(), -1 );
393 int n = 0;
394 for ( auto v : bs )
395 res[v] = n++;
396 return res;
397}
398
400template <typename I>
402{
403 HashMap<I, int> res;
404 int n = 0;
405 for ( auto v : bs )
406 res[v] = n++;
407 return res;
408}
409
410template <typename I>
411template <typename M>
412[[nodiscard]] TypedBitSet<I> TypedBitSet<I>::getMapping( const M & map ) const
413{
414 TypedBitSet<I> res;
415 for ( auto b : *this )
416 if ( auto mapped = map( b ) )
417 res.autoResizeSet( mapped );
418 return res;
419}
420
421template <typename I>
422template <typename M>
423[[nodiscard]] TypedBitSet<I> TypedBitSet<I>::getMapping( const M & map, size_t resSize ) const
424{
425 TypedBitSet<I> res;
426 if ( !any() )
427 return res;
428 res.resize( resSize );
429 for ( auto b : *this )
430 if ( auto mapped = map( b ) )
431 res.set( mapped );
432 return res;
433}
434
435[[nodiscard]] inline BitSet operator & ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res &= b; return res; }
436[[nodiscard]] inline BitSet operator | ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res |= b; return res; }
437[[nodiscard]] inline BitSet operator ^ ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res ^= b; return res; }
438[[nodiscard]] inline BitSet operator - ( const BitSet & a, const BitSet & b ) { BitSet res{ a }; res -= b; return res; }
439
441
442} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
#define M(T)
Definition MRMesh/MRBitSet.h:23
size_t size_type
Definition MRMesh/MRBitSet.h:29
size_t IndexType
Definition MRMesh/MRBitSet.h:30
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:26
IndexType endId() const
Definition MRMesh/MRBitSet.h:166
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:165
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:25
void reserve(size_type numBits)
Definition MRMesh/MRBitSet.h:47
MRMESH_API void resize(size_type numBits, bool fillValue=false)
BitSet() noexcept=default
creates empty bitset
bool empty() const noexcept
Definition MRMesh/MRBitSet.h:52
BitSet & set(IndexType n)
Definition MRMesh/MRBitSet.h:66
void autoResizeSet(size_t pos, bool val=true)
Definition MRMesh/MRBitSet.h:147
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:150
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:62
bool uncheckedTest(IndexType n) const
Definition MRMesh/MRBitSet.h:57
static BitSet fromBlocks(std::vector< block_type > &&blocks)
creates bitset from the given blocks of bits
Definition MRMesh/MRBitSet.h:39
MRMESH_API BitSet & set()
void clear()
Definition MRMesh/MRBitSet.h:49
size_type size() const noexcept
Definition MRMesh/MRBitSet.h:53
bool uncheckedTestSet(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:58
BitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:70
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:61
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:113
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:141
size_type num_blocks() const noexcept
Definition MRMesh/MRBitSet.h:54
BitSet & set(IndexType n, bool val)
Definition MRMesh/MRBitSet.h:65
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:162
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:128
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:110
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:81
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:55
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:87
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRBitSet.h:159
MRMESH_API BitSet & operator|=(const BitSet &b)
bool none() const
returns true if all bits in this container are reset
Definition MRMesh/MRBitSet.h:104
MRMESH_API BitSet & operator^=(const BitSet &b)
static constexpr size_t npos
Definition MRMesh/MRBitSet.h:27
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:84
BitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:74
void shrink_to_fit()
Definition MRMesh/MRBitSet.h:50
iterator to enumerate all indices with set bits in BitSet class or its derivatives
Definition MRMesh/MRBitSet.h:336
SetBitIteratorT operator++(int)
Definition MRMesh/MRBitSet.h:358
const IndexType * pointer
Definition MRMesh/MRBitSet.h:344
SetBitIteratorT()=default
constructs end iterator
std::forward_iterator_tag iterator_category
Definition MRMesh/MRBitSet.h:340
const T * bitset() const
Definition MRMesh/MRBitSet.h:365
IndexType value_type
Definition MRMesh/MRBitSet.h:341
const IndexType reference
intentionally not a reference
Definition MRMesh/MRBitSet.h:343
typename T::IndexType IndexType
Definition MRMesh/MRBitSet.h:338
SetBitIteratorT & operator++()
Definition MRMesh/MRBitSet.h:353
SetBitIteratorT(const T &bitset)
constructs begin iterator
Definition MRMesh/MRBitSet.h:349
std::ptrdiff_t difference_type
Definition MRMesh/MRBitSet.h:342
Definition MRMesh/MRBitSet.h:213
IndexType find_last() const
Definition MRMesh/MRBitSet.h:240
TypedBitSet & operator|=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:245
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:261
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:236
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:274
friend TypedBitSet operator|(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:250
friend TypedBitSet operator&(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:249
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:288
TypedBitSet(const BitSet &src)
copies all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRMesh/MRBitSet.h:220
TypedBitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:233
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:285
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:281
TypedBitSet & operator-=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:247
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:225
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:258
TypedBitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:229
friend TypedBitSet operator-(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:252
TypedBitSet & operator^=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:246
TypedBitSet & set()
Definition MRMesh/MRBitSet.h:228
void autoResizeSet(IndexType pos, size_type len, bool val=true)
Definition MRMesh/MRBitSet.h:263
IndexType endId() const
Definition MRMesh/MRBitSet.h:289
I IndexType
Definition MRMesh/MRBitSet.h:217
TypedBitSet & flip()
Definition MRMesh/MRBitSet.h:234
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:279
IndexType find_first() const
Definition MRMesh/MRBitSet.h:238
friend TypedBitSet operator^(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:251
TypedBitSet & set(IndexType n, bool val)
Definition MRMesh/MRBitSet.h:226
TypedBitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:232
TypedBitSet & operator&=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:244
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:264
IndexType find_next(IndexType pos) const
Definition MRMesh/MRBitSet.h:239
TypedBitSet & reset()
Definition MRMesh/MRBitSet.h:231
bool autoResizeTestSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:265
TypedBitSet(BitSet &&src)
moves all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRMesh/MRBitSet.h:223
TypedBitSet & set(IndexType n)
Definition MRMesh/MRBitSet.h:227
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:255
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:270
TypedBitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:230
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:242
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:235
TypedBitSet getMapping(const BMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:272
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:438
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:376
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:401
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:435
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:390
bool contains(const TypedBitSet< I > *bitset, I id)
Definition MRMesh/MRBitSet.h:322
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:436
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:378
std::function< bool(I)> makePredicate(const TypedBitSet< I > *bitset)
Definition MRMesh/MRBitSet.h:309
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:437
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRMesh/MRBitSet.h:294
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 MRMesh/MRMeshFwd.h:194
Color operator*(float a, const Color &b)
Definition MRMesh/MRColor.h:116
I
Definition MRMesh/MRMeshFwd.h:130
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:10
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:592
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