未验证 提交 39e58128 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #15812 from ClickHouse/bigint-hash

Minor changes in BigInt hash
...@@ -73,7 +73,7 @@ inline DB::UInt64 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value) ...@@ -73,7 +73,7 @@ inline DB::UInt64 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value)
} }
template <typename T> template <typename T>
inline typename std::enable_if<(sizeof(T) > sizeof(DB::UInt64)) && !is_big_int_v<T>, DB::UInt64>::type inline typename std::enable_if<(sizeof(T) > sizeof(DB::UInt64)), DB::UInt64>::type
intHashCRC32(const T & x, DB::UInt64 updated_value) intHashCRC32(const T & x, DB::UInt64 updated_value)
{ {
auto * begin = reinterpret_cast<const char *>(&x); auto * begin = reinterpret_cast<const char *>(&x);
...@@ -86,16 +86,6 @@ intHashCRC32(const T & x, DB::UInt64 updated_value) ...@@ -86,16 +86,6 @@ intHashCRC32(const T & x, DB::UInt64 updated_value)
return updated_value; return updated_value;
} }
template <typename T>
inline typename std::enable_if<is_big_int_v<T>, DB::UInt64>::type
intHashCRC32(const T & x, DB::UInt64 updated_value)
{
std::vector<UInt64> parts = DB::BigInt<T>::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) 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) ...@@ -248,22 +238,7 @@ inline size_t hashCRC32(std::enable_if_t<(sizeof(T) <= sizeof(UInt64)), T> key)
template <typename T> template <typename T>
inline size_t hashCRC32(std::enable_if_t<(sizeof(T) > sizeof(UInt64)), T> key) inline size_t hashCRC32(std::enable_if_t<(sizeof(T) > sizeof(UInt64)), T> key)
{ {
if constexpr (std::is_same_v<T, DB::Int128>) return intHashCRC32(key, -1);
{
return intHashCRC32(static_cast<UInt64>(key) ^ static_cast<UInt64>(key >> 64));
}
else if constexpr (std::is_same_v<T, DB::UInt128>)
{
return intHashCRC32(key.low ^ key.high);
}
else if constexpr (is_big_int_v<T> && sizeof(T) == 32)
{
return intHashCRC32(static_cast<UInt64>(key) ^
static_cast<UInt64>(key >> 64) ^
static_cast<UInt64>(key >> 128) ^
static_cast<UInt64>(key >> 256));
}
__builtin_unreachable();
} }
#define DEFINE_HASH(T) \ #define DEFINE_HASH(T) \
......
#pragma once #pragma once
#include <common/StringRef.h> #include <common/StringRef.h>
#include <common/unaligned.h>
#include <Core/Types.h> #include <Core/Types.h>
namespace DB namespace DB
{ {
...@@ -14,8 +16,7 @@ struct BigInt ...@@ -14,8 +16,7 @@ struct BigInt
static StringRef serialize(const T & x, char * pos) static StringRef serialize(const T & x, char * pos)
{ {
//unalignedStore<T>(pos, x); unalignedStore<T>(pos, x);
memcpy(pos, &x, size);
return StringRef(pos, size); return StringRef(pos, size);
} }
...@@ -28,20 +29,7 @@ struct BigInt ...@@ -28,20 +29,7 @@ struct BigInt
static T deserialize(const char * pos) static T deserialize(const char * pos)
{ {
//return unalignedLoad<T>(pos); return unalignedLoad<T>(pos);
T res;
memcpy(&res, pos, size);
return res;
}
static std::vector<UInt64> toIntArray(const T & x)
{
std::vector<UInt64> parts(4, 0);
parts[0] = UInt64(x);
parts[1] = UInt64(x >> 64);
parts[2] = UInt64(x >> 128);
parts[4] = UInt64(x >> 192);
return parts;
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册