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; }
40 BitSet &
set(
IndexType n, size_type len,
bool val ) { base::set( n, len, val );
return *
this; }
51 const auto &
bits()
const {
return m_bits; }
70 auto reserved = capacity();
71 if ( reserved > 0 && newSize > reserved )
73 while ( newSize > reserved )
83 if ( pos + len >
size() )
92 bool const b =
test( pos );
99 [[nodiscard]]
size_t heapBytes()
const {
return capacity() / 8; }
109 #if defined(MR_PARSING_FOR_PB11_BINDINGS) || defined(MR_COMPILING_PB11_BINDINGS)
110 std::size_t
size()
const {
return dynamic_bitset::size(); }
111 std::size_t count()
const {
return dynamic_bitset::count(); }
112 void resize( std::size_t num_bits,
bool value =
false ) { dynamic_bitset::resize( num_bits, value ); }
113 void clear() { dynamic_bitset::clear(); }
114 void push_back(
bool bit ) { dynamic_bitset::push_back( bit ); }
115 void pop_back() { dynamic_bitset::pop_back(); }
119 using base::m_highest_block;
121 using base::m_num_bits;
173 template <
typename M>
182 template <
typename M>
201 {
return static_cast<const BitSet &
>( a ) ==
static_cast<const BitSet &
>( b ); }
203template <
typename T,
typename U>
209 std::function<bool(
Id<T> )> res;
211 res = [bitset](
Id<T> id ) {
return bitset->
test(
id ); };
222 return id.valid() && ( !bitset || bitset->
test(
id ) );
228 return id.valid() && bitset.
test(
id );
253 index_ = bitset_->find_next( index_ );
263 [[nodiscard]]
const T *
bitset()
const {
return bitset_; }
267 const T * bitset_ =
nullptr;
319 for (
auto b : *this )
320 if (
auto mapped = map( b ) )
332 res.resize( resSize );
333 for (
auto b : *this )
334 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:106
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:105
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:45
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:40
BitSet & set()
Definition MRMesh/MRBitSet.h:42
void autoResizeSet(size_t pos, bool val=true)
Definition MRMesh/MRBitSet.h:87
BitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:43
BitSet & set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:41
bool autoResizeTestSet(size_t pos, bool val=true)
same as autoResizeSet and returns previous value of pos-bit
Definition MRMesh/MRBitSet.h:90
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:38
BitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:46
BitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:44
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:37
BitSet & flip()
Definition MRMesh/MRBitSet.h:48
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:81
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:102
void resizeWithReserve(size_t newSize)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRBitSet.h:68
const auto & bits() const
read-only access to all bits stored as a vector of uint64 blocks
Definition MRMesh/MRBitSet.h:51
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRBitSet.h:99
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:47
Definition MRMesh/MRId.h:13
iterator to enumerate all indices with set bits in BitSet class or its derivatives
Definition MRMesh/MRBitSet.h:234
SetBitIteratorT operator++(int)
Definition MRMesh/MRBitSet.h:256
const IndexType * pointer
Definition MRMesh/MRBitSet.h:242
SetBitIteratorT()=default
constructs end iterator
std::forward_iterator_tag iterator_category
Definition MRMesh/MRBitSet.h:238
const T * bitset() const
Definition MRMesh/MRBitSet.h:263
IndexType value_type
Definition MRMesh/MRBitSet.h:239
const IndexType reference
intentionally not a reference
Definition MRMesh/MRBitSet.h:241
typename T::IndexType IndexType
Definition MRMesh/MRBitSet.h:236
reference operator*() const
Definition MRMesh/MRBitSet.h:264
SetBitIteratorT & operator++()
Definition MRMesh/MRBitSet.h:251
SetBitIteratorT(const T &bitset)
constructs begin iterator
Definition MRMesh/MRBitSet.h:247
std::ptrdiff_t difference_type
Definition MRMesh/MRBitSet.h:240
container of bits representing specific indices (faces, verts or edges)
Definition MRMesh/MRBitSet.h:127
TaggedBitSet & operator^=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:163
TaggedBitSet getMapping(const Vector< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:184
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:149
TaggedBitSet(BitSet &&src)
moves all bits from another BitSet (or a descending class, e.g. TaggedBitSet)
Definition MRMesh/MRBitSet.h:137
TaggedBitSet & operator-=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:164
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:148
TaggedBitSet & operator|=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:162
TaggedBitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:142
bool autoResizeTestSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:170
IndexType endId() const
Definition MRMesh/MRBitSet.h:194
MR_BIND_IGNORE reference operator[](IndexType pos)
Definition MRMesh/MRBitSet.h:152
TaggedBitSet & flip()
Definition MRMesh/MRBitSet.h:147
void autoResizeSet(IndexType pos, size_type len, bool val=true)
Definition MRMesh/MRBitSet.h:168
IndexType find_next(IndexType pos) const
Definition MRMesh/MRBitSet.h:156
TaggedBitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:143
IndexType find_first() const
Definition MRMesh/MRBitSet.h:155
TaggedBitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:139
IndexType find_last() const
Definition MRMesh/MRBitSet.h:157
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:166
TaggedBitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:146
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:175
TaggedBitSet & operator&=(const TaggedBitSet &b)
Definition MRMesh/MRBitSet.h:161
TaggedBitSet & set()
Definition MRMesh/MRBitSet.h:141
TaggedBitSet(const BitSet &src)
copies all bits from another BitSet (or a descending class, e.g. TaggedBitSet)
Definition MRMesh/MRBitSet.h:134
TaggedBitSet getMapping(const HashMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:179
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:190
TaggedBitSet getMapping(const BMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:177
bool operator[](IndexType pos) const
Definition MRMesh/MRBitSet.h:153
TaggedBitSet getMapping(const HashMap< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:186
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:193
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:159
void autoResizeSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:169
TaggedBitSet & reset()
Definition MRMesh/MRBitSet.h:144
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:131
TaggedBitSet & set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:140
TaggedBitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:145
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:342
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:280
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:282
BitSet operator&(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:339
std::function< bool(Id< T >)> makePredicate(const TaggedBitSet< T > *bitset)
Definition MRMesh/MRBitSet.h:207
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:294
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:340
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:341
bool contains(const TaggedBitSet< T > *bitset, Id< T > id)
Definition MRMesh/MRBitSet.h:220
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:305
bool operator!=(const SetBitIteratorT< T > &a, const SetBitIteratorT< T > &b)
Definition MRMesh/MRBitSet.h:276
Definition MRCameraOrientationPlugin.h:8
class MRMESH_CLASS BitSet
Definition MRMesh/MRMeshFwd.h:102
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:460
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