-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocument.cpp
More file actions
30 lines (28 loc) · 1.08 KB
/
Copy pathdocument.cpp
File metadata and controls
30 lines (28 loc) · 1.08 KB
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 "document.h"
using namespace std;
// перегрузка оператора == для типа Document
bool operator == (const Document &lhs, const Document &rhs) {
return (lhs.id == rhs.id &&
lhs.rating == rhs.rating &&
abs(lhs.relevance - rhs.relevance) < 1e-6);
}
bool operator != (const Document &lhs, const Document &rhs) {
return !(lhs==rhs);
}
// перегрузка оператора < для типа Document
bool operator < (const Document &lhs, const Document &rhs) {
//сравниваем документы по убыванию релевантности и рейтинга
if (abs(lhs.relevance - rhs.relevance) < 1e-6) {
return lhs.rating < rhs.rating;
}
return lhs.relevance < rhs.relevance;
}
// перегрузка оператора << для типа Document
ostream& operator << (ostream &os, const Document &rhs) {
os << "{ "s
<< "document_id = "s << rhs.id << ", "s
<< "relevance = "s << rhs.relevance << ", "s
<< "rating = "s << rhs.rating
<< " }"s;
return os;
}