7#include "MRPch/MRBindingMacros.h"
8#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
10#pragma warning(disable: 4643)
11#include <boost/dynamic_bitset.hpp>
26class BitSet :
public boost::dynamic_bitset<std::uint64_t>
29 using base = boost::dynamic_bitset<std::uint64_t>;
34 explicit BitSet(
size_t numBits,
bool fillValue ) { resize( numBits, fillValue ); }
38 [[nodiscard]]
bool test_set(
IndexType n,
bool val =
true ) {
return ( val || n <
size() ) ? base::test_set( n, val ) :
false; }
39 BitSet &
set(
IndexType n, size_type len,
bool val ) { base::set( n, len, val );
return *
this; }
64 auto reserved = capacity();
65 if ( reserved > 0 && newSize > reserved )
67 while ( newSize > reserved )
77 if ( pos + len >
size() )
86 bool const b =
test( pos );
93 [[nodiscard]]
size_t heapBytes()
const {
return capacity() / 8; }
103 #if defined(MR_PARSING_FOR_PB11_BINDINGS) || defined(MR_COMPILING_PB11_BINDINGS)
104 std::size_t
size()
const {
return dynamic_bitset::size(); }
105 std::size_t count()
const {
return dynamic_bitset::count(); }
106 void resize( std::size_t num_bits,
bool value =
false ) { dynamic_bitset::resize( num_bits, value ); }
107 void clear() { dynamic_bitset::clear(); }
108 void push_back(
bool bit ) { dynamic_bitset::push_back( bit ); }
109 void pop_back() { dynamic_bitset::pop_back(); }
156 template <
typename M>
165 template <
typename M>
184 {
return static_cast<const BitSet &
>( a ) ==
static_cast<const BitSet &
>( b ); }
186template <
typename T,
typename U>
192 std::function<bool(
Id<T> )> res;
194 res = [bitset](
Id<T> id ) {
return bitset->
test(
id ); };
205 return id.valid() && ( !bitset || bitset->
test(
id ) );
211 return id.valid() && bitset.
test(
id );
236 index_ = bitset_->find_next( index_ );
246 [[nodiscard]]
const T *
bitset()
const {
return bitset_; }
250 const T * bitset_ =
nullptr;
302 for (
auto b : *this )
303 if (
auto mapped = map( b ) )
315 res.resize( resSize );
316 for (
auto b : *this )
317 if (
auto mapped = map( b ) )
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
container of bits
Definition MRMesh/MRBitSet.h:27
size_t IndexType
Definition MRMesh/MRBitSet.h:31
IndexType endId() const
Definition MRMesh/MRBitSet.h:100
boost::dynamic_bitset< std::uint64_t > base
Definition MRMesh/MRBitSet.h:29
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:99
MRMESH_API IndexType find_last() const
return the highest index i such as bit i is set, or npos if *this has no on bits.
BitSet & reset()
Definition MRMesh/MRBitSet.h:44
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)
BitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:39
BitSet & set()
Definition MRMesh/MRBitSet.h:41
void autoResizeSet(size_t pos, bool val=true)
Definition MRMesh/MRBitSet.h:81
BitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:42
BitSet & set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:40
bool autoResizeTestSet(size_t pos, bool val=true)
same as autoResizeSet and returns previous value of pos-bit
Definition MRMesh/MRBitSet.h:84
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:38
BitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:45
BitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:43
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:37
BitSet & flip()
Definition MRMesh/MRBitSet.h:47
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:75
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:96
void resizeWithReserve(size_t newSize)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRBitSet.h:62
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRBitSet.h:93
BitSet(size_t numBits, bool fillValue)
creates bitset of given size filled with given value
Definition MRMesh/MRBitSet.h:34
MRMESH_API BitSet & operator|=(const BitSet &b)
MRMESH_API BitSet & operator^=(const BitSet &b)
MRMESH_API BitSet & operator&=(const BitSet &b)
BitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:46
Definition MRMesh/MRId.h:13
iterator to enumerate all indices with set bits in BitSet class or its derivatives
Definition MRMesh/MRBitSet.h:217
SetBitIteratorT operator++(int)
Definition MRMesh/MRBitSet.h:239
const IndexType * pointer
Definition MRMesh/MRBitSet.h:225
SetBitIteratorT()=default
constructs end iterator
std::forward_iterator_tag iterator_category
Definition MRMesh/MRBitSet.h:221
const T * bitset() const
Definition MRMesh/MRBitSet.h:246
IndexType value_type
Definition MRMesh/MRBitSet.h:222
const IndexType reference
intentionally not a reference
Definition MRMesh/MRBitSet.h:224
typename T::IndexType IndexType
Definition MRMesh/MRBitSet.h:219
reference operator*() const
Definition MRMesh/MRBitSet.h:247
SetBitIteratorT & operator++()
Definition MRMesh/MRBitSet.h:234
SetBitIteratorT(const T &bitset)
constructs begin iterator
Definition MRMesh/MRBitSet.h:230
std::ptrdiff_t difference_type
Definition MRMesh/MRBitSet.h:223
container of bits representing specific indices (faces, verts or edges)
Definition MRMesh/MRBitSet.h:116
TaggedBitSet & operator^=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:146
TaggedBitSet getMapping(const Vector< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:167
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:132
TaggedBitSet & operator-=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:147
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:131
TaggedBitSet & operator|=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:145
TaggedBitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:125
bool autoResizeTestSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:153
IndexType endId() const
Definition MRMesh/MRBitSet.h:177
MR_BIND_IGNORE reference operator[](IndexType pos)
Definition MRMesh/MRBitSet.h:135
TaggedBitSet & flip()
Definition MRMesh/MRBitSet.h:130
void autoResizeSet(IndexType pos, size_type len, bool val=true)
Definition MRMesh/MRBitSet.h:151
IndexType find_next(IndexType pos) const
Definition MRMesh/MRBitSet.h:139
TaggedBitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:126
IndexType find_first() const
Definition MRMesh/MRBitSet.h:138
TaggedBitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:122
IndexType find_last() const
Definition MRMesh/MRBitSet.h:140
TaggedBitSet & subtract(const TaggedBitSet &b, int bShiftInBlocks)
subtracts b from this, considering that bits in b are shifted right on bShiftInBlocks*bits_per_block
Definition MRMesh/MRBitSet.h:149
TaggedBitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:129
TaggedBitSet getMapping(const M &map) const
constructs another bit set from this where every set bit index is transformed using given map
TaggedBitSet getMapping(const Vector< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:158
TaggedBitSet & operator&=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:144
TaggedBitSet & set()
Definition MRMesh/MRBitSet.h:124
TaggedBitSet getMapping(const HashMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:162
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:173
TaggedBitSet getMapping(const BMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:160
bool operator[](IndexType pos) const
Definition MRMesh/MRBitSet.h:136
TaggedBitSet getMapping(const HashMap< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:169
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:176
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:142
void autoResizeSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:152
TaggedBitSet & reset()
Definition MRMesh/MRBitSet.h:127
TaggedBitSet getMapping(const M &map, size_t resSize) const
this is a faster version if the result size is known beforehand
Id< T > IndexType
Definition MRMesh/MRBitSet.h:120
TaggedBitSet & set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:123
TaggedBitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:128
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:325
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:263
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...
auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:265
BitSet operator&(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:322
std::function< bool(Id< T >)> makePredicate(const TaggedBitSet< T > *bitset)
Definition MRMesh/MRBitSet.h:190
Vector< int, Id< T > > makeVectorWithSeqNums(const TaggedBitSet< T > &bs)
creates a Vector where for each set bit of input bitset its sequential number starting from 0 is retu...
Definition MRMesh/MRBitSet.h:277
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:323
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:324
bool contains(const TaggedBitSet< T > *bitset, Id< T > id)
Definition MRMesh/MRBitSet.h:203
HashMap< Id< T >, int > makeHashMapWithSeqNums(const TaggedBitSet< T > &bs)
creates a HashMap where for each set bit of input bitset its sequential number starting from 0 is ret...
Definition MRMesh/MRBitSet.h:288
bool operator!=(const SetBitIteratorT< T > &a, const SetBitIteratorT< T > &b)
Definition MRMesh/MRBitSet.h:259
Definition MRCameraOrientationPlugin.h:8
class MRMESH_CLASS BitSet
Definition MRMesh/MRMeshFwd.h:101
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
T getAt(const Buffer< T, I > &bmap, I key)
given some buffer map and a key, returns the value associated with the key, or default value if key i...
Definition MRBuffer.h:119
SetBitIteratorT< BitSet >(FaceSetBitIterator, SetBitIteratorT< FaceBitSet >)(VertSetBitIterator
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:459
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