Allow hashing of uint128

This commit is contained in:
Nathan Hourt 2015-03-06 16:41:52 -05:00
parent 9b7753b127
commit 4194a609c2
3 changed files with 15 additions and 8 deletions

View file

@ -44,11 +44,13 @@
#include <stdlib.h> // for size_t. #include <stdlib.h> // for size_t.
#include <stdint.h> #include <stdint.h>
#include <utility> #include <utility>
#include <fc/uint128.hpp>
#include <fc/array.hpp>
namespace fc { namespace fc {
class uint128;
template<typename T, size_t N>
class array;
// Hash function for a byte array. // Hash function for a byte array.
uint64_t city_hash64(const char *buf, size_t len); uint64_t city_hash64(const char *buf, size_t len);

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <fc/exception/exception.hpp> #include <fc/exception/exception.hpp>
#include <fc/crypto/city.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (push) #pragma warning (push)
@ -22,7 +23,7 @@ namespace fc
public: public:
uint128():hi(0),lo(0){}; uint128():hi(0),lo(0){}
uint128( uint32_t l ):hi(0),lo(l){} uint128( uint32_t l ):hi(0),lo(l){}
uint128( int32_t l ):hi( -(l<0) ),lo(l){} uint128( int32_t l ):hi( -(l<0) ),lo(l){}
uint128( int64_t l ):hi( -(l<0) ),lo(l){} uint128( int64_t l ):hi( -(l<0) ),lo(l){}
@ -76,6 +77,8 @@ namespace fc
friend bool operator >= ( const uint128& l, const uint128& r ) { return l == r || l > r; } friend bool operator >= ( const uint128& l, const uint128& r ) { return l == r || l > r; }
friend bool operator <= ( const uint128& l, const uint128& r ) { return l == r || l < r; } friend bool operator <= ( const uint128& l, const uint128& r ) { return l == r || l < r; }
friend std::size_t hash_value( const uint128& v ) { return city_hash_size_t((const char*)&v, sizeof(v)); }
uint32_t to_integer()const uint32_t to_integer()const
{ {
FC_ASSERT( hi == 0 ); FC_ASSERT( hi == 0 );

View file

@ -33,6 +33,8 @@
#include <algorithm> #include <algorithm>
#include <string.h> // for memcpy and memset #include <string.h> // for memcpy and memset
#include <fc/crypto/city.hpp> #include <fc/crypto/city.hpp>
#include <fc/uint128.hpp>
#include <fc/array.hpp>
#if defined(__SSE4_2__) && defined(__x86_64__) #if defined(__SSE4_2__) && defined(__x86_64__)
#include <nmmintrin.h> #include <nmmintrin.h>