Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FactorOracleAutomaton.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <ext/iostream>
27
28#include <alib/string>
29#include <alib/set>
30
32
34
35#include <automaton/FSM/DFA.h>
36
37namespace indexes {
38
39namespace stringology {
40
41class GeneralAlphabet;
42
48template < class SymbolType = DefaultSymbolType >
54
55public:
62
69
76
83 return m_automaton.getInputAlphabet ( );
84 }
85
92 return std::move ( m_automaton ).getInputAlphabet ( );
93 }
94
100 bool removeSymbolFromAlphabet ( const SymbolType & symbol ) {
101 return m_automaton.removeInputSymbol ( symbol );
102 }
103
108 unsigned getBackboneLength ( ) const {
109 return m_automaton.getStates ( ).size ( ) - 1;
110 }
111
119 auto operator <=> ( const FactorOracleAutomaton & other ) const {
120 return std::tie ( getAutomaton ( ) ) <=> std::tie ( other.getAutomaton ( ) );
121 }
122
130 bool operator == ( const FactorOracleAutomaton & other ) const {
131 return std::tie ( getAutomaton ( ) ) == std::tie ( other.getAutomaton ( ) );
132 }
133
142 friend ext::ostream & operator << ( ext::ostream & out, const FactorOracleAutomaton & instance ) {
143 return out << "(FactorOracleAutomaton " << instance.m_automaton << ")";
144 }
145
151 explicit operator automaton::DFA < SymbolType, unsigned > ( ) const;
152};
153
154} /* namespace stringology */
155
156} /* namespace indexes */
157
158namespace indexes {
159
160namespace stringology {
161
162template < class SymbolType >
164}
165
166template < class SymbolType >
168 return m_automaton;
169}
170
171template < class SymbolType >
173 return std::move ( m_automaton );
174}
175
176template < class SymbolType >
178 return getAutomaton ( );
179}
180
181} /* namespace stringology */
182
183} /* namespace indexes */
184
185namespace core {
186
192template < class SymbolType >
193struct normalize < indexes::stringology::FactorOracleAutomaton < SymbolType > > {
195 ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( std::move ( value ).getAutomaton ( ) ).getInputAlphabet ( ) );
196 ext::set < unsigned > states = std::move ( std::move ( value ).getAutomaton ( ) ).getStates ( );
197 unsigned initialState = std::move ( std::move ( value ).getAutomaton ( ) ).getInitialState ( );
198 ext::set < unsigned > finalStates = std::move ( std::move ( value ).getAutomaton ( ) ).getFinalStates ( );
199
200 automaton::DFA < DefaultStateType, unsigned > res ( std::move ( states ), std::move ( alphabet ), initialState, std::move ( finalStates ) );
201
202 for ( std::pair < ext::pair < unsigned, SymbolType >, unsigned > && transition : ext::make_mover ( std::move ( std::move ( value ).getAutomaton ( ) ).getTransitions ( ) ) ) {
203 unsigned from = transition.first.first;
204 DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) );
205 unsigned to = transition.second;
206
207 res.addTransition ( from, std::move ( input ), to );
208 }
209
211 }
212};
213
214} /* namespace core */
215
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Definition: ostream.h:14
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
Factor oracle automaton string index. Stores a deterministic finite automaton. The automaton is of ex...
Definition: FactorOracleAutomaton.h:49
FactorOracleAutomaton(automaton::DFA< SymbolType, unsigned > automaton)
Definition: FactorOracleAutomaton.h:163
const ext::set< SymbolType > & getAlphabet() const &
Definition: FactorOracleAutomaton.h:82
friend ext::ostream & operator<<(ext::ostream &out, const FactorOracleAutomaton &instance)
Definition: FactorOracleAutomaton.h:142
unsigned getBackboneLength() const
Definition: FactorOracleAutomaton.h:108
ext::set< SymbolType > && getAlphabet() &&
Definition: FactorOracleAutomaton.h:91
const automaton::DFA< SymbolType, unsigned > & getAutomaton() const &
Definition: FactorOracleAutomaton.h:167
bool operator==(const FactorOracleAutomaton &other) const
Definition: FactorOracleAutomaton.h:130
bool removeSymbolFromAlphabet(const SymbolType &symbol)
Definition: FactorOracleAutomaton.h:100
auto operator<=>(const FactorOracleAutomaton &other) const
Definition: FactorOracleAutomaton.h:119
Definition: Object.h:16
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
Definition: CompressedBitParallelTreeIndex.h:40
Definition: ArithmeticCompression.h:18
static indexes::stringology::FactorOracleAutomaton< > eval(indexes::stringology::FactorOracleAutomaton< SymbolType > &&value)
Definition: FactorOracleAutomaton.h:194
Definition: normalize.hpp:13