-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoint_hash.h
62 lines (53 loc) · 1.42 KB
/
endpoint_hash.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
#include <string>
#include <vector>
#include <iostream>
#include "boost/functional/hash.hpp"
#pragma once
enum class ip_addr_type { IPV4, IPV6 };
struct EndPoint
{
std::string SvcName;
std::string Ip_addr;
ip_addr_type Ip_type;
EndPoint(const std::string& name, const std::string& ipAddr, ip_addr_type type):
SvcName(name), Ip_addr(ipAddr), Ip_type(type)
{
}
//Copy constructor
EndPoint(const EndPoint& pt) {
SvcName = pt.SvcName;
Ip_addr = pt.Ip_addr;
Ip_type = pt.Ip_type;
}
//Move constructor
EndPoint(EndPoint&& pt) {
SvcName = std::move(pt.SvcName);
Ip_addr = std::move(pt.Ip_addr);
Ip_type = pt.Ip_type;
}
bool operator<(const EndPoint& r) const
{
return Ip_addr < r.Ip_addr;
}
bool operator>(const EndPoint& r) const
{
return Ip_addr > r.Ip_addr;
}
bool operator==(const EndPoint& r) const
{
return SvcName == r.SvcName && Ip_addr == r.Ip_addr && Ip_type == r.Ip_type;
}
size_t Hash(size_t seed = 0) const
{
boost::hash_combine(seed, std::hash<std::string>{}(SvcName));
boost::hash_combine(seed, std::hash<std::string>{}(Ip_addr));
return seed;
}
};
struct EndPointHasher
{
std::size_t operator()(EndPoint const& k) const
{
return k.Hash();
}
};