Add gccHash function

This commit is contained in:
sundy-li 2019-01-08 13:12:52 +08:00
parent 082e6e0c42
commit e6c02a2356
6 changed files with 36 additions and 0 deletions

View File

@ -28,6 +28,7 @@ void registerFunctionsHashing(FunctionFactory & factory)
factory.registerFunction<FunctionMurmurHash3_32>(); factory.registerFunction<FunctionMurmurHash3_32>();
factory.registerFunction<FunctionMurmurHash3_64>(); factory.registerFunction<FunctionMurmurHash3_64>();
factory.registerFunction<FunctionMurmurHash3_128>(); factory.registerFunction<FunctionMurmurHash3_128>();
factory.registerFunction<FunctionGccHash>();
#if USE_XXHASH #if USE_XXHASH
factory.registerFunction<FunctionXxHash32>(); factory.registerFunction<FunctionXxHash32>();

View File

@ -257,6 +257,25 @@ struct MurmurHash2Impl64
static constexpr bool use_int_hash_for_pods = false; static constexpr bool use_int_hash_for_pods = false;
}; };
/// To be compatible with gcc: https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/libstdc%2B%2B-v3/include/bits/functional_hash.h#L191
struct GccHashImpl
{
static constexpr auto name = "gccHash";
using ReturnType = UInt64;
static UInt64 apply(const char * data, const size_t size)
{
return MurmurHash64A(data, size, 0xc70f6907UL);
}
static UInt64 combineHashes(UInt64 h1, UInt64 h2)
{
return IntHash64Impl::apply(h1) ^ h2;
}
static constexpr bool use_int_hash_for_pods = false;
};
struct MurmurHash3Impl32 struct MurmurHash3Impl32
{ {
static constexpr auto name = "murmurHash3_32"; static constexpr auto name = "murmurHash3_32";
@ -1070,6 +1089,7 @@ using FunctionFarmHash64 = FunctionAnyHash<ImplFarmHash64>;
using FunctionMetroHash64 = FunctionAnyHash<ImplMetroHash64>; using FunctionMetroHash64 = FunctionAnyHash<ImplMetroHash64>;
using FunctionMurmurHash2_32 = FunctionAnyHash<MurmurHash2Impl32>; using FunctionMurmurHash2_32 = FunctionAnyHash<MurmurHash2Impl32>;
using FunctionMurmurHash2_64 = FunctionAnyHash<MurmurHash2Impl64>; using FunctionMurmurHash2_64 = FunctionAnyHash<MurmurHash2Impl64>;
using FunctionGccHash = FunctionAnyHash<GccHashImpl>;
using FunctionMurmurHash3_32 = FunctionAnyHash<MurmurHash3Impl32>; using FunctionMurmurHash3_32 = FunctionAnyHash<MurmurHash3Impl32>;
using FunctionMurmurHash3_64 = FunctionAnyHash<MurmurHash3Impl64>; using FunctionMurmurHash3_64 = FunctionAnyHash<MurmurHash3Impl64>;
using FunctionMurmurHash3_128 = FunctionStringHashFixedString<MurmurHash3Impl128>; using FunctionMurmurHash3_128 = FunctionStringHashFixedString<MurmurHash3Impl128>;

View File

@ -22,5 +22,8 @@
11303473983767132390 11303473983767132390
956517343494314387 956517343494314387
956517343494314387 956517343494314387
9631199822919835226
4334672815104069193
4334672815104069193
6145F501578671E2877DBA2BE487AF7E 6145F501578671E2877DBA2BE487AF7E
16FE7483905CCE7A85670E43E4678877 16FE7483905CCE7A85670E43E4678877

View File

@ -28,5 +28,10 @@ SELECT murmurHash3_64('foo');
SELECT murmurHash3_64('\x01'); SELECT murmurHash3_64('\x01');
SELECT murmurHash3_64(1); SELECT murmurHash3_64(1);
SELECT gccHash('foo');
SELECT gccHash('\x01');
SELECT gccHash(1);
SELECT hex(murmurHash3_128('foo')); SELECT hex(murmurHash3_128('foo'));
SELECT hex(murmurHash3_128('\x01')); SELECT hex(murmurHash3_128('\x01'));

View File

@ -13,3 +13,6 @@
8163029322371165472 8163029322371165472
8788309436660676487 8788309436660676487
236561483980029756 236561483980029756
12384823029245979431
4507350192761038840
1188926775431157506

View File

@ -17,3 +17,7 @@ SELECT murmurHash2_64(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2))));
SELECT murmurHash3_64(1, 2, 3); SELECT murmurHash3_64(1, 2, 3);
SELECT murmurHash3_64(1, 3, 2); SELECT murmurHash3_64(1, 3, 2);
SELECT murmurHash3_64(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2)))); SELECT murmurHash3_64(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2))));
SELECT gccHash(1, 2, 3);
SELECT gccHash(1, 3, 2);
SELECT gccHash(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2))));