update part 1
This commit is contained in:
parent
ebb6e83745
commit
dd0de524ac
|
@ -24,18 +24,29 @@ int main(int argc, char **argv)
|
||||||
int search_start_position = atoi(argv[3]);
|
int search_start_position = atoi(argv[3]);
|
||||||
int search_end_position = atoi(argv[4]);
|
int search_end_position = atoi(argv[4]);
|
||||||
int find = 0;
|
int find = 0;
|
||||||
|
int pid = getpid();
|
||||||
ifstream file(file_to_search_in, ios::binary);
|
ifstream file(file_to_search_in, ios::binary);
|
||||||
|
int len2 = search_end_position - search_start_position;
|
||||||
|
string buffer;
|
||||||
|
buffer.resize(len2);
|
||||||
|
// file.seekg(i);
|
||||||
|
file.read(&buffer[0], len2);
|
||||||
//TODO
|
//TODO
|
||||||
for(int i = search_start_position; i < search_end_position; ++i) {
|
auto a = buffer.find(pattern_to_search_for);
|
||||||
char *buffer = new char[len];
|
if(a != string::npos) {
|
||||||
file.seekg(i);
|
cout << "[" << pid << "]" << " found at" << " " << a<< endl;
|
||||||
file.read(buffer, len);
|
|
||||||
if(!strcmp(buffer, pattern_to_search_for)) {
|
|
||||||
cout << "[1] found at" << " " << i << endl;
|
|
||||||
find = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(find == 0) cout << "[1] didn't find\n";
|
else {
|
||||||
|
cout << "[" << pid << "]" << " didn't find\n";
|
||||||
|
}
|
||||||
|
// for(int i = search_start_position; i < search_end_position; ++i) {
|
||||||
|
// if(!strcmp(buffer, pattern_to_search_for)) {
|
||||||
|
// cout << "[" << pid << "]" << " found at" << " " << i << endl;
|
||||||
|
// find = 1;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if(find == 0) cout << "[" << pid << "]" << " didn't find\n";
|
||||||
auto endmain = std::chrono::high_resolution_clock::now();
|
auto endmain = std::chrono::high_resolution_clock::now();
|
||||||
chrono::duration<double> mainduration = endmain - startmain;
|
chrono::duration<double> mainduration = endmain - startmain;
|
||||||
cout << mainduration.count() << endl;
|
cout << mainduration.count() << endl;
|
||||||
|
|
Loading…
Reference in New Issue