Skip to content
Snippets Groups Projects
Commit a0b71e57 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

implementation of Lyndon factorization

parent 6c9120f8
No related branches found
No related tags found
No related merge requests found
/*
* LyndonFactoring.cpp
*
* Created on: 30. 8. 2018
* Author: Jan Travnicek
*/
#include "LyndonFactoring.h"
#include <registration/AlgoRegistration.hpp>
namespace stringology {
namespace properties {
auto lyndonFactoringString = registration::AbstractRegister < LyndonFactoring, ext::vector < unsigned >, const string::LinearString < > & > ( LyndonFactoring::factorize );
} /* namespace properties */
} /* namespace stringology */
/*
* LyndonFactoring.h
*
* Created on: 30. 8. 2018
* Author: Jan Travnicek
*
* Based on code from https://cp-algorithms.com/string/lyndon_factorization.html
*/
#ifndef LYNDON_FACTORING_H_
#define LYNDON_FACTORING_H_
#include <string/LinearString.h>
namespace stringology {
namespace properties {
class LyndonFactoring {
public:
/**
* Computes length of backbone for a suffix/factor/oracle automaton
* @param automaton the suffix/factor/oracle automaton
* @return backbone length
*/
template < class SymbolType >
static ext::vector < unsigned > factorize ( const string::LinearString < SymbolType > & string );
};
template < class SymbolType >
ext::vector < unsigned > LyndonFactoring::factorize ( const string::LinearString < SymbolType > & string ) {
int n = string.getContent ( ).size ( );
int i = 0;
ext::vector < unsigned > factorization;
while ( i < n ) {
int j = i + 1, k = i;
while ( j < n && string.getContent ( ) [ k ] <= string.getContent ( ) [ j ] ) {
if ( string.getContent ( ) [ k ] < string.getContent ( ) [ j ] )
k = i;
else
k ++;
j ++;
}
while ( i <= k ) {
factorization.push_back ( i );
i += j - k;
}
}
return factorization;
}
} /* namespace properties */
} /* namespace stringology */
#endif /* LYNDON_FACTORING_H_ */
......@@ -62,7 +62,9 @@ public:
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::set < unsigned > > ( );
 
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::vector < object::Object > > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::vector < unsigned > > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::vector < ext::pair < object::Object, object::Object > > > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::pair < ext::vector < object::Object >, double > > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::pair < ext::vector < object::Object >, int > > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < ext::pair < ext::vector < object::Object >, long > > ( );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment