From 637372bbc2181c527264ee95f090ecb06763fbf9 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 26 Jul 2013 23:26:51 -0400 Subject: [PATCH] unify city uint128 with new uint128 class --- include/fc/crypto/city.hpp | 3 +-- include/fc/uint128.hpp | 11 +++++------ src/crypto/city.cpp | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/fc/crypto/city.hpp b/include/fc/crypto/city.hpp index 39a6f70..9f9c34a 100644 --- a/include/fc/crypto/city.hpp +++ b/include/fc/crypto/city.hpp @@ -44,11 +44,10 @@ #include // for size_t. #include #include +#include namespace fc { -typedef std::pair uint128; - // Hash function for a byte array. uint64_t city_hash64(const char *buf, size_t len); diff --git a/include/fc/uint128.hpp b/include/fc/uint128.hpp index 23a4645..9fe280d 100644 --- a/include/fc/uint128.hpp +++ b/include/fc/uint128.hpp @@ -10,9 +10,6 @@ namespace fc */ class uint128 { - private: - uint128( uint64_t _h, uint64_t _l ) - :hi(_h),lo(_l){} uint64_t hi; uint64_t lo; @@ -24,6 +21,8 @@ namespace fc uint128( int64_t l ):hi( -(l<0) ),lo(l){} uint128( uint64_t l ):hi(0),lo(l){} uint128( const std::string& s ); + uint128( uint64_t _h, uint64_t _l ) + :hi(_h),lo(_l){} operator std::string()const; @@ -32,6 +31,7 @@ namespace fc bool operator < ( const uint128& o )const { return (hi == o.hi) ? lo < o.lo : hi < o.hi; } bool operator !()const { return !(hi !=0 || lo != 0); } uint128 operator -()const { return ++uint128( ~hi, ~lo ); } + uint128 operator ~()const { return uint128( ~hi, ~lo ); } uint128& operator++() { hi += (++lo == 0); return *this; } uint128& operator--() { hi -= (lo-- == 0); return *this; } @@ -62,14 +62,13 @@ namespace fc friend uint128 operator >> ( const uint128& l, const uint128& r ) { return uint128(l)>>=r; } friend bool operator > ( const uint128& l, const uint128& r ) { return r < l; } - uint128 operator ~()const { return uint128( ~hi, ~lo ); } - // uint128& operator ~=( const uint128& u );// { /*hi ~= u.hi; lo ~= u.lo;*/ return *this; } 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; } uint32_t to_integer()const { return lo; } - + uint64_t low_bits()const { return lo; } + uint64_t high_bits()const { return hi; } }; static_assert( sizeof(uint128) == 2*sizeof(uint64_t), "validate packing assumptions" ); diff --git a/src/crypto/city.cpp b/src/crypto/city.cpp index 1fee602..b89bfd1 100644 --- a/src/crypto/city.cpp +++ b/src/crypto/city.cpp @@ -38,8 +38,8 @@ uint64_t _mm_crc32_u64(uint64_t a, uint64_t b ); namespace fc { -inline uint64_t Uint128Low64(const uint128& x) { return x.first; } -inline uint64_t Uint128High64(const uint128& x) { return x.second; } +inline uint64_t Uint128Low64(const uint128& x) { return x.low_bits(); } +inline uint64_t Uint128High64(const uint128& x) { return x.high_bits(); } // Hash 128 input bits down to 64 bits of output. // This is intended to be a reasonably good hash function.