Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
filter.cpp
Go to the documentation of this file.
1/*
2This file expect the output of parser.cpp
3This code filter the output only printing the files similar to files that contains a given pattern passed as argc
4The code filter every file that has the pattern as a substring, so be carefull with duplications
5*/
6
7#include <bits/stdc++.h>
8using namespace std;
9
10
11bool matches(string text, string pattern){
12 return text.find(pattern) != string::npos;
13}
14
15void filter(string file_name){
16 int number_comparations;
17 cin >> number_comparations;
18
19 set<pair<string,double>> similar_files;
20
21 for(int i = 0; i < number_comparations; i++){
22 vector<string> files_compared(2);
23 double similarity;
24
25 cin >> files_compared[0] >> files_compared[1];
26 cin >> similarity;
27
28 for(int j = 0; j < 2; j++){
29 string file1 = files_compared[j];
30 string file2 = files_compared[j^1];
31
32 if(matches(file1,file_name)){
33 similar_files.insert(make_pair(file2,similarity));
34 }
35 }
36 }
37
38 for(auto [similar_file,similarity] : similar_files){
39 cout << similar_file << ' ';
40 cout << fixed << setprecision(2) << similarity << endl;
41 }
42}
43
44
45
46int main(int argc, char *argv[]){
47 if(argc <= 1){
48 cout << "Erro: Expect the name of the file to be filtred, but none has given" << endl;
49 return 0;
50 }
51 string pattern(argv[1]);
52 filter(pattern);
53 return 0;
54}
int main(int argc, char *argv[])
Definition filter.cpp:46
void filter(string file_name)
Definition filter.cpp:15
bool matches(string text, string pattern)
Definition filter.cpp:11