-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFSM_alg.cpp
69 lines (55 loc) · 1.48 KB
/
FSM_alg.cpp
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
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <iomanip>
using namespace std;
double PCFreq = 0.0;
__int64 CounterStart = 0;
int currentLine=1;
void StartCounter()
{
LARGE_INTEGER li;
if(!QueryPerformanceFrequency(&li))
cout << "QueryPerformanceFrequency failed!\n";
PCFreq = double(li.QuadPart)/1000000.0;
QueryPerformanceCounter(&li);
CounterStart = li.QuadPart;
}
double GetCounter()
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return double(li.QuadPart-CounterStart)/PCFreq;
}
;
void fsmSearch(string pattern ,string line ){
int currentState = 0;
for(int x=0; x<line.size(); x++){
if(line[x] == pattern[currentState]){
currentState++;
}else if(currentState == pattern.size()){
currentState = 0;
//cout<<"line -> "<<currentLine<<". Pattern found at the index - > "<<x-pattern.size()<<endl;
}else{
currentState = 0;
}
}
currentLine++;
}
int main(){
ifstream myFile("data.txt");
string line;
StartCounter();
if(myFile.is_open()){
while(getline(myFile,line)){
fsmSearch("netwothreeftyujmnkoplkjhqertyujhnbytghjoplkjhbzxcvqerfgtyxcprtghjuiolpnetwothreeftyujmnkoplkjhqertyujhnbytghjoplkjhbzxcvqerfgtyxcprtghjuiolp",line);
}
}else{
cout<<"ERROR : while opening 'data.txt' "<<endl;
}
double var=GetCounter();
cout<<var<<endl;
return 0;
}