-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremove_duplicates.cpp
More file actions
31 lines (25 loc) · 919 Bytes
/
Copy pathremove_duplicates.cpp
File metadata and controls
31 lines (25 loc) · 919 Bytes
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
#include <set>
#include <vector>
#include "remove_duplicates.h"
using namespace std;
void RemoveDuplicates(SearchServer &search_server) {
set<set<string_view, std::less<>>> unique_docs;
vector<int> docs_to_delete;
for (const int id : search_server) {
const map<string_view, double> word_freqs = search_server.GetWordFrequencies(id);
set<string_view, std::less<>> words;
transform(word_freqs.begin(), word_freqs.end(), inserter(words, words.begin()),
[](const pair<string_view, double> word) {
return word.first;
});
if (unique_docs.count(words) == 0) {
unique_docs.insert(words);
} else {
docs_to_delete.push_back(id);
}
}
for (const int id : docs_to_delete) {
cout << "Found duplicate document id " + to_string(id) << "\n";
search_server.RemoveDocument(id);
}
}