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 ); }
37 explicit BitSet(
size_t,
unsigned long ) =
delete;
38 template<class T, std::enable_if_t<std::is_arithmetic<T>::value, std::nullptr_t> =
nullptr>
43 [[nodiscard]]
bool test_set(
IndexType n,
bool val =
true ) {
return ( val || n <
size() ) ? base::test_set( n, val ) :
false; }
45 BitSet &
set(
IndexType n, size_type len,
bool val ) { base::set( n, len, val );
return *
this; }
56 const auto &
bits()
const {
return m_bits; }
75 auto reserved = capacity();
76 if ( reserved > 0 && newSize > reserved )
78 while ( newSize > reserved )
88 if ( pos + len >
size() )
97 bool const b =
test( pos );
104 [[nodiscard]]
size_t heapBytes()
const {
return capacity() / 8; }
114 #if defined(MR_PARSING_FOR_PB11_BINDINGS) || defined(MR_COMPILING_PB11_BINDINGS)
115 std::size_t
size()
const {
return dynamic_bitset::size(); }
116 std::size_t count()
const {
return dynamic_bitset::count(); }
117 void resize( std::size_t num_bits,
bool value =
false ) { dynamic_bitset::resize( num_bits, value ); }
118 void clear() { dynamic_bitset::clear(); }
119 void push_back(
bool bit ) { dynamic_bitset::push_back( bit ); }
120 void pop_back() { dynamic_bitset::pop_back(); }
124 using base::m_highest_block;
126 using base::m_num_bits;
193 template <
typename M>
202 template <
typename M>
228 {
return static_cast<const BitSet &
>( a ) ==
static_cast<const BitSet &
>( b ); }
230template <
typename T,
typename U>
236 std::function<bool( I )> res;
238 res = [bitset]( I id ) {
return bitset->
test(
id ); };
249 return id.valid() && ( !bitset || bitset->
test(
id ) );
255 return id.valid() && bitset.
test(
id );
275 : bitset_( &bitset ), index_( bitset.find_first() )
280 index_ = bitset_->find_next( index_ );
290 [[nodiscard]]
const T *
bitset()
const {
return bitset_; }
294 const T * bitset_ =
nullptr;
295 IndexType index_ = IndexType( ~
size_t( 0 ) );
309[[nodiscard]] MR_BIND_IGNORE
inline auto end(
const BitSet & )
346 for (
auto b : *this )
347 if (
auto mapped = map( b ) )
359 res.resize( resSize );
360 for (
auto b : *this )
361 if (
auto mapped = map( b ) )
constexpr auto operator*(A a, B b)
Definition MRImGuiVectorOperators.h:107
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
container of bits
Definition MRMesh/MRBitSet.h:27
size_t IndexType
Definition MRMesh/MRBitSet.h:31
IndexType endId() const
Definition MRMesh/MRBitSet.h:111
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:110
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:50
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(size_t, unsigned long)=delete
prohibit these constructors inherited from boost::dynamic_bitset, which can initialize only few initi...
BitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:45
BitSet & set()
Definition MRMesh/MRBitSet.h:47
void autoResizeSet(size_t pos, bool val=true)
Definition MRMesh/MRBitSet.h:92
BitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:48
BitSet & set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:46
bool autoResizeTestSet(size_t pos, bool val=true)
same as autoResizeSet and returns previous value of pos-bit
Definition MRMesh/MRBitSet.h:95
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:43
BitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:51
BitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:49
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:42
BitSet & flip()
Definition MRMesh/MRBitSet.h:53
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:86
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:107
void resizeWithReserve(size_t newSize)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRBitSet.h:73
const auto & bits() const
read-only access to all bits stored as a vector of uint64 blocks
Definition MRMesh/MRBitSet.h:56
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRBitSet.h:104
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:52
iterator to enumerate all indices with set bits in BitSet class or its derivatives
Definition MRMesh/MRBitSet.h:261
SetBitIteratorT operator++(int)
Definition MRMesh/MRBitSet.h:283
const IndexType * pointer
Definition MRMesh/MRBitSet.h:269
SetBitIteratorT()=default
constructs end iterator
std::forward_iterator_tag iterator_category
Definition MRMesh/MRBitSet.h:265
const T * bitset() const
Definition MRMesh/MRBitSet.h:290
IndexType value_type
Definition MRMesh/MRBitSet.h:266
const IndexType reference
intentionally not a reference
Definition MRMesh/MRBitSet.h:268
typename T::IndexType IndexType
Definition MRMesh/MRBitSet.h:263
SetBitIteratorT & operator++()
Definition MRMesh/MRBitSet.h:278
SetBitIteratorT(const T &bitset)
constructs begin iterator
Definition MRMesh/MRBitSet.h:274
std::ptrdiff_t difference_type
Definition MRMesh/MRBitSet.h:267
container of bits representing specific indices (faces, verts or edges)
Definition MRMesh/MRBitSet.h:132
IndexType find_last() const
Definition MRMesh/MRBitSet.h:162
TypedBitSet & operator|=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:167
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:186
bool test_set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:154
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:199
friend TypedBitSet operator|(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:172
friend TypedBitSet operator&(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:171
static IndexType beginId()
[beginId(), endId()) is the range of all bits in the set
Definition MRMesh/MRBitSet.h:213
TypedBitSet(const BitSet &src)
copies all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRMesh/MRBitSet.h:139
TypedBitSet & flip(IndexType n)
Definition MRMesh/MRBitSet.h:151
IndexType backId() const
returns the identifier of the back() element
Definition MRMesh/MRBitSet.h:210
MR_BIND_IGNORE reference operator[](IndexType pos)
Definition MRMesh/MRBitSet.h:157
TypedBitSet getMapping(const HashMap< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:206
TypedBitSet & operator-=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:169
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:144
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:180
TypedBitSet & reset(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:147
friend TypedBitSet operator-(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:174
TypedBitSet & operator^=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:168
TypedBitSet & set()
Definition MRMesh/MRBitSet.h:146
void autoResizeSet(IndexType pos, size_type len, bool val=true)
Definition MRMesh/MRBitSet.h:188
bool operator[](IndexType pos) const
Definition MRMesh/MRBitSet.h:158
IndexType endId() const
Definition MRMesh/MRBitSet.h:214
I IndexType
Definition MRMesh/MRBitSet.h:136
TypedBitSet & flip()
Definition MRMesh/MRBitSet.h:152
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map, size_t resSize) const
Definition MRMesh/MRBitSet.h:204
IndexType find_first() const
Definition MRMesh/MRBitSet.h:160
friend TypedBitSet operator^(const TypedBitSet &a, const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:173
TypedBitSet & flip(IndexType n, size_type len)
Definition MRMesh/MRBitSet.h:150
TypedBitSet & operator&=(const TypedBitSet &b)
Definition MRMesh/MRBitSet.h:166
bool is_proper_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:183
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:189
IndexType find_next(IndexType pos) const
Definition MRMesh/MRBitSet.h:161
TypedBitSet & reset()
Definition MRMesh/MRBitSet.h:149
bool autoResizeTestSet(IndexType pos, bool val=true)
Definition MRMesh/MRBitSet.h:190
TypedBitSet(BitSet &&src)
moves all bits from another BitSet (or a descending class, e.g. TypedBitSet)
Definition MRMesh/MRBitSet.h:142
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:177
TypedBitSet getMapping(const Vector< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:195
TypedBitSet & reset(IndexType n)
Definition MRMesh/MRBitSet.h:148
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:164
bool test(IndexType n) const
Definition MRMesh/MRBitSet.h:153
TypedBitSet getMapping(const BMap< IndexType, IndexType > &map) const
Definition MRMesh/MRBitSet.h:197
TypedBitSet & set(IndexType n, bool val=true)
Definition MRMesh/MRBitSet.h:145
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:369
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:307
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:332
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:366
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:321
bool contains(const TypedBitSet< I > *bitset, I id)
Definition MRMesh/MRBitSet.h:247
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:367
MR_BIND_IGNORE bool operator!=(const SetBitIteratorT< T > &a, const SetBitIteratorT< T > &b)
Definition MRMesh/MRBitSet.h:303
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:309
std::function< bool(I)> makePredicate(const TypedBitSet< I > *bitset)
Definition MRMesh/MRBitSet.h:234
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:368
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRMesh/MRBitSet.h:219
Definition MRCameraOrientationPlugin.h:8
class MRMESH_CLASS BitSet
Definition MRMesh/MRMeshFwd.h:139
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:29
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
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMesh/MRMeshFwd.h:528
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