Skip to content
Snippets Groups Projects
Commit 5bc1596c authored by Jan Jirák's avatar Jan Jirák Committed by Jan Trávníček
Browse files

added measurements

parent 3b26cfb2
No related branches found
No related tags found
1 merge request!153Jirakjan bp rebase
Pipeline #83463 canceled
......@@ -46,8 +46,11 @@ namespace stringology {
size_t n = text.size(), m = pat.size();
 
size_t repSize, p , q ;
measurements::start ( "Preprocess", measurements::Type::PREPROCESS );
std::tie( repSize , p , q ) = string::properties::Repetition::construct(pattern) ;
measurements::end ( );
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
// for repSize == 0 or 1 use naive solution
if ( repSize == 0 || repSize == 1 ) {
for ( size_t i = 0 ; i <= n - m ; ++ i ) {
......@@ -55,6 +58,7 @@ namespace stringology {
while ( j < m && text[i + j ] == pat[j] ) ++ j ;
if ( j == m ) occ.insert(i) ;
}
measurements::end();
return occ ;
}
 
......@@ -72,7 +76,7 @@ namespace stringology {
for ( size_t j = i - repSize / 2 ; j <= n - m ; ++ j ) {
if ( std::equal( pat.begin() , pat.end() , text.begin() + j ) ) occ.insert(j) ;
}
measurements::end();
return occ ;
}
 
......
......@@ -44,13 +44,14 @@ namespace stringology {
 
unsigned i = 0 , j = 0 , k = 0 ;
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
do {
j = 0 ;
while ( j < m && pat[j] == text[i] ) { ++ i ; ++ j ; }
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 ) return occ ;
if ( i > n - m + j ) { measurements::end() ; return occ ; }
k = 0 ;
while ( k <= m - 1 && pat[k] == text[ i - j + k ] ) ++ k ;
if ( k == m ) { occ.insert( i - j ) ; i = i - j + m ; }
......@@ -58,6 +59,7 @@ namespace stringology {
 
} while ( i < n - m + j ) ;
 
measurements::end() ;
return occ;
}
 
......
......@@ -67,6 +67,7 @@ namespace stringology {
size_t p2 = 0 , q2 = 0 ;
 
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
newp1:
while( x[s + p1 + q1] == x[s + q1] ) ++ q1 ;
if ( p1 + q1 >= k * p1 ) {
......@@ -117,7 +118,7 @@ namespace stringology {
q = 0;
}
}
measurements::end() ;
return occ ;
}
 
......
......@@ -39,6 +39,7 @@ namespace stringology {
ext::set < unsigned > NotSoNaive::match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern ) {
ext::set<unsigned> occ;
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
// if pattern is one char, skip the rest and use naive approach
if (pattern.getContent().size() == 1) {
for (unsigned i = 0; i < subject.getContent().size(); ++i) {
......@@ -78,6 +79,7 @@ namespace stringology {
if ( match ) occ.insert(i);
}
}
measurements::end() ;
return occ;
 
}
......
......@@ -44,11 +44,14 @@ namespace stringology {
const auto & pat = pattern.getContent();
size_t n = text.size(), m = pat.size();
 
measurements::start ( "Preprocess", measurements::Type::PREPROCESS );
// Preprocessing
size_t gamma = 1 , delta = 1 ;
while ( delta < m && pat[m-1] != pat[m-1-delta]) ++ delta;
while ( gamma < m && pat[m-1] == pat[m-1-gamma]) ++ gamma;
measurements::end() ;
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
// Searching
size_t s = 0;
while ( s <= n - m ){
......@@ -60,7 +63,7 @@ namespace stringology {
s += delta;
}
}
measurements::end() ;
return occ;
}
 
......
......@@ -147,14 +147,20 @@ namespace stringology {
template < class SymbolType >
ext::set < unsigned > SequentialSampling::match ( const string::LinearString < SymbolType > & subject, const string::LinearString < SymbolType > & pattern ) {
ssize_t periodic_prefix , period ;
measurements::start ( "Preprocess", measurements::Type::PREPROCESS );
std::tie(periodic_prefix , period ) = string::properties::PeriodicPrefix::construct(pattern);
measurements::end() ;
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
ext::set<unsigned> res ;
if ( periodic_prefix == -1 ) {
return SimpleTextSearching( subject , pattern) ;
res = SimpleTextSearching( subject , pattern) ;
} else if ( (size_t)periodic_prefix < pattern.getContent().size() ) {
return SeqSampling( subject, pattern , periodic_prefix - period, periodic_prefix ) ;
} else return Mix( subject, pattern, period ) ;
res = SeqSampling( subject, pattern , periodic_prefix - period, periodic_prefix ) ;
} else res = Mix( subject, pattern, period ) ;
 
measurements::end() ;
return res ;
}
 
 
......
......@@ -49,6 +49,7 @@ namespace stringology {
long int i , k;
i = k = m - 1;
 
measurements::start ( "Algorithm", measurements::Type::ALGORITHM );
// Phase 1
while ( s <= n - m && i - delta >= 0 ) {
if ( pat[i] != text[s + i] ) s = s + 1;
......@@ -77,6 +78,7 @@ namespace stringology {
s += delta;
}
}
measurements::end();
return occ;
}
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment