adding std::hash to fc::ip::endpoint

This commit is contained in:
Daniel Larimer 2013-07-12 01:21:53 -04:00
parent 4bfaa4b962
commit fa98cb6816
2 changed files with 21 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <fc/string.hpp> #include <fc/string.hpp>
#include <fc/crypto/sha1.hpp>
namespace fc { namespace fc {
@ -53,3 +54,13 @@ namespace fc {
void to_variant( const ip::address& var, variant& vo ); void to_variant( const ip::address& var, variant& vo );
void from_variant( const variant& var, ip::address& vo ); void from_variant( const variant& var, ip::address& vo );
} }
namespace std
{
template<typename T> struct hash;
template<>
struct hash<fc::ip::endpoint>
{
size_t operator()( const fc::ip::endpoint& e )const;
};
}

View file

@ -75,3 +75,13 @@ namespace fc { namespace ip {
} }
} }
namespace std
{
size_t hash<fc::ip::endpoint>::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;
}
}