Revert changes of hash functions signatures and fix callers

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2022-10-21 22:21:17 +02:00
parent 905a95e166
commit bbcdedb945
6 changed files with 21 additions and 21 deletions

View File

@ -277,13 +277,13 @@ void ColumnArray::updateWeakHash32(WeakHash32 & hash) const
{ {
/// This row improves hash a little bit according to integration tests. /// This row improves hash a little bit according to integration tests.
/// It is the same as to use previous hash value as the first element of array. /// It is the same as to use previous hash value as the first element of array.
hash_data[i] = intHashCRC32(hash_data[i]); hash_data[i] = static_cast<UInt32>(intHashCRC32(hash_data[i]));
for (size_t row = prev_offset; row < offsets_data[i]; ++row) for (size_t row = prev_offset; row < offsets_data[i]; ++row)
/// It is probably not the best way to combine hashes. /// It is probably not the best way to combine hashes.
/// But much better then xor which lead to similar hash for arrays like [1], [1, 1, 1], [1, 1, 1, 1, 1], ... /// But much better then xor which lead to similar hash for arrays like [1], [1, 1, 1], [1, 1, 1, 1, 1], ...
/// Much better implementation - to add offsets as an optional argument to updateWeakHash32. /// Much better implementation - to add offsets as an optional argument to updateWeakHash32.
hash_data[i] = intHashCRC32(internal_hash_data[row], hash_data[i]); hash_data[i] = static_cast<UInt32>(intHashCRC32(internal_hash_data[row], hash_data[i]));
prev_offset = offsets_data[i]; prev_offset = offsets_data[i];
} }

View File

