unify city uint128 with new uint128 class
This commit is contained in:
parent
29a1346d05
commit
637372bbc2
3 changed files with 8 additions and 10 deletions
|
|
@ -44,11 +44,10 @@
|
|||
#include <stdlib.h> // for size_t.
|
||||
#include <stdint.h>
|
||||
#include <utility>
|
||||
#include <fc/uint128.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
typedef std::pair<uint64_t, uint64_t> uint128;
|
||||
|
||||
// Hash function for a byte array.
|
||||
uint64_t city_hash64(const char *buf, size_t len);
|
||||
|
||||
|
|
|
|||
|
|
@ -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" );
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue