From fa98cb681630a17a10bd3953b6f9c0776508e24f Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 12 Jul 2013 01:21:53 -0400 Subject: [PATCH] adding std::hash to fc::ip::endpoint --- include/fc/network/ip.hpp | 11 +++++++++++ src/network/ip.cpp | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/fc/network/ip.hpp b/include/fc/network/ip.hpp index f21eb27..20c9509 100644 --- a/include/fc/network/ip.hpp +++ b/include/fc/network/ip.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include namespace fc { @@ -53,3 +54,13 @@ namespace fc { void to_variant( const ip::address& var, variant& vo ); void from_variant( const variant& var, ip::address& vo ); } +namespace std +{ + template struct hash; + + template<> + struct hash + { + size_t operator()( const fc::ip::endpoint& e )const; + }; +} diff --git a/src/network/ip.cpp b/src/network/ip.cpp index 9a906bd..26c628a 100644 --- a/src/network/ip.cpp +++ b/src/network/ip.cpp @@ -75,3 +75,13 @@ namespace fc { namespace ip { } } +namespace std +{ + size_t hash::operator()( const fc::ip::endpoint& e )const + { + auto h = fc::sha1::hash( (char*)&e, sizeof(e) ); + size_t s; + memcpy( (char*)&s, (char*)&h, sizeof(s) ); + return s; + } +}