Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
TailedSubstring.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
27 public:
32 template < class SymbolType >
34
35 };
36
37 template < class SymbolType >
40 const auto & text = subject.getContent();
41 const auto & pat = pattern.getContent();
42 long int n = text.size(), m = pat.size();
43
44 long int s = 0;
45 long int delta = 1;
46 long int i , k;
47 i = k = m - 1;
48
50 // Phase 1
51 while ( s <= n - m && i - delta >= 0 ) {
52 if ( pat[i] != text[s + i] ) s = s + 1;
53 else {
54 long int j = 0;
55 while ( j < m && pat[j] == text[s + j] ) ++j;
56 if ( j == m ) occ.insert(s);
57 long int h = i - 1;
58 while ( h >= 0 && pat[h] != pat[i] ) --h;
59 if ( delta < i - h ){
60 delta = i - h;
61 k = i;
62 }
63 s = s + i - h;
64 i = i - 1;
65 }
66 }
67
68 // Phase 2
69 while ( s <= n - m ){
70 if ( pat[k] != text[s+k] ) ++ s;
71 else {
72 long int j = 0 ;
73 while ( j < m && pat[j] == text[s+j]) ++j;
74 if ( j == m ) occ.insert(s);
75 s += delta;
76 }
77 }
79 return occ;
80 }
81
82
83 } /* namespace exact */
84
85} /* namespace stringology */
86
Definition: set.hpp:44
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: TailedSubstring.h:26
static ext::set< unsigned > match(const string::LinearString< SymbolType > &subject, const string::LinearString< SymbolType > &pattern)
Definition: TailedSubstring.h:38
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