Skip to content

Commit 5a21450

Browse files
[Bugfix:Plagiarism] Remove merge logic (#22)
* fix hash * remove common for now...
1 parent 01f33bb commit 5a21450

File tree

1 file changed

+21
-72
lines changed

1 file changed

+21
-72
lines changed

compare_hashes/compare_hashes.cpp

+21-72
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void insert_others(const std::string &this_username,
8181
}
8282
}
8383

84-
void convert(std::map<Submission,std::set<int> > &myset, nlohmann::json &obj) {
84+
void convert(std::map<Submission,std::set<int> > &myset, nlohmann::json &obj, int sequence_length) {
8585
for (std::map<Submission,std::set<int> >::iterator itr = myset.begin(); itr != myset.end(); itr++) {
8686
nlohmann::json me;
8787
me["username"] = itr->first.username;
@@ -91,25 +91,14 @@ void convert(std::map<Submission,std::set<int> > &myset, nlohmann::json &obj) {
9191
int start = -1;
9292
int end = -1;
9393
std::set<int>::iterator itr2 = itr->second.begin();
94-
while (true) {
95-
int pos = (itr2 == itr->second.end()) ? -1 : *itr2;
96-
if (pos != -1 && start == -1) {
97-
start = end = pos;
98-
} else if (pos != -1 && end+1 == pos) {
99-
end = pos;
100-
} else if (start != -1) {
101-
nlohmann::json range;
102-
range["start"] = start;
103-
range["end"] = end;
104-
start=end=-1;
105-
foo.push_back(range);
106-
}
107-
if (itr2 == itr->second.end()) {
108-
break;
109-
}
110-
itr2++;
94+
for (; itr2 != itr->second.end(); itr2++) {
95+
start = *itr2;
96+
end = start + sequence_length;
97+
nlohmann::json range;
98+
range["start"] = start;
99+
range["end"] = end;
100+
foo.push_back(range);
111101
}
112-
113102
me["matchingpositions"] = foo;
114103
obj.push_back(me);
115104
}
@@ -278,60 +267,20 @@ int main(int argc, char* argv[]) {
278267
int range_end=-1;
279268
std::map<Submission, std::set<int> > others;
280269
std::map<int,std::map<Submission,std::vector<Sequence> > >::iterator itr2 = itr->second.begin();
281-
while (true) {
282-
int pos = (itr2 == itr->second.end()) ? -1 : itr2->first;
283-
if (pos != -1 && range_start==-1) {
284-
range_start = range_end = pos;
285-
insert_others(username,others,itr2->second);
286-
} else if (pos != -1 && range_end+1 == pos) {
287-
range_end = pos;
288-
insert_others(username,others,itr2->second);
289-
} else if (range_start != -1) {
290-
std::map<std::string,nlohmann::json> info_data;
291-
info_data["start"]=nlohmann::json(range_start);
292-
info_data["end"]=nlohmann::json(range_end);
293-
info_data["type"]=nlohmann::json(std::string("match"));
294-
nlohmann::json obj;
295-
convert(others,obj);
296-
info_data["others"]=obj;
297-
info.push_back(info_data);
298-
range_start=range_end=-1;
299-
others.clear();
300-
}
301-
if (itr2 == itr->second.end()) {
302-
break;
303-
}
304-
itr2++;
305-
}
306270

307-
std::map<Submission,std::set<int> >::iterator itr3 = common.find(itr->first);
308-
if (itr3 != common.end()) {
309-
//std::cout << "HAS COMMON CODE" << std::endl;
310-
int range_start=-1;
311-
int range_end=-1;
312-
for (std::set<int>::iterator itr4 = itr3->second.begin(); itr4 != itr3->second.end(); itr4++) {
313-
//std::cout << "v=" << *itr4 << std::endl;
314-
if (range_start == -1) {
315-
range_start = range_end = *itr4;
316-
} else if (range_end+1 == *itr4) {
317-
range_end = *itr4;
318-
} else {
319-
std::map<std::string,nlohmann::json> info_data;
320-
info_data["start"]=nlohmann::json(range_start);
321-
info_data["end"]=nlohmann::json(range_end);
322-
info_data["type"]=std::string("common");
323-
info.push_back(info_data);
324-
range_start = range_end = -1;
325-
}
326-
}
327-
if (range_start != -1) {
328-
std::map<std::string,nlohmann::json> info_data;
329-
info_data["start"]=nlohmann::json(range_start);
330-
info_data["end"]=nlohmann::json(range_end);
331-
info_data["type"]=std::string("common");
332-
info.push_back(info_data);
333-
range_start=range_end=-1;
334-
}
271+
for (; itr2 != itr->second.end(); itr2++) {
272+
range_start = itr2->first;
273+
range_end = range_start + sequence_length;
274+
insert_others(username,others,itr2->second);
275+
std::map<std::string,nlohmann::json> info_data;
276+
info_data["start"]=nlohmann::json(range_start);
277+
info_data["end"]=nlohmann::json(range_end);
278+
info_data["type"]=nlohmann::json(std::string("match"));
279+
nlohmann::json obj;
280+
convert(others,obj, sequence_length);
281+
info_data["others"]=obj;
282+
info.push_back(info_data);
283+
others.clear();
335284
}
336285

337286
// save the file with matches per user

0 commit comments

Comments
 (0)