Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
MaximalSuffix.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/vector>
9#include <string/LinearString.h>
10
11namespace string {
12
13namespace properties {
14
16public:
23 template < class SymbolType >
25
33 template < class SymbolType >
35};
36
37template < class SymbolType >
39 const auto& x = string.getContent();
40 size_t i = 0, j = 1, k = 1, p = 1;
41
42 while (j + k <= x.size()) {
43 auto A = x[i + k - 1];
44 auto a = x[j + k - 1];
45 if ( a < A ) { j = j + k ; k = 1 ; p = j - i ; }
46 else if ( a == A ) {
47 if ( k == p ) { j = j + p ; k = 1 ; } else { k = k + 1 ;}
48 } else { i = j ; j = i + 1 ; k = 1 ; p = 1 ;}
49 }
50 return ext::make_pair( i , p );
51}
52
53template < class SymbolType >
55 const auto& x = string.getContent();
56 size_t i = 0, j = 1, k = 1, p = 1;
57
58 while (j + k <= x.size()) {
59 auto A = x[i + k - 1];
60 auto a = x[j + k - 1];
61 if ( a > A ) { j = j + k ; k = 1 ; p = j - i ; }
62 else if ( a == A ) {
63 if ( k == p ) { j = j + p ; k = 1 ; } else { k = k + 1 ;}
64 } else { i = j ; j = i + 1 ; k = 1 ; p = 1 ;}
65 }
66 return ext::make_pair( i , p );
67}
68
69} /* namespace properties */
70
71} /* namespace string */
72
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Linear string.
Definition: LinearString.h:57
Definition: MaximalSuffix.h:15
static ext::pair< size_t, size_t > constructReversed(const string::LinearString< SymbolType > &string)
Definition: MaximalSuffix.h:54
static ext::pair< size_t, size_t > construct(const string::LinearString< SymbolType > &string)
Definition: MaximalSuffix.h:38
int i
Definition: AllEpsilonClosure.h:118
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: RandomStringFactory.cpp:12