Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NyldonFactoring.h
Go to the documentation of this file.
1
6/*
7 *
8 * Based on code from arXiv:1804.09735
9 */
10
11#pragma once
12
13#include <string/LinearString.h>
14
15#include <alib/deque>
16
17namespace stringology {
18
19namespace properties {
20
22public:
29 template < class SymbolType >
31
32};
33
34template < class SymbolType >
36 unsigned n = string.getContent ( ).size ( );
37 ext::deque < ext::vector < SymbolType > > NyIF { ext::vector < SymbolType > { string.getContent ( ) [ n - 1 ] } };
38 for ( unsigned i = 2; i <= n; ++ i ) {
39 NyIF.push_front ( ext::vector < SymbolType > { string.getContent ( ) [ n - i ] } );
40 while ( NyIF.size ( ) >= 2 && NyIF [ 0 ] > NyIF [ 1 ] ) {
41 ext::vector < SymbolType > tmp = std::move ( NyIF [ 0 ] );
42 tmp.insert ( tmp.end ( ), NyIF [ 1 ].begin ( ), NyIF [ 1 ].end ( ) );
43
44 NyIF.pop_front ( );
45 NyIF.pop_front ( );
46 NyIF.push_front ( std::move ( tmp ) );
47 }
48 }
49
50 ext::vector < unsigned > factorization;
51 unsigned i = 0;
52 for ( const ext::vector < SymbolType > & factor : NyIF ) {
53 factorization.push_back ( i );
54 i += factor.size ( );
55 }
56 return factorization;
57}
58
59} /* namespace properties */
60
61} /* namespace stringology */
62
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
reverse_iterator insert(const_reverse_iterator pos, const T &value)
Inserts the value on position given by iterator pos.
Definition: vector.hpp:229
auto end() &
Inherited behavior of end for non-const instance.
Definition: vector.hpp:155
Linear string.
Definition: LinearString.h:57
Definition: NyldonFactoring.h:21
static ext::vector< unsigned > factorize(const string::LinearString< SymbolType > &string)
Definition: NyldonFactoring.h:35
int i
Definition: AllEpsilonClosure.h:118
Definition: ArithmeticCompression.h:18