Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BackwardOracleMatching.h
Go to the documentation of this file.
1
6/*
7 * Author: Radovan Cerveny
8 */
9
10#pragma once
11
12#include <alib/set>
13
14#include <string/LinearString.h>
15#include <automaton/FSM/DFA.h>
16
18
19namespace stringology {
20
21namespace query {
22
27public:
32 template < class SymbolType, class StateType >
34
35};
36
37template < class SymbolType, class StateType >
40
41 size_t patternSize = stringology::properties::BackboneLength::length ( factorOracle );
42 size_t subjectSize = subject.getContent ( ).size ( );
43
44 bool fail;
45 size_t posInSubject = 0;
46
47 while ( posInSubject + patternSize <= subjectSize ) {
48
49 StateType currentState = factorOracle.getInitialState ( );
50
51 size_t posInPattern = patternSize;
52
53 fail = false;
54 while ( posInPattern > 0 && ! fail ) {
55 auto transition = factorOracle.getTransitions ( ).find ( { currentState, subject.getContent ( ).at ( posInSubject + posInPattern - 1 ) } );
56
57 if ( transition == factorOracle.getTransitions ( ).end ( ) )
58 fail = true;
59 else
60 currentState = transition->second;
61
62 posInPattern--;
63 }
64
65 if ( ! fail )
66 // Yay, there is match!!!
67 occ.insert ( posInSubject );
68
69 posInSubject += posInPattern + 1;
70 }
71
72 return occ;
73}
74
75} /* namespace query */
76
77} /* namespace stringology */
78
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
const ext::map< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: DFA.h:473
const StateType & getInitialState() const &
Definition: DFA.h:105
Definition: set.hpp:44
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
static unsigned length(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: BackboneLength.h:40
Definition: BackwardOracleMatching.h:26
static ext::set< unsigned > match(const string::LinearString< SymbolType > &subject, const automaton::DFA< SymbolType, StateType > &factorOracle)
Definition: BackwardOracleMatching.h:38
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
Definition: ArithmeticCompression.h:18