hmbdc
simplify-high-performance-messaging-programming
 All Classes Namespaces Functions Variables Friends Pages
Hash.hpp
1 #include "hmbdc/Copyright.hpp"
2 #pragma once
3 
4 #include <functional>
5 
6 namespace hmbdc { namespace comm { namespace inet {
7 
8 template <typename asio_endpoint>
9 struct HashEndpoint {
10  typedef asio_endpoint argument_type;
11  typedef std::size_t result_type;
12  result_type operator()(argument_type const& e) const noexcept {
13  uint64_t v = e.port();
14  v += ((e.address().to_v4().to_ulong()) << 32u);
15  return std::hash<uint64_t>{}(v);
16  }
17 };
18 
19 template <typename sockaddr_in>
21  typedef sockaddr_in argument_type;
22  typedef std::size_t result_type;
23  result_type operator()(sockaddr_in const& e) const noexcept {
24  uint64_t v = e.sin_port;
25  v <<= 32u;
26  v += e.sin_addr.s_addr;
27  return std::hash<uint64_t>{}(v);
28  }
29 };
30 
31 template <typename sockaddr_in>
33  bool operator ()(sockaddr_in const& a, sockaddr_in const& b) const {
34  return a.sin_addr.s_addr == b.sin_addr.s_addr &&
35  a.sin_port == b.sin_port;
36  }
37 };
38 }}}
39 
Definition: Hash.hpp:32
Definition: Hash.hpp:9
Definition: Hash.hpp:20