diff --git a/src/Common/HashTable/Hash.h b/src/Common/HashTable/Hash.h index abd1a69545f62fad56383cbd5da12690c14da529..3d9cec1bb23cdb9f515d95082728b155c6aec432 100644 --- a/src/Common/HashTable/Hash.h +++ b/src/Common/HashTable/Hash.h @@ -73,7 +73,7 @@ inline DB::UInt64 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value) } template -inline typename std::enable_if<(sizeof(T) > sizeof(DB::UInt64)) && !is_big_int_v, DB::UInt64>::type +inline typename std::enable_if<(sizeof(T) > sizeof(DB::UInt64)), DB::UInt64>::type intHashCRC32(const T & x, DB::UInt64 updated_value) { auto * begin = reinterpret_cast(&x); @@ -86,16 +86,6 @@ intHashCRC32(const T & x, DB::UInt64 updated_value) return updated_value; } -template -inline typename std::enable_if, DB::UInt64>::type -intHashCRC32(const T & x, DB::UInt64 updated_value) -{ - std::vector parts = DB::BigInt::toIntArray(x); - for (const auto & part : parts) - updated_value = intHashCRC32(part, updated_value); - - return updated_value; -} inline UInt32 updateWeakHash32(const DB::UInt8 * pos, size_t size, DB::UInt32 updated_value) { @@ -248,22 +238,7 @@ inline size_t hashCRC32(std::enable_if_t<(sizeof(T) <= sizeof(UInt64)), T> key) template inline size_t hashCRC32(std::enable_if_t<(sizeof(T) > sizeof(UInt64)), T> key) { - if constexpr (std::is_same_v) - { - return intHashCRC32(static_cast(key) ^ static_cast(key >> 64)); - } - else if constexpr (std::is_same_v) - { - return intHashCRC32(key.low ^ key.high); - } - else if constexpr (is_big_int_v && sizeof(T) == 32) - { - return intHashCRC32(static_cast(key) ^ - static_cast(key >> 64) ^ - static_cast(key >> 128) ^ - static_cast(key >> 256)); - } - __builtin_unreachable(); + return intHashCRC32(key, -1); } #define DEFINE_HASH(T) \ diff --git a/src/Core/BigInt.h b/src/Core/BigInt.h index 5abd71100629c139183ea042eff8e688f59d7969..8ce765fbc2091136a423a247968cd2f746761ae7 100644 --- a/src/Core/BigInt.h +++ b/src/Core/BigInt.h @@ -1,8 +1,10 @@ #pragma once #include +#include #include + namespace DB { @@ -14,8 +16,7 @@ struct BigInt static StringRef serialize(const T & x, char * pos) { - //unalignedStore(pos, x); - memcpy(pos, &x, size); + unalignedStore(pos, x); return StringRef(pos, size); } @@ -28,20 +29,7 @@ struct BigInt static T deserialize(const char * pos) { - //return unalignedLoad(pos); - T res; - memcpy(&res, pos, size); - return res; - } - - static std::vector toIntArray(const T & x) - { - std::vector parts(4, 0); - parts[0] = UInt64(x); - parts[1] = UInt64(x >> 64); - parts[2] = UInt64(x >> 128); - parts[4] = UInt64(x >> 192); - return parts; + return unalignedLoad(pos); } };