Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ExactFactorOracleAutomaton.h
Go to the documentation of this file.
1
6/*
7 * Author: Radovan Cerveny
8 */
9
10#pragma once
11
12#include <limits>
13
15#include <string/LinearString.h>
16
17namespace stringology {
18
19namespace indexing {
20
22private:
23 static constexpr unsigned infinity = std::numeric_limits < unsigned >::max ( );
24
25 template < class SymbolType >
26 static void oracleAddLetter ( automaton::DFA < SymbolType, unsigned > & oracle, const SymbolType & symbol, ext::vector < unsigned > & supplyFunction );
27
28public:
33 template < class SymbolType >
35
36};
37
38template < class SymbolType >
40 automaton::DFA < SymbolType, unsigned > oracleAutomaton ( 0u );
41
42 oracleAutomaton.addFinalState ( oracleAutomaton.getInitialState ( ) );
43
44 ext::vector < unsigned > supplyFunction { infinity }; //vector is fine, the state number is exactly the index to the vector
45
46 oracleAutomaton.setInputAlphabet ( pattern.getAlphabet ( ) );
47
48 for ( const SymbolType & symbol : pattern.getContent ( ) )
49 oracleAddLetter ( oracleAutomaton, symbol, supplyFunction );
50
51 return indexes::stringology::FactorOracleAutomaton < SymbolType > ( std::move ( oracleAutomaton ) );
52}
53
54template < class SymbolType >
55void ExactFactorOracleAutomaton::oracleAddLetter ( automaton::DFA < SymbolType, unsigned > & oracle, const SymbolType & symbol, ext::vector < unsigned > & supplyFunction ) {
56 unsigned lastState = oracle.getStates ( ).size ( ) - 1;
57 unsigned newState = lastState + 1;
58
59 oracle.addState ( newState );
60 oracle.addFinalState ( newState );
61
62 oracle.addTransition ( lastState, symbol, newState );
63 unsigned kState = supplyFunction.at ( lastState );
64
65 while ( kState != infinity && oracle.getTransitions ( ).find ( { kState, symbol } ) == oracle.getTransitions ( ).end ( ) ) {
66 oracle.addTransition ( kState, symbol, newState );
67 kState = supplyFunction.at ( kState );
68 }
69
70 unsigned supplyState = 0;
71
72 if ( kState != infinity )
73 supplyState = oracle.getTransitions ( ).find( { kState, symbol } )->second;
74
75 supplyFunction.push_back ( supplyState );
76}
77
78} /* namespace indexing */
79
80} /* namespace stringology */
81
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
const ext::map< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: DFA.h:473
bool addFinalState(StateType state)
Definition: DFA.h:203
const StateType & getInitialState() const &
Definition: DFA.h:105
const ext::set< StateType > & getStates() const &
Definition: DFA.h:134
bool addTransition(StateType from, SymbolType input, StateType to)
Add a transition to the automaton.
Definition: DFA.h:432
bool addState(StateType state)
Definition: DFA.h:154
void setInputAlphabet(ext::set< SymbolType > symbols)
Definition: DFA.h:270
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Factor oracle automaton string index. Stores a deterministic finite automaton. The automaton is of ex...
Definition: FactorOracleAutomaton.h:49
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: ExactFactorOracleAutomaton.h:21
static indexes::stringology::FactorOracleAutomaton< SymbolType > construct(const string::LinearString< SymbolType > &pattern)
Definition: ExactFactorOracleAutomaton.h:39
p second
Definition: ToRegExpAlgebraic.h:126
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
Definition: ArithmeticCompression.h:18