Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
HammingDynamicProgramming.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <string/LinearString.h>
9
10namespace stringology {
11
12namespace simulations {
13
15public:
16 template <class SymbolType>
18
19 template <class SymbolType>
20 static ext::set<unsigned int> search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors);
21
22};
23
24template <class SymbolType>
28 pattern.getContent().size() + 1,
29 ext::vector<unsigned int>(text.getContent().size() + 1, 0)
30 );
31
32 for(unsigned int j=1; j<=pattern.getContent().size(); j++) {
33 table[j][0] = errors + 1;
34 }
35
36 for(unsigned int i = 1; i<=text.getContent().size(); i++) {
37 for(unsigned int j = 1; j<=pattern.getContent().size(); j++) {
38 if (pattern.getContent()[j-1] == text.getContent()[i-1]) {
39 table[j][i] = table[j-1][i-1];
40 } else {
41 table[j][i] = table[j-1][i-1] + 1;
42 }
43 }
44 }
45
46 return table;
47}
48
49template <class SymbolType>
51 auto table = HammingDynamicProgramming::compute_table(text, pattern, errors);
52
54
55 for(unsigned int i=1; i<=text.getContent().size(); i++) {
56 if (table[pattern.getContent().size()][i] <= errors) {
57 result.insert(i);
58 }
59 }
60
61 return result;
62}
63
64
65
66} // namespace simulations
67
68} // namespace stringology
69
Definition: set.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: HammingDynamicProgramming.h:14
static ext::set< unsigned int > search(const string::LinearString< SymbolType > &text, const string::LinearString< SymbolType > &pattern, unsigned int errors)
Definition: HammingDynamicProgramming.h:50
static ext::vector< ext::vector< unsigned int > > compute_table(const string::LinearString< SymbolType > &text, const string::LinearString< SymbolType > &pattern, unsigned int errors)
Definition: HammingDynamicProgramming.h:25
int i
Definition: AllEpsilonClosure.h:118
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
Definition: ArithmeticCompression.h:18