diff --git a/alib2data/src/common/SparseBoolVector.hpp b/alib2data/src/common/SparseBoolVector.hpp index e2f60074a4b68613ad52d10dac0d349b5f7993d3..e96bf1afdb96368ca4cccf30465b6004c165047c 100644 --- a/alib2data/src/common/SparseBoolVector.hpp +++ b/alib2data/src/common/SparseBoolVector.hpp @@ -26,6 +26,9 @@ namespace common { class SparseBoolVector { + +// -------------------------------------------------------------------------------------------------------------------------------------------------- + struct element { unsigned run; unsigned word; @@ -49,6 +52,8 @@ class SparseBoolVector { return ( ( 1u ) << dist ) - 1; } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + void packData ( ) { size_t sizeWithin = m_Size % ( sizeof ( unsigned ) * 8 ); long long sizeBlocks = m_Size / ( sizeof ( unsigned ) * 8 ) + ( bool ) sizeWithin; @@ -88,6 +93,8 @@ class SparseBoolVector { } } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + public: SparseBoolVector ( ) : m_Size ( 0 ) { } @@ -97,6 +104,8 @@ public: } } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + void push_back ( bool boolean ) { size_t sizeWithin = m_Size % ( sizeof ( unsigned ) * 8 ); @@ -112,6 +121,8 @@ public: m_Size += 1; } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + bool operator [] ( size_t index ) const { size_t sizeWithin = index % ( sizeof ( unsigned ) * 8 ); size_t sizeBlocks = index / ( sizeof ( unsigned ) * 8 ); @@ -173,6 +184,8 @@ public: return BitReference ( m_Data, elementIter, sizeWithin, sizeBlocks ); } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + operator std::vector < bool > ( ) const { std::vector < bool > res; @@ -191,6 +204,8 @@ public: return res; } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + const std::list < element > & data ( ) { return m_Data; } @@ -210,6 +225,8 @@ public: return m_Size; } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + friend bool operator == ( const SparseBoolVector & first, const SparseBoolVector & second ) { return first.m_Size == second.m_Size && first.m_Data == second.m_Data; } @@ -237,6 +254,8 @@ public: return ! ( first < second ); } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + friend SparseBoolVector & operator <<= ( SparseBoolVector & A, size_t dist ) { if ( A.m_Size == 0 || dist == 0 ) return A; @@ -280,6 +299,8 @@ public: return A; } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + friend std::ostream & operator << ( std::ostream & out, const common::SparseBoolVector::element & elem ) { out << "(" << elem.run << ", "; for ( unsigned i = 0; i < sizeof ( elem.word ) * 8; ++ i ) @@ -288,6 +309,8 @@ public: return out; } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + class SparseBoolVectorOnesIterator { std::list < element >::const_iterator underlying; std::list < element >::const_iterator underlyingEnd; @@ -379,6 +402,8 @@ public: return SparseBoolVectorOnesIterator ( m_Data.end ( ), m_Data.end ( ), m_Size ); } +// -------------------------------------------------------------------------------------------------------------------------------------------------- + }; } /* namespace common */