@ -148,7 +148,7 @@ void ColumnConst::updateWeakHash32(WeakHash32 & hash) const
size_t data_hash = element_hash.getData()[0]; size_t data_hash = element_hash.getData()[0];
for (auto & value : hash.getData()) for (auto & value : hash.getData())
value = intHashCRC32(data_hash, value); value = static_cast<UInt32>(intHashCRC32(data_hash, value));
} }
void ColumnConst::compareColumn( void ColumnConst::compareColumn(

View File

@ -109,7 +109,7 @@ void ColumnDecimal<T>::updateWeakHash32(WeakHash32 & hash) const
while (begin < end) while (begin < end)
{ {
*hash_data = intHashCRC32(*begin, *hash_data); *hash_data = static_cast<UInt32>(intHashCRC32(*begin, *hash_data));
++begin; ++begin;
++hash_data; ++hash_data;
} }

View File

@ -789,7 +789,7 @@ void ColumnLowCardinality::Index::updateWeakHash(WeakHash32 & hash, WeakHash32 &
auto size = data.size(); auto size = data.size();
for (size_t i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
hash_data[i] = intHashCRC32(dict_hash_data[data[i]], hash_data[i]); hash_data[i] = static_cast<UInt32>(intHashCRC32(dict_hash_data[data[i]], hash_data[i]));
}; };
callForType(std::move(update_weak_hash), size_of_type); callForType(std::move(update_weak_hash), size_of_type);

View File

@ -84,7 +84,7 @@ void ColumnVector<T>::updateWeakHash32(WeakHash32 & hash) const
while (begin < end) while (begin < end)
{ {
*hash_data = hashCRC32(*begin, *hash_data); *hash_data = static_cast<UInt32>(hashCRC32(*begin, *hash_data));
++begin; ++begin;
++hash_data; ++hash_data;
} }

View File

@ -51,33 +51,33 @@ inline DB::UInt64 intHash64(DB::UInt64 x)
/// NOTE: Intel intrinsic can be confusing. /// NOTE: Intel intrinsic can be confusing.
/// - https://code.google.com/archive/p/sse-intrinsics/wikis/PmovIntrinsicBug.wiki /// - https://code.google.com/archive/p/sse-intrinsics/wikis/PmovIntrinsicBug.wiki
/// - https://stackoverflow.com/questions/15752770/mm-crc32-u64-poorly-defined /// - https://stackoverflow.com/questions/15752770/mm-crc32-u64-poorly-defined
inline DB::UInt32 intHashCRC32(DB::UInt64 x) inline DB::UInt64 intHashCRC32(DB::UInt64 x)
{ {
#ifdef __SSE4_2__ #ifdef __SSE4_2__
return static_cast<UInt32>(_mm_crc32_u64(-1ULL, x)); return _mm_crc32_u64(-1ULL, x);
#elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) #elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
return static_cast<UInt32>(__crc32cd(-1U, x)); return __crc32cd(-1U, x);
#else #else
/// On other platforms we do not have CRC32. NOTE This can be confusing. /// On other platforms we do not have CRC32. NOTE This can be confusing.
/// NOTE: consider using intHash32() /// NOTE: consider using intHash32()
return static_cast<UInt32>(intHash64(x)); return intHash64(x);
#endif #endif
} }
inline DB::UInt32 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value) inline DB::UInt64 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value)
{ {
#ifdef __SSE4_2__ #ifdef __SSE4_2__
return static_cast<UInt32>(_mm_crc32_u64(updated_value, x)); return _mm_crc32_u64(updated_value, x);
#elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) #elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
return __crc32cd(static_cast<UInt32>(updated_value), x); return __crc32cd(static_cast<UInt32>(updated_value), x);
#else #else
/// On other platforms we do not have CRC32. NOTE This can be confusing. /// On other platforms we do not have CRC32. NOTE This can be confusing.
return static_cast<UInt32>(intHash64(x) ^ updated_value); return intHash64(x) ^ updated_value;
#endif #endif
} }
template <typename T> template <typename T>
requires (sizeof(T) > sizeof(DB::UInt64)) requires (sizeof(T) > sizeof(DB::UInt64))
inline DB::UInt32 intHashCRC32(const T & x, DB::UInt64 updated_value) inline DB::UInt64 intHashCRC32(const T & x, DB::UInt64 updated_value)
{ {
const auto * begin = reinterpret_cast<const char *>(&x); const auto * begin = reinterpret_cast<const char *>(&x);
for (size_t i = 0; i < sizeof(T); i += sizeof(UInt64)) for (size_t i = 0; i < sizeof(T); i += sizeof(UInt64))
@ -86,7 +86,7 @@ inline DB::UInt32 intHashCRC32(const T & x, DB::UInt64 updated_value)
begin += sizeof(DB::UInt64); begin += sizeof(DB::UInt64);
} }
return static_cast<UInt32>(updated_value); return updated_value;
} }
@ -126,14 +126,14 @@ inline UInt32 updateWeakHash32(const DB::UInt8 * pos, size_t size, DB::UInt32 up
} }
reinterpret_cast<unsigned char *>(&value)[7] = size; reinterpret_cast<unsigned char *>(&value)[7] = size;
return intHashCRC32(value, updated_value); return static_cast<UInt32>(intHashCRC32(value, updated_value));
} }
const auto * end = pos + size; const auto * end = pos + size;
while (pos + 8 <= end) while (pos + 8 <= end)
{ {
auto word = unalignedLoad<UInt64>(pos); auto word = unalignedLoad<UInt64>(pos);
updated_value = intHashCRC32(word, updated_value); updated_value = static_cast<UInt32>(intHashCRC32(word, updated_value));
pos += 8; pos += 8;
} }
@ -151,7 +151,7 @@ inline UInt32 updateWeakHash32(const DB::UInt8 * pos, size_t size, DB::UInt32 up
/// Use least byte to store tail length. /// Use least byte to store tail length.
word |= tail_size; word |= tail_size;
/// Now word is '\3\0\0\0\0XYZ' /// Now word is '\3\0\0\0\0XYZ'
updated_value = intHashCRC32(word, updated_value); updated_value = static_cast<UInt32>(intHashCRC32(word, updated_value));
} }
return updated_value; return updated_value;
@ -222,7 +222,7 @@ template <typename T> struct HashCRC32;
template <typename T> template <typename T>
requires (sizeof(T) <= sizeof(UInt64)) requires (sizeof(T) <= sizeof(UInt64))
inline UInt32 hashCRC32(T key, DB::UInt64 updated_value = -1) inline size_t hashCRC32(T key, DB::UInt64 updated_value = -1)
{ {
union union
{ {
@ -236,7 +236,7 @@ inline UInt32 hashCRC32(T key, DB::UInt64 updated_value = -1)
template <typename T> template <typename T>
requires (sizeof(T) > sizeof(UInt64)) requires (sizeof(T) > sizeof(UInt64))
inline UInt32 hashCRC32(T key, DB::UInt64 updated_value = -1) inline size_t hashCRC32(T key, DB::UInt64 updated_value = -1)
{ {
return intHashCRC32(key, updated_value); return intHashCRC32(key, updated_value);
} }
@ -244,7 +244,7 @@ inline UInt32 hashCRC32(T key, DB::UInt64 updated_value = -1)
#define DEFINE_HASH(T) \ #define DEFINE_HASH(T) \
template <> struct HashCRC32<T>\ template <> struct HashCRC32<T>\
{\ {\
UInt32 operator() (T key) const\ size_t operator() (T key) const\
{\ {\
return hashCRC32<T>(key);\ return hashCRC32<T>(key);\
}\ }\