Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Dogaru.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/measure>
9
10#include <alib/set>
11#include <alib/vector>
12
13#include <string/LinearString.h>
14
15
16namespace stringology {
17
18 namespace exact {
19
20
24 class Dogaru{
25 public:
30 template < class SymbolType >
32
33 };
34
35 template < class SymbolType >
38 const auto & text = subject.getContent();
39 const auto & pat = pattern.getContent();
40 long int n = text.size(), m = pat.size();
41
42 unsigned i = 0 , j = 0 , k = 0 ;
43
45 do {
46 j = 0 ;
47 while ( j < m && pat[j] == text[i] ) { ++ i ; ++ j ; }
48 if ( j == m ) { occ.insert( i - j ) ; continue ; }
49 one: ++ i ;
50 while ( i <= n - m + j && pat[j] != text[i] ) ++ i ;
51 if ( i > n - m + j ) { measurements::end() ; return occ ; }
52 k = 0 ;
53 while ( k <= m - 1 && pat[k] == text[ i - j + k ] ) ++ k ;
54 if ( k == m ) { occ.insert( i - j ) ; i = i - j + m ; }
55 else { goto one ;}
56
57 } while ( i < n - m + j ) ;
58
60 return occ;
61 }
62
63
64 } /* namespace exact */
65
66} /* namespace stringology */
67
Definition: set.hpp:44
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: Dogaru.h:24
static ext::set< unsigned > match(const string::LinearString< SymbolType > &subject, const string::LinearString< SymbolType > &pattern)
Definition: Dogaru.h:36
int i
Definition: AllEpsilonClosure.h:118
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14
void end()
Definition: measurements.cpp:19
Definition: ArithmeticCompression.h:18