From 204f73e508bba65bcfa24a96a4b324876313d8bb Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sat, 14 Apr 2018 21:07:21 +0200 Subject: [PATCH] allow templated construction of CDAWG --- ...erimentalCompactSuffixAutomatonConstruct.h | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/alib2algo_experimental/src/stringology/indexing/ExperimentalCompactSuffixAutomatonConstruct.h b/alib2algo_experimental/src/stringology/indexing/ExperimentalCompactSuffixAutomatonConstruct.h index 9a14360d81..b874d44510 100644 --- a/alib2algo_experimental/src/stringology/indexing/ExperimentalCompactSuffixAutomatonConstruct.h +++ b/alib2algo_experimental/src/stringology/indexing/ExperimentalCompactSuffixAutomatonConstruct.h @@ -39,7 +39,7 @@ class ExperimentalCompactSuffixAutomatonConstruct { //hledánĂ w[k]-edge. PouĹľito na nÄ›kolika mĂstech v algoritmu. //char c je w[k] - void wkEdge(int s, SymbolType c, int & sc, int & kc, int & pc) { + void wkEdge(int s, const SymbolType & c, int & sc, int & kc, int & pc) { for ( const std::pair < const ext::pair < int, int >, int > edge : edges.at ( s ) ) { if ( w.at ( edge.first.first ) == c) { sc = edge.second; @@ -77,7 +77,7 @@ class ExperimentalCompactSuffixAutomatonConstruct { } //pomocná funkce, která reprezentuje řádek 4 ve funkci check_end_point - bool thereIsACedgeFromS(int s, SymbolType c) { + bool thereIsACedgeFromS(int s, const SymbolType & c) { //procházĂm hrany vrcholu s a hledám, jestli se prvnĂ znak hrany rovná c for ( const std::pair < const ext::pair < int, int >, int > & edge : edges.at ( s ) ) if ( w.at ( edge.first.first ) == c ) @@ -98,7 +98,7 @@ class ExperimentalCompactSuffixAutomatonConstruct { //konec pomocnĂ˝ch funkcĂ. Dále je co nejpĹ™esnÄ›jšà pĹ™epis pseudokodu - bool check_end_point(int s,int k,int p,SymbolType c) { + bool check_end_point(int s,int k,int p, const SymbolType & c) { if(k<= p) { int sc,kc,pc;//s' k' p' wkEdge(s,w.at(k),sc,kc,pc); @@ -190,7 +190,7 @@ class ExperimentalCompactSuffixAutomatonConstruct { } ext::pair<int,int> update(int s,int k,int p) { - SymbolType c = w.at(p); + const SymbolType & c = w.at(p); int oldr = nil; int sc = nil; // v ÄŤlánku nenĂ s' inicializovanĂ©, ale je potĹ™eba to na nÄ›co inicializovat, protoĹľe nĂĹľe docházĂ k porovnávnĂ @@ -320,13 +320,26 @@ public: return res; } - static indexes::stringology::CompactSuffixAutomatonTerminatingSymbol < DefaultSymbolType > construct ( const string::LinearString < DefaultSymbolType > & subject ) { - DefaultSymbolType endSymbol = common::createUnique ( alphabet::EndSymbol::instance < DefaultSymbolType > ( ), subject.getAlphabet ( ) ); - ext::vector < DefaultSymbolType > content = subject.getContent ( ); + template < class SymbolType > + static indexes::stringology::CompactSuffixAutomatonTerminatingSymbol < SymbolType > construct ( const string::LinearString < SymbolType > & subject ) { + SymbolType endSymbol = common::createUnique ( alphabet::EndSymbol::instance < SymbolType > ( ), subject.getAlphabet ( ) ); + ext::vector < SymbolType > content = subject.getContent ( ); content.push_back ( endSymbol ); - ext::set < DefaultSymbolType > alphabet = subject.getAlphabet ( ); - alphabet.insert ( endSymbol ); - return construct ( string::LinearStringTerminatingSymbol ( alphabet, endSymbol, content ) ); + + CompactSuffixAutomatonConstructInt < SymbolType > algo ( content ); + algo.startConstruction(); + algo.changeIntMaxToE(); + //algo.print ( subject.getContent().size ( ) ); + + indexes::stringology::CompactSuffixAutomatonTerminatingSymbol < SymbolType > res; + res.setString ( content ); + res.setNumberOfVertices(algo.getEdges().size()-1); + + for(auto it = algo.getEdges().begin();it!=algo.getEdges().end();++it) + if(it->first != -1) + res.insertVertex(it->first,it->second); + + return res; } }; -- GitLab