2014-11-09 12:43:09 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Stopwatch.h>
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2015-07-20 17:41:51 +00:00
|
|
|
#include <farmhash.h>
|
|
|
|
#include <metrohash.h>
|
|
|
|
|
2014-11-09 12:43:09 +00:00
|
|
|
#define DBMS_HASH_MAP_COUNT_COLLISIONS
|
|
|
|
#define DBMS_HASH_MAP_DEBUG_RESIZES
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <IO/ReadBufferFromFile.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
2018-12-28 18:15:26 +00:00
|
|
|
#include <Compression/CompressedReadBuffer.h>
|
2017-06-23 20:22:35 +00:00
|
|
|
#include <common/StringRef.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/HashTable/HashMap.h>
|
|
|
|
#include <Interpreters/AggregationCommon.h>
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
#ifdef __SSE4_1__
|
2017-04-01 07:20:54 +00:00
|
|
|
#include <smmintrin.h>
|
2016-01-13 21:05:11 +00:00
|
|
|
#endif
|
2014-11-09 12:43:09 +00:00
|
|
|
|
|
|
|
|
2017-04-02 17:37:49 +00:00
|
|
|
/** Do this:
|
2014-11-09 12:43:09 +00:00
|
|
|
for file in MobilePhoneModel PageCharset Params URLDomain UTMSource Referer URL Title; do
|
2018-05-07 02:14:24 +00:00
|
|
|
for size in 30000 100000 300000 1000000 5000000; do
|
|
|
|
echo
|
|
|
|
BEST_METHOD=0
|
|
|
|
BEST_RESULT=0
|
|
|
|
for method in {1..11}; do
|
|
|
|
echo -ne $file $size $method '';
|
|
|
|
TOTAL_ELEMS=0
|
|
|
|
for i in {0..1000}; do
|
|
|
|
TOTAL_ELEMS=$(( $TOTAL_ELEMS + $size ))
|
|
|
|
if [[ $TOTAL_ELEMS -gt 25000000 ]]; then break; fi
|
|
|
|
./hash_map_string_3 $size $method < ${file}.bin 2>&1 |
|
|
|
|
grep HashMap | grep -oE '[0-9\.]+ elem';
|
|
|
|
done | awk -W interactive '{ if ($1 > x) { x = $1 }; printf(".") } END { print x }' | tee /tmp/hash_map_string_3_res;
|
|
|
|
CUR_RESULT=$(cat /tmp/hash_map_string_3_res | tr -d '.')
|
|
|
|
if [[ $CUR_RESULT -gt $BEST_RESULT ]]; then
|
|
|
|
BEST_METHOD=$method
|
|
|
|
BEST_RESULT=$CUR_RESULT
|
|
|
|
fi;
|
|
|
|
done;
|
|
|
|
echo Best: $BEST_METHOD - $BEST_RESULT
|
|
|
|
done;
|
2014-11-09 12:43:09 +00:00
|
|
|
done
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define DefineStringRef(STRUCT) \
|
|
|
|
\
|
|
|
|
struct STRUCT : public StringRef {}; \
|
|
|
|
\
|
|
|
|
namespace ZeroTraits \
|
|
|
|
{ \
|
2017-04-01 07:20:54 +00:00
|
|
|
template <> \
|
|
|
|
inline bool check<STRUCT>(STRUCT x) { return nullptr == x.data; } \
|
2014-11-09 12:43:09 +00:00
|
|
|
\
|
2017-04-01 07:20:54 +00:00
|
|
|
template <> \
|
|
|
|
inline void set<STRUCT>(STRUCT & x) { x.data = nullptr; } \
|
2018-08-26 01:13:02 +00:00
|
|
|
} \
|
2014-11-09 12:43:09 +00:00
|
|
|
\
|
|
|
|
template <> \
|
|
|
|
struct DefaultHash<STRUCT> \
|
|
|
|
{ \
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (STRUCT x) const \
|
|
|
|
{ \
|
2018-11-26 00:56:50 +00:00
|
|
|
return CityHash_v1_0_2::CityHash64(x.data, x.size); \
|
2017-04-01 07:20:54 +00:00
|
|
|
} \
|
2014-11-09 12:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DefineStringRef(StringRef_CompareMemcmp)
|
|
|
|
DefineStringRef(StringRef_CompareAlwaysTrue)
|
|
|
|
|
|
|
|
|
|
|
|
inline bool operator==(StringRef_CompareMemcmp lhs, StringRef_CompareMemcmp rhs)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (lhs.size != rhs.size)
|
|
|
|
return false;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (lhs.size == 0)
|
|
|
|
return true;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0 == memcmp(lhs.data, rhs.data, lhs.size);
|
2014-11-09 12:43:09 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
inline bool operator==(StringRef_CompareAlwaysTrue, StringRef_CompareAlwaysTrue)
|
2014-11-09 12:43:09 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2014-11-09 12:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct FastHash64
|
|
|
|
{
|
2018-06-03 16:51:31 +00:00
|
|
|
static inline uint64_t mix(uint64_t h)
|
|
|
|
{
|
|
|
|
h ^= h >> 23;
|
|
|
|
h *= 0x2127599bf4325c37ULL;
|
|
|
|
h ^= h >> 47;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
const char * buf = x.data;
|
|
|
|
size_t len = x.size;
|
|
|
|
|
|
|
|
const uint64_t m = 0x880355f21e6d1965ULL;
|
|
|
|
const uint64_t *pos = reinterpret_cast<const uint64_t *>(buf);
|
|
|
|
const uint64_t *end = pos + (len / 8);
|
|
|
|
const unsigned char *pos2;
|
|
|
|
uint64_t h = len * m;
|
|
|
|
uint64_t v;
|
|
|
|
|
2018-01-10 00:04:08 +00:00
|
|
|
while (pos != end)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
v = *pos++;
|
|
|
|
h ^= mix(v);
|
|
|
|
h *= m;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos2 = reinterpret_cast<const unsigned char*>(pos);
|
|
|
|
v = 0;
|
|
|
|
|
2018-01-10 00:04:08 +00:00
|
|
|
switch (len & 7)
|
|
|
|
{
|
|
|
|
case 7: v ^= static_cast<uint64_t>(pos2[6]) << 48; [[fallthrough]];
|
|
|
|
case 6: v ^= static_cast<uint64_t>(pos2[5]) << 40; [[fallthrough]];
|
|
|
|
case 5: v ^= static_cast<uint64_t>(pos2[4]) << 32; [[fallthrough]];
|
|
|
|
case 4: v ^= static_cast<uint64_t>(pos2[3]) << 24; [[fallthrough]];
|
|
|
|
case 3: v ^= static_cast<uint64_t>(pos2[2]) << 16; [[fallthrough]];
|
|
|
|
case 2: v ^= static_cast<uint64_t>(pos2[1]) << 8; [[fallthrough]];
|
|
|
|
case 1: v ^= static_cast<uint64_t>(pos2[0]);
|
|
|
|
h ^= mix(v);
|
|
|
|
h *= m;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mix(h);
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-21 21:59:27 +00:00
|
|
|
struct FNV1a
|
|
|
|
{
|
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
size_t res = 0xcbf29ce484222325ULL;
|
|
|
|
|
|
|
|
const char * pos = x.data;
|
|
|
|
const char * end = x.data + x.size;
|
|
|
|
|
|
|
|
for (; pos < end; ++pos)
|
|
|
|
{
|
|
|
|
res *= 1099511628211ULL;
|
|
|
|
res ^= *pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
#ifdef __SSE4_1__
|
2016-01-13 21:05:11 +00:00
|
|
|
|
2014-11-09 12:43:09 +00:00
|
|
|
struct CrapWow
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
const char * key = x.data;
|
|
|
|
size_t len = x.size;
|
|
|
|
size_t seed = 0;
|
|
|
|
|
|
|
|
const UInt64 m = 0x95b47aa3355ba1a1, n = 0x8a970be7488fda55;
|
|
|
|
UInt64 hash;
|
|
|
|
// 3 = m, 4 = n
|
|
|
|
// r12 = h, r13 = k, ecx = seed, r12 = key
|
|
|
|
asm(
|
|
|
|
"leaq (%%rcx,%4), %%r13\n"
|
|
|
|
"movq %%rdx, %%r14\n"
|
|
|
|
"movq %%rcx, %%r15\n"
|
|
|
|
"movq %%rcx, %%r12\n"
|
|
|
|
"addq %%rax, %%r13\n"
|
|
|
|
"andq $0xfffffffffffffff0, %%rcx\n"
|
|
|
|
"jz QW%=\n"
|
|
|
|
"addq %%rcx, %%r14\n\n"
|
|
|
|
"negq %%rcx\n"
|
|
|
|
"XW%=:\n"
|
|
|
|
"movq %4, %%rax\n"
|
|
|
|
"mulq (%%r14,%%rcx)\n"
|
|
|
|
"xorq %%rax, %%r12\n"
|
|
|
|
"xorq %%rdx, %%r13\n"
|
|
|
|
"movq %3, %%rax\n"
|
|
|
|
"mulq 8(%%r14,%%rcx)\n"
|
|
|
|
"xorq %%rdx, %%r12\n"
|
|
|
|
"xorq %%rax, %%r13\n"
|
|
|
|
"addq $16, %%rcx\n"
|
|
|
|
"jnz XW%=\n"
|
|
|
|
"QW%=:\n"
|
|
|
|
"movq %%r15, %%rcx\n"
|
|
|
|
"andq $8, %%r15\n"
|
|
|
|
"jz B%=\n"
|
|
|
|
"movq %4, %%rax\n"
|
|
|
|
"mulq (%%r14)\n"
|
|
|
|
"addq $8, %%r14\n"
|
|
|
|
"xorq %%rax, %%r12\n"
|
|
|
|
"xorq %%rdx, %%r13\n"
|
|
|
|
"B%=:\n"
|
|
|
|
"andq $7, %%rcx\n"
|
|
|
|
"jz F%=\n"
|
|
|
|
"movq $1, %%rdx\n"
|
|
|
|
"shlq $3, %%rcx\n"
|
|
|
|
"movq %3, %%rax\n"
|
|
|
|
"shlq %%cl, %%rdx\n"
|
|
|
|
"addq $-1, %%rdx\n"
|
|
|
|
"andq (%%r14), %%rdx\n"
|
|
|
|
"mulq %%rdx\n"
|
|
|
|
"xorq %%rdx, %%r12\n"
|
|
|
|
"xorq %%rax, %%r13\n"
|
|
|
|
"F%=:\n"
|
|
|
|
"leaq (%%r13,%4), %%rax\n"
|
|
|
|
"xorq %%r12, %%rax\n"
|
|
|
|
"mulq %4\n"
|
|
|
|
"xorq %%rdx, %%rax\n"
|
|
|
|
"xorq %%r12, %%rax\n"
|
|
|
|
"xorq %%r13, %%rax\n"
|
|
|
|
: "=a"(hash), "=c"(key), "=d"(key)
|
|
|
|
: "r"(m), "r"(n), "a"(seed), "c"(len), "d"(key)
|
|
|
|
: "%r12", "%r13", "%r14", "%r15", "cc"
|
|
|
|
);
|
|
|
|
return hash;
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
};
|
|
|
|
|
2016-01-13 21:05:11 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-09 12:43:09 +00:00
|
|
|
|
|
|
|
struct SimpleHash
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
const char * pos = x.data;
|
|
|
|
size_t size = x.size;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * end = pos + size;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t res = 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size < 8)
|
|
|
|
{
|
2019-01-04 12:10:00 +00:00
|
|
|
#ifdef __SSE4_1__
|
2017-04-01 07:20:54 +00:00
|
|
|
return hashLessThan8(x.data, x.size);
|
2017-01-25 19:17:13 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
while (pos + 8 < end)
|
|
|
|
{
|
|
|
|
uint64_t word = *reinterpret_cast<const uint64_t *>(pos);
|
|
|
|
res = intHash64(word ^ res);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
pos += 8;
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
uint64_t word = *reinterpret_cast<const uint64_t *>(end - 8);
|
|
|
|
res = intHash64(word ^ res);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VerySimpleHash
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
const char * pos = x.data;
|
|
|
|
size_t size = x.size;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * end = pos + size;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t res = 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size < 8)
|
|
|
|
{
|
2019-01-04 12:10:00 +00:00
|
|
|
#ifdef __SSE4_1__
|
2017-04-01 07:20:54 +00:00
|
|
|
return hashLessThan8(x.data, x.size);
|
2017-01-25 19:17:13 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
while (pos + 8 < end)
|
|
|
|
{
|
|
|
|
res ^= reinterpret_cast<const uint64_t *>(pos)[0];
|
|
|
|
res ^= res >> 33;
|
|
|
|
res *= 0xff51afd7ed558ccdULL;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
pos += 8;
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
res ^= *reinterpret_cast<const uint64_t *>(end - 8);
|
|
|
|
res ^= res >> 33;
|
|
|
|
res *= 0xc4ceb9fe1a85ec53ULL;
|
|
|
|
res ^= res >> 33;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-20 17:41:51 +00:00
|
|
|
struct FarmHash64
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
2018-06-19 18:09:09 +00:00
|
|
|
return NAMESPACE_FOR_HASH_FUNCTIONS::Hash64(x.data, x.size);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-07-20 17:41:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <void metrohash64(const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * out)>
|
2019-01-28 14:00:50 +00:00
|
|
|
struct SMetroHash64
|
2015-07-20 17:41:51 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
2018-01-10 00:04:08 +00:00
|
|
|
union
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
uint64_t u64;
|
|
|
|
std::uint8_t u8[sizeof(u64)];
|
|
|
|
};
|
2015-07-20 17:41:51 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
metrohash64(reinterpret_cast<const std::uint8_t *>(x.data), x.size, 0, u8);
|
2015-07-20 17:41:51 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return u64;
|
|
|
|
}
|
2015-07-20 17:41:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
#ifdef __SSE4_1__
|
2016-01-13 21:05:11 +00:00
|
|
|
|
2014-11-09 12:43:09 +00:00
|
|
|
/*struct CRC32Hash
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
const char * pos = x.data;
|
|
|
|
size_t size = x.size;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size < 8)
|
|
|
|
{
|
|
|
|
return hashLessThan8(x.data, x.size);
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * end = pos + size;
|
|
|
|
size_t res = -1ULL;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
uint64_t word = *reinterpret_cast<const uint64_t *>(pos);
|
|
|
|
res = _mm_crc32_u64(res, word);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
pos += 8;
|
|
|
|
} while (pos + 8 < end);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
uint64_t word = *reinterpret_cast<const uint64_t *>(end - 8);
|
|
|
|
res = _mm_crc32_u64(res, word);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
|
|
struct CRC32ILPHash
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t operator() (StringRef x) const
|
|
|
|
{
|
|
|
|
const char * pos = x.data;
|
|
|
|
size_t size = x.size;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (size < 16)
|
|
|
|
{
|
|
|
|
return hashLessThan16(x.data, x.size);
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * end = pos + size;
|
|
|
|
const char * end_16 = pos + size / 16 * 16;
|
|
|
|
size_t res0 = -1ULL;
|
|
|
|
size_t res1 = -1ULL;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
uint64_t word0 = reinterpret_cast<const uint64_t *>(pos)[0];
|
|
|
|
uint64_t word1 = reinterpret_cast<const uint64_t *>(pos)[1];
|
|
|
|
res0 = _mm_crc32_u64(res0, word0);
|
|
|
|
res1 = _mm_crc32_u64(res1, word1);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
pos += 16;
|
|
|
|
} while (pos < end_16);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
uint64_t word0 = *reinterpret_cast<const uint64_t *>(end - 8);
|
|
|
|
uint64_t word1 = *reinterpret_cast<const uint64_t *>(end - 16);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/* return HashLen16(Rotate(word0 - word1, 43) + Rotate(res0, 30) + res1,
|
|
|
|
word0 + Rotate(word1 ^ k3, 20) - res0 + size);*/
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
res0 = _mm_crc32_u64(res0, word0);
|
|
|
|
res1 = _mm_crc32_u64(res1, word1);
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return hashLen16(res0, res1);
|
|
|
|
}
|
2014-11-09 12:43:09 +00:00
|
|
|
};
|
|
|
|
|
2016-01-13 21:05:11 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2016-10-26 22:27:38 +00:00
|
|
|
using Value = uint64_t;
|
2014-11-09 12:43:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <typename Key, typename Hash>
|
|
|
|
void NO_INLINE bench(const std::vector<StringRef> & data, const char * name)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
Stopwatch watch;
|
|
|
|
|
|
|
|
using Map = HashMapWithSavedHash<Key, Value, Hash>;
|
|
|
|
|
|
|
|
Map map;
|
|
|
|
typename Map::iterator it;
|
|
|
|
bool inserted;
|
|
|
|
|
|
|
|
for (size_t i = 0, size = data.size(); i < size; ++i)
|
|
|
|
{
|
|
|
|
map.emplace(static_cast<const Key &>(data[i]), it, inserted);
|
|
|
|
if (inserted)
|
|
|
|
it->second = 0;
|
|
|
|
++it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "HashMap (" << name << "). Size: " << map.size()
|
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << data.size() / watch.elapsedSeconds() << " elem/sec.)"
|
2014-11-09 12:43:09 +00:00
|
|
|
#ifdef DBMS_HASH_MAP_COUNT_COLLISIONS
|
2017-04-01 07:20:54 +00:00
|
|
|
<< ", collisions: " << map.getCollisions()
|
2014-11-09 12:43:09 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
<< std::endl;
|
2014-11-09 12:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
2017-12-02 02:47:12 +00:00
|
|
|
if (argc < 3)
|
|
|
|
{
|
|
|
|
std::cerr << "Usage: program n m\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t n = atoi(argv[1]);
|
|
|
|
size_t m = atoi(argv[2]);
|
|
|
|
|
|
|
|
DB::Arena pool;
|
|
|
|
std::vector<StringRef> data(n);
|
|
|
|
|
|
|
|
std::cerr << "sizeof(Key) = " << sizeof(StringRef) << ", sizeof(Value) = " << sizeof(Value) << std::endl;
|
|
|
|
|
|
|
|
{
|
|
|
|
Stopwatch watch;
|
|
|
|
DB::ReadBufferFromFileDescriptor in1(STDIN_FILENO);
|
|
|
|
DB::CompressedReadBuffer in2(in1);
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
for (size_t i = 0; i < n && !in2.eof(); ++i)
|
|
|
|
{
|
|
|
|
DB::readStringBinary(tmp, in2);
|
|
|
|
data[i] = StringRef(pool.insert(tmp.data(), tmp.size()), tmp.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "Vector. Size: " << n
|
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << n / watch.elapsedSeconds() << " elem/sec.)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
2017-08-21 21:59:27 +00:00
|
|
|
if (!m || m == 1) bench<StringRef, StringRefHash64>(data, "StringRef_CityHash64");
|
|
|
|
if (!m || m == 2) bench<StringRef, FastHash64> (data, "StringRef_FastHash64");
|
|
|
|
if (!m || m == 3) bench<StringRef, SimpleHash> (data, "StringRef_SimpleHash");
|
2017-08-21 22:03:28 +00:00
|
|
|
if (!m || m == 4) bench<StringRef, FNV1a> (data, "StringRef_FNV1a");
|
2016-01-13 21:05:11 +00:00
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
#ifdef __SSE4_1__
|
2017-08-21 22:03:28 +00:00
|
|
|
if (!m || m == 5) bench<StringRef, CrapWow> (data, "StringRef_CrapWow");
|
|
|
|
if (!m || m == 6) bench<StringRef, CRC32Hash> (data, "StringRef_CRC32Hash");
|
|
|
|
if (!m || m == 7) bench<StringRef, CRC32ILPHash> (data, "StringRef_CRC32ILPHash");
|
2016-01-13 21:05:11 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-21 22:03:28 +00:00
|
|
|
if (!m || m == 8) bench<StringRef, VerySimpleHash> (data, "StringRef_VerySimpleHash");
|
|
|
|
if (!m || m == 9) bench<StringRef, FarmHash64> (data, "StringRef_FarmHash64");
|
2019-01-28 14:00:50 +00:00
|
|
|
if (!m || m == 10) bench<StringRef, SMetroHash64<metrohash64_1>>(data, "StringRef_MetroHash64_1");
|
|
|
|
if (!m || m == 11) bench<StringRef, SMetroHash64<metrohash64_2>>(data, "StringRef_MetroHash64_2");
|
2014-11-09 12:43:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0;
|
2014-11-09 12:43:09 +00:00
|
|
|
}
|