Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SuffixTrieNaive.h
Go to the documentation of this file.
1
6#pragma once
7
9#include <string/LinearString.h>
10
11namespace stringology {
12
13namespace indexing {
14
22public:
28 template < class SymbolType >
30
31};
32
33template < class SymbolType >
35 ext::trie < SymbolType, std::optional < unsigned > > trie ( std::optional < unsigned > ( w.getContent ( ).size ( ) ) );
36
37 for ( unsigned i = w.getContent ( ).size ( ); i > 0; i-- ) {
38 unsigned k = i - 1;
40
41 // inlined slow_find_one from MI-EVY lectures
42 while ( n->getChildren ( ).count ( w.getContent ( )[k] ) )
43 n = & n->getChildren ( ).find ( w.getContent ( )[k++] )->second;
44
45 for ( ; k < w.getContent ( ).size ( ); k++ ) {
46 std::optional < unsigned > node = k + 1 < w.getContent ( ).size ( ) ? std::optional < unsigned > ( ) : std::optional < unsigned > ( i - 1 );
47 n = & n->getChildren ( ).insert ( std::make_pair ( w.getContent ( )[k], ext::trie < SymbolType, std::optional < unsigned > > ( node ) ) ).first->second;
48 }
49 }
50
51 return indexes::stringology::SuffixTrie < SymbolType > ( w.getAlphabet ( ), std::move ( trie ) );
52}
53
54} /* namespace indexing */
55
56} /* namespace stringology */
57
Class introducing a trie with interface trying to be close to the interface of standard library conta...
Definition: trie.hpp:47
ext::map< Key, trie > & getChildren()
Getter of children of the root node.
Definition: trie.hpp:115
Suffix trie string index. Tree like representation of all suffixes. Nodes of the trie are optionally ...
Definition: SuffixTrie.h:55
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: SuffixTrieNaive.h:21
static indexes::stringology::SuffixTrie< SymbolType > construct(const string::LinearString< SymbolType > &w)
Definition: SuffixTrieNaive.h:34
int i
Definition: AllEpsilonClosure.h:118
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: Node.cpp:11
Definition: ArithmeticCompression.h:18