Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
LyndonFactoring.h
Go to the documentation of this file.
1
6/*
7 *
8 * Based on code from https://cp-algorithms.com/string/lyndon_factorization.html
9 */
10
11#pragma once
12
13#include <string/LinearString.h>
14
15namespace stringology {
16
17namespace properties {
18
20public:
27 template < class SymbolType >
29
30};
31
32template < class SymbolType >
34 int n = string.getContent ( ).size ( );
35 int i = 0;
36 ext::vector < unsigned > factorization;
37
38 while ( i < n ) {
39 int j = i + 1;
40 int k = i;
41 while ( j < n && string.getContent ( ) [ k ] <= string.getContent ( ) [ j ] ) {
42 if ( string.getContent ( ) [ k ] < string.getContent ( ) [ j ] )
43 k = i;
44 else
45 k ++;
46 j ++;
47 }
48 while ( i <= k ) {
49 factorization.push_back ( i );
50 i += j - k;
51 }
52 }
53
54 return factorization;
55}
56
57} /* namespace properties */
58
59} /* namespace stringology */
60
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: LyndonFactoring.h:19
static ext::vector< unsigned > factorize(const string::LinearString< SymbolType > &string)
Definition: LyndonFactoring.h:33
int i
Definition: AllEpsilonClosure.h:118
Definition: ArithmeticCompression.h:18