From 8647ef704d63bae95a41409a9479e21cc9850c53 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 9 Jan 2017 20:25:34 +0100 Subject: [PATCH] simplify suffix array query --- .../src/stringology/query/SuffixArrayFactors.h | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/alib2algo/src/stringology/query/SuffixArrayFactors.h b/alib2algo/src/stringology/query/SuffixArrayFactors.h index 9187fd5e26..8724b0306a 100644 --- a/alib2algo/src/stringology/query/SuffixArrayFactors.h +++ b/alib2algo/src/stringology/query/SuffixArrayFactors.h @@ -43,7 +43,7 @@ public: template < class SymbolType > std::set < unsigned > SuffixArrayFactors::query ( const indexes::SuffixArray < SymbolType > & suffixArray, const string::LinearString < SymbolType > & string ) { - auto comparator = [ & ] ( const std::vector < SymbolType > & first, unsigned firstIndex, const std::vector < SymbolType > & second, unsigned secondIndex, unsigned limit ) { + auto comparator = [ & ] ( const std::vector < SymbolType > & first, unsigned firstIndex, const std::vector < SymbolType > & second, unsigned secondIndex, unsigned limit ) -> int { static std::compare < SymbolType > comp; for ( ; firstIndex < first.size ( ) && secondIndex < second.size ( ) && limit > 0; ++ firstIndex, ++ secondIndex, --limit ) { @@ -56,16 +56,7 @@ std::set < unsigned > SuffixArrayFactors::query ( const indexes::SuffixArray < S if ( limit == 0 ) return 0; - if ( first.size ( ) == firstIndex && second.size ( ) == secondIndex ) - return 0; - - if ( first.size ( ) == firstIndex ) - return -1; - - if ( second.size ( ) == secondIndex ) - return 1; - - return 0; + return ( first.size ( ) - firstIndex ) - ( second.size ( ) - secondIndex ); }; // The value returned by comparator indicates whether the first argument is considered to go before the second. -- GitLab