Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BackwardDAWGMatching.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
15#include <string/LinearString.h>
16
17namespace stringology {
18
19namespace query {
20
25public:
30 template < class SymbolType >
32
33};
34
35template < class SymbolType >
38
39 size_t patternSize = suffixAutomaton.getBackboneLength ( );
40 size_t subjectSize = subject.getContent ( ).size ( );
41
42 bool fail;
43 size_t posInSubject = 0;
44
45 while ( posInSubject + patternSize <= subjectSize ) {
46 unsigned currentState = suffixAutomaton.getAutomaton ( ).getInitialState ( );
47
48 size_t posInPattern = patternSize;
49 size_t lastPrefixPos = posInPattern;
50
51 fail = false;
52 while ( posInPattern > 0 && ! fail ) {
53 auto transition = suffixAutomaton.getAutomaton ( ).getTransitions ( ).find ( { currentState, subject.getContent ( ).at ( posInSubject + posInPattern - 1 ) } );
54
55 if ( transition == suffixAutomaton.getAutomaton ( ).getTransitions ( ).end ( ) )
56 fail = true;
57 else
58 currentState = transition->second;
59
60 posInPattern--;
61
62 // found a prefix of nonreversed pattern that does not correspond to the entire pattern
63 if ( ( posInPattern != 0 ) && ( suffixAutomaton.getAutomaton ( ).getFinalStates ( ).find ( currentState ) != suffixAutomaton.getAutomaton ( ).getFinalStates ( ).end ( ) ) )
64 lastPrefixPos = posInPattern;
65 }
66
67 if ( ! fail )
68 // Yay, there is match!!!
69 occ.insert ( posInSubject );
70
71 posInSubject += lastPrefixPos;
72 }
73
74 return occ;
75}
76
77} /* namespace query */
78
79} /* namespace stringology */
80
Definition: set.hpp:44
Suffix automaton string index. Automaton representation of all suffixes. The automaton is general det...
Definition: SuffixAutomaton.h:50
unsigned getBackboneLength() const
Definition: SuffixAutomaton.h:116
const automaton::DFA< SymbolType, unsigned > & getAutomaton() const &
Definition: SuffixAutomaton.h:175
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: BackwardDAWGMatching.h:24
static ext::set< unsigned > match(const string::LinearString< SymbolType > &subject, const indexes::stringology::SuffixAutomaton< SymbolType > &suffixAutomaton)
Definition: BackwardDAWGMatching.h:36
Definition: ArithmeticCompression.h:18