diff --git a/alib2algo/src/stringology/query/BitParallelismFactors.h b/alib2algo/src/stringology/query/BitParallelismFactors.h index a96f961501a133ed0e534c3e8aa9d81659f37804..a4e1232ea74bf6179245f9d230709b586cbe2fb3 100644 --- a/alib2algo/src/stringology/query/BitParallelismFactors.h +++ b/alib2algo/src/stringology/query/BitParallelismFactors.h @@ -14,6 +14,8 @@ #include <core/multipleDispatch.hpp> #include <global/GlobalData.h> +#include <foreach> + namespace stringology { namespace query { @@ -45,10 +47,7 @@ std::set < unsigned > BitParallelismFactors::query ( const indexes::stringology: if ( bitParallelIndex.getData ( ).begin ( ) == bitParallelIndex.getData ( ).end ( ) ) return { }; - std::set < unsigned > res; - for ( unsigned i = 0; i < bitParallelIndex.getData ( ).begin ( )->second.size ( ); ++ i ) { - res.insert ( i ); - } + return { std::sequence < unsigned > ( 0 ).begin ( ), std::sequence < unsigned > ( bitParallelIndex.getData ( ).begin ( )->second.size ( ) ).end ( ) }; } auto symbolIter = string.getContent ( ).begin ( ); diff --git a/alib2algo/src/stringology/query/CompressedBitParallelismFactors.h b/alib2algo/src/stringology/query/CompressedBitParallelismFactors.h index 4411d639f4b005324f91ad670500a5d81b35afca..c7fd3a0059c63bca3a19f5881cc9556f226d1ff0 100644 --- a/alib2algo/src/stringology/query/CompressedBitParallelismFactors.h +++ b/alib2algo/src/stringology/query/CompressedBitParallelismFactors.h @@ -14,12 +14,14 @@ #include <core/multipleDispatch.hpp> #include <global/GlobalData.h> +#include <foreach> + namespace stringology { namespace query { /** - * Query compressedBit parallel index for given string. + * Query compressed bit parallel index for given string. * */ @@ -27,16 +29,15 @@ class CompressedBitParallelismFactors : public std::SingleDispatchFirstStaticPar public: /** - * Query a suffix trie - * @param suffix trie to query - * @param string string to query by + * Query a compressed bit parallel index + * @param compressedBitParallelIndex the index to query + * @param string the string to query with * @return occurences of factors */ static std::set < unsigned > query ( const indexes::stringology::CompressedBitParallelIndex < DefaultSymbolType > & compressedBitParallelIndex, const string::String & string ); template < class SymbolType > static std::set < unsigned > query ( const indexes::stringology::CompressedBitParallelIndex < SymbolType > & compressedBitParallelIndex, const string::LinearString < SymbolType > & string ); - }; template < class SymbolType > @@ -45,14 +46,12 @@ std::set < unsigned > CompressedBitParallelismFactors::query ( const indexes::st if ( compressedBitParallelIndex.getData ( ).begin ( ) == compressedBitParallelIndex.getData ( ).end ( ) ) return { }; - std::set < unsigned > res; - for ( unsigned i = 0; i < compressedBitParallelIndex.getData ( ).begin ( )->second.size ( ); ++ i ) { - res.insert ( i ); - } + return { std::sequence < unsigned > ( 0 ).begin ( ), std::sequence < unsigned > ( compressedBitParallelIndex.getData ( ).begin ( )->second.size ( ) ).end ( ) }; } auto symbolIter = string.getContent ( ).begin ( ); typename std::map < SymbolType, common::SparseBoolVector >::const_iterator symbolVectorIter = compressedBitParallelIndex.getData ( ).find ( * symbolIter ); + if ( symbolVectorIter == compressedBitParallelIndex.getData ( ).end ( ) ) return { }; @@ -67,8 +66,9 @@ std::set < unsigned > CompressedBitParallelismFactors::query ( const indexes::st } std::set < unsigned > res; + for ( unsigned i : indexVector ) - res.insert ( i - string.getContent ( ).size ( ) + 1); + res.insert ( i - string.getContent ( ).size ( ) + 1 ); return res; } diff --git a/alib2std/src/extensions/foreach.hpp b/alib2std/src/extensions/foreach.hpp index fb382dac3aa525d5376d4d40cd4c4c3ef1b76924..a892f0c39d4d0b6e16bbea9201bf11eee48378e2 100644 --- a/alib2std/src/extensions/foreach.hpp +++ b/alib2std/src/extensions/foreach.hpp @@ -37,7 +37,7 @@ public: } template < int number > - decltype ( std::get < number > ( current ) )base ( ) const { + decltype ( std::get < number > ( current ) ) base ( ) const { return std::get < number > ( current ); } @@ -122,6 +122,72 @@ const_tuple_foreach < Types ... > make_tuple_foreach ( const Types & ... args ) return const_tuple_foreach < Types ... > ( args ... ); } +template < class IntegralType > +class virtual_pointer_to_integer { + IntegralType m_data; + +public: + virtual_pointer_to_integer ( IntegralType data ) : m_data ( data ) { + } + + IntegralType operator * ( ) const { + return m_data; + } + + virtual_pointer_to_integer & operator ++( ) { + m_data ++; + return * this; + } + + virtual_pointer_to_integer & operator --( ) { + m_data --; + return * this; + } + + virtual_pointer_to_integer operator ++( int ) { + virtual_pointer_to_integer temp = * this; + + ++( * this ); + return temp; + } + + virtual_pointer_to_integer operator --( int ) { + virtual_pointer_to_integer temp = * this; + + --( * this ); + return temp; + } + + bool operator ==( const virtual_pointer_to_integer < IntegralType > & other ) { + return this->m_data == other.m_data; + } + + bool operator !=( const virtual_pointer_to_integer < IntegralType > & other ) { + return !( * this == other ); + } +}; + +template < class IntegralType > +class sequence { + IntegralType m_first; + IntegralType m_last; + +public: + sequence ( IntegralType first, IntegralType last ) : m_first ( first ), m_last ( last ) { + } + + sequence ( IntegralType size ) : m_first ( 0 ), m_last ( size ) { + } + + virtual_pointer_to_integer < IntegralType > begin ( ) { + return virtual_pointer_to_integer < IntegralType > ( m_first ); + } + + virtual_pointer_to_integer < IntegralType > end ( ) { + return virtual_pointer_to_integer < IntegralType > ( m_last ); + } +}; + } /* namespace std */ #endif /* __FOREACH_HPP_ */