Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GeneralizedLevenshteinBitParalelism.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <exception>
9#include <string/LinearString.h>
10
11#include "BitParalelism.h"
12
13namespace stringology {
14
15namespace simulations {
16
18public:
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
23template <class SymbolType>
25 // preparation stage
26 ext::set<SymbolType> common_alphabet = text.getAlphabet();
27 common_alphabet.insert(pattern.getAlphabet().begin(), pattern.getAlphabet().end());
28
30
31 auto V_vector = ext::vector<bool>(pattern.getContent().size(), false);
32 V_vector[pattern.getContent().size() - 1] = true;
33
34 // computation part
36
38 for(unsigned int i=0; i<=errors; i++) {
39 B_vectors.push_back(ext::vector<bool>(pattern.getContent().size(), false));
40 }
41
42 for(unsigned int l = 0; l <= errors; l++) {
43 for(unsigned int j = l; j <= pattern.getContent().size(); j++) {
44 B_vectors[l][j] = true;
45 }
46 }
47
49 for(unsigned int i=0; i<=errors; i++) {
50 S_vectors.push_back(ext::vector<bool>(pattern.getContent().size(), true));
51 }
52
53 // 0-th column R-vectors
54 ext::vector<bool> b0 = ext::vector < bool > ( pattern.getContent().size(), true );
55 for(unsigned int j=1; j<=errors; j++) {
56 b0 <<= 1;
57 if( ! b0 [ pattern.getContent ( ).size ( ) - 1 ] ) {
58 result.insert(0);
59 break;
60 }
61 }
62
63 for(unsigned int i=0; i<text.getContent().size(); i++) {
64 ext::vector< ext::vector<bool> > previous_B_vectors = B_vectors;
65 ext::vector< ext::vector<bool> > previous_S_vectors = S_vectors;
66
67 auto D_vector = D_vectors[text.getContent()[i]];
68
69 B_vectors[0] = (previous_B_vectors[0] << 1) | D_vector;
70 S_vectors[0] = (previous_B_vectors[0] << 1) | (D_vector >> 1);
71
72 for(unsigned int j=1; j<=errors; j++) {
73 B_vectors[j] = ((previous_B_vectors[j] << 1) | D_vector) &
74 ((previous_B_vectors[j-1] & B_vectors[j-1] & (previous_S_vectors[j-1] | D_vector)) << 1) &
75 (previous_B_vectors[j-1] | V_vector);
76
77 S_vectors[j] = (previous_B_vectors[j] << 1) | (D_vector >> 1);
78 }
79
80 for (const auto & data : B_vectors) {
81 if ( ! data [ pattern.getContent ( ).size ( ) - 1 ] ) {
82 result.insert(i+1);
83 break;
84 }
85 }
86 }
87
88 return result;
89}
90
91} // namespace simulations
92
93} // namespace stringology
94
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
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::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
static ext::map< SymbolType, ext::vector< bool > > constructDVectors(const ext::set< SymbolType > &alphabet, const string::LinearString< SymbolType > &pattern)
Definition: BitParalelism.h:22
Definition: GeneralizedLevenshteinBitParalelism.h:17
static ext::set< unsigned int > search(const string::LinearString< SymbolType > &text, const string::LinearString< SymbolType > &pattern, unsigned int errors)
Definition: GeneralizedLevenshteinBitParalelism.h:24
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