forked from K3n1-Code/KMP-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_search.cpp
More file actions
60 lines (48 loc) · 1.01 KB
/
text_search.cpp
File metadata and controls
60 lines (48 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cmath>
using namespace std;
class Matrix{
private:
vector<vector<int>> matrix;
int size[2];
public:
Matrix(int w, int h){
size[0]=w;
size[1]=h;
matrix=vector<vector<int>>(w);
for(int k=0;k<w;k++){
matrix[k]=vector<int>(h);
}
}
Matrix(){
this->matrix=vector<vector<int>>();
size[0]=0;
size[1]=0;
}
int width(){return size[0];}
int height(){return size[1];}
vector<int> operator[](const int &w){
return matrix[w];
}
};
Matrix computeFailureFunction(string str){
Matrix func(256,str.length());
for(int c=0;c<256;c++){
func[c][0]=0;
}
func[str[0]][0]=1;
int x=0;
for(int k=1;k<str.length()-1;k++){
for(int c=0;c<256;c++){
func[c][k]=func[c][x];
}
func[str[k]][k]=k+1;
x=func[str[k]][x];
}
return func;
}
int main(){
}