Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BorderArray.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:
22 template < class SymbolType >
24};
25
26template < class SymbolType >
28 const auto& w = string.getContent();
29 ext::vector<size_t> res(w.size() + 1);
30
31 res[0] = -1;
32 if ( w.size ( ) > 0 )
33 res[1] = 0;
34
35 for(size_t i = 1; i < w.size(); i++) {
36 size_t b = res[i];
37 while (b > 0 && w[i] != w[b])
38 b = res[b];
39
40 if(w[i] == w[b])
41 res[i + 1] = b + 1;
42 else
43 res[i + 1] = 0;
44 }
45
46 return res;
47}
48
49} /* namespace properties */
50
51} /* namespace string */
52
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Linear string.
Definition: LinearString.h:57
Definition: BorderArray.h:15
static ext::vector< size_t > construct(const string::LinearString< SymbolType > &string)
Definition: BorderArray.h:27
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
Definition: RandomStringFactory.cpp:12