Skip to content
Snippets Groups Projects
Commit 9a388740 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

tidy: formatting

parent 4ef31e39
No related branches found
No related tags found
1 merge request!215Merge jt
......@@ -8,10 +8,7 @@
#include <string/properties/PeriodicPrefix.h>
#include <string/LinearString.h>
 
namespace stringology {
namespace exact {
namespace stringology::exact {
 
namespace {
 
......@@ -180,13 +177,12 @@ ext::set < unsigned > SequentialSampling::match ( const string::LinearString < S
res = SimpleTextSearching( subject , pattern);
} else if ( static_cast < size_t > ( periodic_prefix ) < pattern.getContent().size() ) {
res = SeqSampling( subject, pattern , periodic_prefix - period, periodic_prefix );
} else res = Mix( subject, pattern, period );
} else {
res = Mix( subject, pattern, period );
}
 
measurements::end();
return res;
}
 
} /* namespace exact */
} /* namespace stringology */
} /* namespace stringology::exact */
......@@ -7,11 +7,7 @@
 
#include <string/LinearString.h>
 
namespace stringology {
namespace exact {
namespace stringology::exact {
 
/**
* Implementation of the TailedSubstring algorithm from article “ IT’S ECONOMY, STUPID! ” : SEARCHING FOR A SUBSTRING
......@@ -26,12 +22,11 @@ public:
*/
template < class SymbolType >
static ext::set < unsigned > match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern );
};
 
template < class SymbolType >
ext::set < unsigned > TailedSubstring::match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern ) {
ext::set<unsigned> occ;
ext::set < unsigned > occ;
const auto & text = subject.getContent();
const auto & pat = pattern.getContent();
long int n = text.size();
......@@ -45,14 +40,18 @@ ext::set < unsigned > TailedSubstring::match ( const string::LinearString < Symb
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
// Phase 1
while ( s <= n - m && i - delta >= 0 ) {
if ( pat[i] != text[s + i] ) s = s + 1;
else {
if ( pat[i] != text[s + i] ) {
s = s + 1;
} else {
long int j = 0;
while ( j < m && pat[j] == text[s + j] ) ++j;
if ( j == m ) occ.insert(s);
while ( j < m && pat[j] == text[s + j] )
++j;
if ( j == m )
occ.insert(s);
long int h = i - 1;
while ( h >= 0 && pat[h] != pat[i] ) --h;
if ( delta < i - h ){
while ( h >= 0 && pat[h] != pat[i] )
--h;
if ( delta < i - h ) {
delta = i - h;
k = i;
}
......@@ -63,20 +62,20 @@ ext::set < unsigned > TailedSubstring::match ( const string::LinearString < Symb
 
// Phase 2
while ( s <= n - m ){
if ( pat[k] != text[s+k] ) ++ s;
else {
if ( pat[k] != text[s+k] ) {
++ s;
} else {
long int j = 0;
while ( j < m && pat[j] == text[s+j]) ++j;
if ( j == m ) occ.insert(s);
while ( j < m && pat[j] == text[s+j])
++j;
if ( j == m )
occ.insert(s);
s += delta;
}
}
measurements::end();
return occ;
}
 
} /* namespace exact */
} /* namespace stringology */
} /* namespace stringology::exact */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment