-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyValuePair.h
68 lines (51 loc) · 1.31 KB
/
KeyValuePair.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef KEYVALUEPAIR_H
#define KEYVALUEPAIR_H
// DO NOT CHANGE THIS FILE.
#include <iostream>
template<class K, class V>
class KeyValuePair {
public:
KeyValuePair() {}
KeyValuePair(const K &key) {
this->key = key;
}
KeyValuePair(const K &key, const V &value) {
this->key = key;
this->value = value;
}
bool operator<(const KeyValuePair &rhs) const {
return key < rhs.key;
}
bool operator>(const KeyValuePair &rhs) const {
return rhs < *this;
}
bool operator<=(const KeyValuePair &rhs) const {
return !(rhs < *this);
}
bool operator>=(const KeyValuePair &rhs) const {
return !(*this < rhs);
}
bool operator==(const KeyValuePair &rhs) const {
return key == rhs.key;
}
bool operator!=(const KeyValuePair &rhs) const {
return !(rhs == *this);
}
const K &getKey() const {
return key;
}
const V &getValue() const {
return value;
}
void setValue(const V &value) {
this->value = value;
}
friend std::ostream &operator<<(std::ostream &os, const KeyValuePair &pair) {
os << "KeyValuePair(key: \"" << pair.key << "\", value: \"" << pair.value << "\")";
return os;
}
private:
K key;
V value;
};
#endif //KEYVALUEPAIR_H