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

tidy: formatting and fixing clang-tidy issues

parent e98eac18
No related branches found
No related tags found
1 merge request!215Merge jt
...@@ -7,11 +7,7 @@ ...@@ -7,11 +7,7 @@
   
#include <string/LinearString.h> #include <string/LinearString.h>
   
namespace stringology::exact {
namespace stringology {
namespace exact {
   
/** /**
* Implementation of the Dogaru algorithm from article "On the All Occurrences of a Word in a Text" by O.C.Dogaru * Implementation of the Dogaru algorithm from article "On the All Occurrences of a Word in a Text" by O.C.Dogaru
...@@ -24,30 +20,52 @@ public: ...@@ -24,30 +20,52 @@ public:
*/ */
template < class SymbolType > template < class SymbolType >
static ext::set < unsigned > match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern ); static ext::set < unsigned > match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern );
}; };
   
template < class SymbolType > template < class SymbolType >
ext::set < unsigned > Dogaru::match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern ) { ext::set < unsigned > Dogaru::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 & text = subject.getContent();
const auto & pat = pattern.getContent(); const auto & pat = pattern.getContent();
long int n = text.size(), m = pat.size(); long int n = text.size();
long int m = pat.size();
   
unsigned i = 0 , j = 0 , k = 0; unsigned i = 0;
unsigned j = 0;
unsigned k = 0;
   
measurements::start ( "Algorithm", measurements::Type::ALGORITHM ); measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
do { do {
j = 0; j = 0;
while ( j < m && pat[j] == text[i] ) { ++ i; ++ j; } while ( j < m && pat[j] == text[i] ) {
if ( j == m ) { occ.insert( i - j ); continue; } ++ i;
one: ++ i; ++ j;
while ( i <= n - m + j && pat[j] != text[i] ) ++ i; }
if ( i > n - m + j ) { measurements::end(); return occ; }
if ( j == m ) {
occ.insert( i - j );
continue;
}
one:
++ i;
while ( i <= n - m + j && pat[j] != text[i] )
++ i;
if ( i > n - m + j ) {
measurements::end();
return occ;
}
k = 0; k = 0;
while ( k <= m - 1 && pat[k] == text[ i - j + k ] ) ++ k; while ( k <= m - 1 && pat[k] == text[ i - j + k ] )
if ( k == m ) { occ.insert( i - j ); i = i - j + m; } ++ k;
else { goto one;}
if ( k == m ) {
occ.insert( i - j );
i = i - j + m;
} else {
goto one;
}
   
} while ( i < n - m + j ); } while ( i < n - m + j );
   
...@@ -55,8 +73,4 @@ ext::set < unsigned > Dogaru::match ( const string::LinearString < SymbolType > ...@@ -55,8 +73,4 @@ ext::set < unsigned > Dogaru::match ( const string::LinearString < SymbolType >
return occ; return occ;
} }
   
} /* namespace stringology::exact */
} /* namespace exact */
} /* namespace stringology */
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