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

fix construction of suffix trie

parent dfa24fd3
No related branches found
No related tags found
No related merge requests found
...@@ -39,11 +39,11 @@ public: ...@@ -39,11 +39,11 @@ public:
   
template < class SymbolType > template < class SymbolType >
indexes::SuffixTrie < SymbolType, unsigned > SuffixTrieNaive::construct ( const string::LinearString < SymbolType > & w ) { indexes::SuffixTrie < SymbolType, unsigned > SuffixTrieNaive::construct ( const string::LinearString < SymbolType > & w ) {
std::trie < SymbolType, std::variant < void, unsigned > > trie ( std::variant < void, unsigned >::from < void > ( ) ); std::trie < SymbolType, std::variant < void, unsigned > > trie ( std::variant < void, unsigned > ( ( unsigned ) w.getContent ( ).size ( ) ) );
std::set < unsigned > nodeAlphabet; std::set < unsigned > nodeAlphabet = { ( unsigned ) w.getContent ( ).size ( ) };
   
for ( unsigned i = 0; i < w.getContent ( ).size ( ); i++ ) { for ( unsigned i = w.getContent ( ).size ( ); i > 0; i-- ) {
unsigned k = i; unsigned k = i - 1;
std::trie < SymbolType, std::variant < void, unsigned > > * n = & trie; std::trie < SymbolType, std::variant < void, unsigned > > * n = & trie;
   
// inlined slow_find_one from MI-EVY lectures // inlined slow_find_one from MI-EVY lectures
...@@ -51,11 +51,11 @@ indexes::SuffixTrie < SymbolType, unsigned > SuffixTrieNaive::construct ( const ...@@ -51,11 +51,11 @@ indexes::SuffixTrie < SymbolType, unsigned > SuffixTrieNaive::construct ( const
n = & n->getChildren ( ).find ( w.getContent ( )[k++] )->second; n = & n->getChildren ( ).find ( w.getContent ( )[k++] )->second;
   
for ( ; k < w.getContent ( ).size ( ); k++ ) { for ( ; k < w.getContent ( ).size ( ); k++ ) {
std::variant < void, unsigned > node = k + 1 < w.getContent ( ).size ( ) ? std::variant < void, unsigned >::from < void > ( ) : std::variant < void, unsigned > ( i ); std::variant < void, unsigned > node = k + 1 < w.getContent ( ).size ( ) ? std::variant < void, unsigned >::from < void > ( ) : std::variant < void, unsigned > ( i - 1 );
n = & n->getChildren ( ).insert ( std::make_pair ( w.getContent ( )[k], std::trie < SymbolType, std::variant < void, unsigned > > ( node ) ) ).first->second; n = & n->getChildren ( ).insert ( std::make_pair ( w.getContent ( )[k], std::trie < SymbolType, std::variant < void, unsigned > > ( node ) ) ).first->second;
} }
   
nodeAlphabet.insert ( i ); nodeAlphabet.insert ( i - 1 );
} }
   
return indexes::SuffixTrie < SymbolType, unsigned > ( w.getAlphabet ( ), nodeAlphabet, trie ); return indexes::SuffixTrie < SymbolType, unsigned > ( w.getAlphabet ( ), nodeAlphabet, trie );
......
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