Fix build.

This commit is contained in:
Nikolai Kochetov 2020-03-18 19:18:37 +03:00
parent e26eac4649
commit e76877c5ed
4 changed files with 28 additions and 32 deletions

View File

@ -265,35 +265,6 @@ struct CRC32Hash
return res;
}
static UInt32 updateWeakHash(StringRef x, UInt32 updated_value)
{
const char * pos = x.data;
size_t size = x.size;
if (size < 8)
{
auto value = unalignedLoad<UInt64>(pos);
/// 8 bytes were loaded to UInt64 value, but string size is less then 8 bytes.
/// We need to zero excessive bytes to remove the garbage.
/// But instead we move bits to the right, so that we had zeros at left.
/// It helps to have different hash for strings like 'a' and 'a\0'
value >>= UInt8(8 * (8 - size));
return intHashCRC32(value, updated_value);
}
const char * end = pos + size;
while (pos + 8 < end)
{
auto word = unalignedLoad<UInt64>(pos);
updated_value = intHashCRC32(word, updated_value);
pos += 8;
}
auto word = unalignedLoad<UInt64>(pos - 8);
return intHashCRC32(word, updated_value);
}
};
struct StringRefHash : CRC32Hash {};

View File

@ -7,7 +7,7 @@
#include <Common/memcmpSmall.h>
#include <Common/assert_cast.h>
#include <Common/WeakHash.h>
#include <common/StringRef.h>
#include <Common/HashTable/Hash.h>
#include <DataStreams/ColumnGathererStream.h>
@ -116,7 +116,7 @@ void ColumnFixedString::updateWeakHash32(WeakHash32 & hash) const
for (size_t row = 0; row < s; ++row)
{
*hash_data = StringRefHash::updateWeakHash(StringRef(pos, n), *hash_data);
*hash_data = ::updateWeakHash32(pos, n, *hash_data);
pos += n;
++hash_data;

View File

@ -80,7 +80,7 @@ void ColumnString::updateWeakHash32(WeakHash32 & hash) const
for (auto & offset : offsets)
{
auto str_size = offset - prev_offset;
*hash_data = StringRefHash::updateWeakHash(StringRef(pos, str_size), *hash_data);
*hash_data = ::updateWeakHash32(pos, str_size, *hash_data);
pos += str_size;
prev_offset = offset;

View File

@ -70,6 +70,31 @@ inline DB::UInt64 intHashCRC32(DB::UInt64 x, DB::UInt64 updated_value)
#endif
}
UInt32 updateWeakHash32(const DB::UInt8 * pos, size_t size, DB::UInt32 updated_value)
{
if (size < 8)
{
auto value = unalignedLoad<DB::UInt64>(pos);
/// 8 bytes were loaded to UInt64 value, but string size is less then 8 bytes.
/// We need to zero excessive bytes to remove the garbage.
/// But instead we move bits to the right, so that we had zeros at left.
/// It helps to have different hash for strings like 'a' and 'a\0'
value >>= UInt8(8 * (8 - size));
return intHashCRC32(value, updated_value);
}
const auto * end = pos + size;
while (pos + 8 < end)
{
auto word = unalignedLoad<UInt64>(pos);
updated_value = intHashCRC32(word, updated_value);
pos += 8;
}
auto word = unalignedLoad<UInt64>(pos - 8);
return intHashCRC32(word, updated_value);
}
template <typename T>
inline size_t DefaultHash64(T key)