From a2ef0f6cba515e47e2c443baff82a5554efb6884 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 10 Oct 2020 18:46:41 +0300 Subject: [PATCH] Minor changes in BigInt hash --- src/Common/HashTable/Hash.h | 29 ++--------------------------- src/Core/BigInt.h | 20 ++++---------------- 2 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/Common/HashTable/Hash.h b/src/Common/HashTable/Hash.h index abd1a69545..3d9cec1bb2 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 5abd711006..8ce765fbc2 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); } }; -- GitLab