28 static const size_t BITS_IN_BYTE = 8;
49 static inline unsigned getMask (
size_t dist ) {
50 return ( ( 1u ) << dist ) - 1;
56 size_t sizeWithin =
m_Size % (
sizeof ( unsigned ) * BITS_IN_BYTE );
57 size_t sizeBlocks =
m_Size / (
sizeof ( unsigned ) * BITS_IN_BYTE ) +
static_cast < unsigned > ( sizeWithin != 0 );
58 unsigned mask = getMask ( sizeWithin );
62 for ( ; elementIter !=
m_Data.end ( ); ++ elementIter ) {
63 if ( sizeBlocks <= elementIter->run + 1 )
65 sizeBlocks -= elementIter->run + 1;
69 if ( sizeBlocks == elementIter->run + 1 ) {
71 elementIter->word &= mask;
73 elementIter->run = sizeBlocks - 1;
74 elementIter->word = 0;
78 for ( ; elementIter !=
m_Data.end ( ); ) {
79 elementIter =
m_Data.erase ( elementIter );
83 unsigned runCarry = 0;
84 for ( elementIter =
m_Data.begin ( ); elementIter !=
m_Data.end ( ); ++ elementIter ) {
85 while ( elementIter->word == 0 && std::next ( elementIter ) !=
m_Data.end ( ) ) {
86 runCarry += elementIter->run + 1;
87 elementIter =
m_Data.erase ( elementIter );
89 elementIter->run += runCarry;
100 for (
bool boolean :
raw ) {
112 size_t sizeWithin =
m_Size % (
sizeof ( unsigned ) * BITS_IN_BYTE );
116 }
else if ( sizeWithin == 0 &&
m_Data.back ( ).word == 0 ) {
118 }
else if ( sizeWithin == 0 &&
m_Data.back ( ).word != 0 ) {
122 m_Data.back ( ).word |=
static_cast < unsigned > (
boolean ) << sizeWithin;
129 size_t sizeWithin = index % (
sizeof ( unsigned ) * BITS_IN_BYTE );
130 size_t sizeBlocks = index / (
sizeof ( unsigned ) * BITS_IN_BYTE );
133 for ( ; elementIter !=
m_Data.end ( ); ++ elementIter ) {
134 if ( elementIter->run + 1 > sizeBlocks )
136 sizeBlocks -= elementIter->run + 1;
138 if ( elementIter->run > sizeBlocks )
141 return static_cast < bool > ( elementIter->word & 1u << sizeWithin );
154 BitReference & operator = (
bool value ) {
155 if ( elementIter->run > sizeBlocks ) {
156 elementIter->run -= sizeBlocks + 1;
157 elementIter =
data.insert ( elementIter, element {
static_cast < unsigned > ( sizeBlocks ), 0 } );
160 elementIter->word |= 1u << sizeWithin;
162 elementIter->word &= ~ ( 1u << sizeWithin );
168 if ( elementIter->run > sizeBlocks )
171 return elementIter->word & 1u << sizeWithin;
178 size_t sizeWithin = index % (
sizeof ( unsigned ) * BITS_IN_BYTE );
179 size_t sizeBlocks = index / (
sizeof ( unsigned ) * BITS_IN_BYTE );
182 for ( ; elementIter !=
m_Data.end ( ); ++ elementIter ) {
183 if ( elementIter->run + 1 > sizeBlocks )
185 sizeBlocks -= elementIter->run + 1;
187 return BitReference (
m_Data, elementIter, sizeWithin, sizeBlocks );
196 for (
unsigned i = 0;
i < elem.run ; ++
i )
197 for (
size_t j = 0; j <
sizeof ( unsigned ) * BITS_IN_BYTE; ++j )
198 res.push_back (
false );
200 for (
size_t i = 0;
i <
sizeof ( unsigned ) * BITS_IN_BYTE; ++
i ) {
201 res.push_back ( elem.word & 1u <<
i );
215 size_t added = ( newSize -
m_Size ) / (
sizeof (
unsigned ) * BITS_IN_BYTE ) + 1;
216 m_Data.push_back (
element {
static_cast < unsigned > ( added ), 0 } );
244 if ( A.
m_Size == 0 || dist == 0 )
247 size_t distBlocks = dist / (
sizeof ( unsigned ) * BITS_IN_BYTE );
248 size_t distWithin = dist % (
sizeof ( unsigned ) * BITS_IN_BYTE );
249 size_t backDist =
sizeof ( unsigned ) * BITS_IN_BYTE - distWithin;
252 A.
m_Data.front ( ).run += distBlocks;
254 if ( distWithin == 0 ) {
259 unsigned shiftedWord = 0;
261 for (
auto elementIter = A.
m_Data.begin ( ); elementIter != A.
m_Data.end ( ); ++ elementIter ) {
262 if ( shiftedWord != 0 && elementIter->run != 0 ) {
264 elementIter->run -= 1;
266 elementIter = A.
m_Data.insert ( elementIter,
element { 0, shiftedWord } );
270 unsigned tmp = elementIter->word >> backDist;
271 elementIter->word = elementIter->word << distWithin | shiftedWord;
289 out <<
"(" << elem.
m_Size <<
", " << elem.
m_Data <<
")";
294 out <<
"(" << elem.
run <<
", ";
295 for (
size_t i = 0;
i <
sizeof ( elem.
word ) * BITS_IN_BYTE; ++
i )
296 out <<
static_cast < bool > ( elem.
word & 1u <<
i );
310 if ( underlying == underlyingEnd ) {
315 index =
sizeof ( unsigned ) * BITS_IN_BYTE * underlying->run;
316 if ( underlying->word & 1u )
324 if ( underlying == underlyingEnd )
328 size_t innerIndex = index % (
sizeof ( unsigned ) * BITS_IN_BYTE );
333 if ( innerIndex ==
sizeof (
unsigned ) * BITS_IN_BYTE )
337 if ( underlying == underlyingEnd )
341 if ( innerIndex ==
sizeof (
unsigned ) * BITS_IN_BYTE )
342 index +=
sizeof (
unsigned ) * BITS_IN_BYTE * underlying->run;
346 for ( innerIndex = index % (
sizeof (
unsigned ) * BITS_IN_BYTE ); innerIndex <
sizeof ( unsigned ) * BITS_IN_BYTE; ++ innerIndex ) {
348 if ( underlying->word & ( 1u << innerIndex ) )
358 if ( underlying == underlyingEnd )
362 index +=
sizeof ( unsigned ) * BITS_IN_BYTE * underlying->run;
374 return underlying == underlyingEnd && other.underlying == other.underlyingEnd && underlying == other.underlying;
378 return ! ( *
this == other );
402 size_t blocksA = iterA->run;
403 size_t blocksB = iterB->run;
405 while ( iterA != A.
m_Data.end ( ) && iterB != B.
m_Data.end ( ) ) {
406 if ( blocksA == blocksB ) {
407 iterA->word &= iterB->word;
410 blocksA += 1 + iterA->run;
413 blocksB += 1 + iterB->run;
414 }
else if ( blocksA < blocksB ) {
418 blocksA += 1 + iterA->run;
421 blocksB += 1 + iterB->run;
425 while ( iterA != A.
m_Data.end ( ) ) {
Definition: SparseBoolVector.hpp:303
SparseBoolVectorOnesIterator(ext::list< element >::const_iterator iterBegin, ext::list< element >::const_iterator iterEnd, size_t ind)
Definition: SparseBoolVector.hpp:309
bool operator!=(const SparseBoolVectorOnesIterator &other) const
Definition: SparseBoolVector.hpp:377
bool operator==(const SparseBoolVectorOnesIterator &other) const
Definition: SparseBoolVector.hpp:373
SparseBoolVectorOnesIterator & operator++()
Definition: SparseBoolVector.hpp:323
size_t operator*() const
Definition: SparseBoolVector.hpp:381
Definition: SparseBoolVector.hpp:27
bool operator==(const SparseBoolVector &other) const
Definition: SparseBoolVector.hpp:233
bool operator[](size_t index) const
Definition: SparseBoolVector.hpp:128
size_t m_Size
Definition: SparseBoolVector.hpp:46
size_t size() const
Definition: SparseBoolVector.hpp:223
SparseBoolVectorOnesIterator end() const
Definition: SparseBoolVector.hpp:390
ext::list< element > m_Data
Definition: SparseBoolVector.hpp:45
void resize(size_t newSize)
Definition: SparseBoolVector.hpp:212
friend SparseBoolVector operator&(SparseBoolVector A, const SparseBoolVector &B)
Definition: SparseBoolVector.hpp:435
const ext::list< element > & data() const
Definition: SparseBoolVector.hpp:227
void push_back(bool boolean)
Definition: SparseBoolVector.hpp:111
SparseBoolVector()=default
friend SparseBoolVector operator<<(SparseBoolVector A, size_t dist)
Definition: SparseBoolVector.hpp:281
friend SparseBoolVector & operator<<=(SparseBoolVector &A, size_t dist)
Definition: SparseBoolVector.hpp:243
SparseBoolVector(const ext::vector< bool > &raw)
Definition: SparseBoolVector.hpp:99
friend SparseBoolVector & operator&=(SparseBoolVector &A, const SparseBoolVector &B)
Definition: SparseBoolVector.hpp:396
SparseBoolVectorOnesIterator begin() const
Definition: SparseBoolVector.hpp:386
std::strong_ordering operator<=>(const SparseBoolVector &other) const
Definition: SparseBoolVector.hpp:237
SparseBoolVector(ext::list< element > data, size_t size)
Definition: SparseBoolVector.hpp:105
Class extending the list class from the standard library. Original reason is to allow printing of the...
Definition: list.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
Definition: Permutation.hpp:18
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
typename std::conditional< value, std::true_type, std::false_type >::type boolean
Definition: type_traits.hpp:145
Definition: RawRegistration.hpp:13
Definition: FordFulkerson.hpp:16
Definition: SparseBoolVector.hpp:32
unsigned run
Definition: SparseBoolVector.hpp:33
unsigned word
Definition: SparseBoolVector.hpp:34
bool operator==(const element &other) const
Definition: SparseBoolVector.hpp:36
std::strong_ordering operator<=>(const element &other) const
Definition: SparseBoolVector.hpp:40