mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #15812 from ClickHouse/bigint-hash
Minor changes in BigInt hash
This commit is contained in:
commit
39e58128cd
@ -73,7 +73,7 @@ inline DB::UInt64 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value)
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
auto * begin = reinterpret_cast<const char *>(&x);
|
||||
@ -86,16 +86,6 @@ intHashCRC32(const T & x, DB::UInt64 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)
|
||||
{
|
||||
@ -248,22 +238,7 @@ inline size_t hashCRC32(std::enable_if_t<(sizeof(T) <= sizeof(UInt64)), T> key)
|
||||
template <typename T>
|
||||
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(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();
|
||||
return intHashCRC32(key, -1);
|
||||
}
|
||||
|
||||
#define DEFINE_HASH(T) \
|
||||
|
@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/StringRef.h>
|
||||
#include <common/unaligned.h>
|
||||
#include <Core/Types.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -14,8 +16,7 @@ struct BigInt
|
||||
|
||||
static StringRef serialize(const T & x, char * pos)
|
||||
{
|
||||
//unalignedStore<T>(pos, x);
|
||||
memcpy(pos, &x, size);
|
||||
unalignedStore<T>(pos, x);
|
||||
return StringRef(pos, size);
|
||||
}
|
||||
|
||||
@ -28,20 +29,7 @@ struct BigInt
|
||||
|
||||
static T deserialize(const char * 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;
|
||||
return unalignedLoad<T>(pos);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user