From 64989afa52075fe8a4eb9eebfb60c724938bc942 Mon Sep 17 00:00:00 2001 From: olevino999 Date: Thu, 21 Apr 2022 02:26:37 +0300 Subject: [PATCH] wyhash --- .gitmodules | 3 +++ contrib/CMakeLists.txt | 1 + contrib/wyhash | 1 + contrib/wyhash-cmake/CMakeLists.txt | 7 +++++++ src/Functions/CMakeLists.txt | 1 + src/Functions/FunctionsHashing.cpp | 2 ++ src/Functions/FunctionsHashing.h | 26 ++++++++++++++++++++++++++ 7 files changed, 41 insertions(+) create mode 160000 contrib/wyhash create mode 100644 contrib/wyhash-cmake/CMakeLists.txt diff --git a/.gitmodules b/.gitmodules index 6c9e66f9cbc..5fd9e9721f6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -262,3 +262,6 @@ [submodule "contrib/minizip-ng"] path = contrib/minizip-ng url = https://github.com/zlib-ng/minizip-ng +[submodule "contrib/wyhash"] + path = contrib/wyhash + url = https://github.com/wangyi-fudan/wyhash.git diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 1f03c0fd341..94003f3b3ee 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -94,6 +94,7 @@ if (ENABLE_FUZZING) add_contrib (libprotobuf-mutator-cmake libprotobuf-mutator) endif() +add_contrib (wyhash-cmake wyhash) add_contrib (cityhash102) add_contrib (libfarmhash) add_contrib (icu-cmake icu) diff --git a/contrib/wyhash b/contrib/wyhash new file mode 160000 index 00000000000..991aa3dab62 --- /dev/null +++ b/contrib/wyhash @@ -0,0 +1 @@ +Subproject commit 991aa3dab624e50b066f7a02ccc9f6935cc740ec diff --git a/contrib/wyhash-cmake/CMakeLists.txt b/contrib/wyhash-cmake/CMakeLists.txt new file mode 100644 index 00000000000..4e1be5ce6f5 --- /dev/null +++ b/contrib/wyhash-cmake/CMakeLists.txt @@ -0,0 +1,7 @@ +set (LIBRARY_DIR ${ClickHouse_SOURCE_DIR}/contrib/wyhash) + +add_library (wyhash "${LIBRARY_DIR}/wyhash.h") + +target_include_directories(wyhash PUBLIC ${LIBRARY_DIR}) + +add_library (ch_contrib::wyhash ALIAS wyhash) diff --git a/src/Functions/CMakeLists.txt b/src/Functions/CMakeLists.txt index debe7fac8a5..a84e5a3f526 100644 --- a/src/Functions/CMakeLists.txt +++ b/src/Functions/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(clickhouse_functions ${clickhouse_functions_sources}) target_link_libraries(clickhouse_functions PUBLIC + ch_contrib::wyhash ch_contrib::cityhash ch_contrib::farmhash clickhouse_dictionaries diff --git a/src/Functions/FunctionsHashing.cpp b/src/Functions/FunctionsHashing.cpp index cbafd4bcec2..901234e5443 100644 --- a/src/Functions/FunctionsHashing.cpp +++ b/src/Functions/FunctionsHashing.cpp @@ -39,5 +39,7 @@ void registerFunctionsHashing(FunctionFactory & factory) factory.registerFunction(); factory.registerFunction(); + + factory.registerFunction(); } } diff --git a/src/Functions/FunctionsHashing.h b/src/Functions/FunctionsHashing.h index b78ecb5c72a..cd323e4a285 100644 --- a/src/Functions/FunctionsHashing.h +++ b/src/Functions/FunctionsHashing.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "config_functions.h" #include "config_core.h" @@ -1369,6 +1370,29 @@ private: } }; +struct ImplWyHash64 +{ + static constexpr auto name = "wyHash64"; + using ReturnType = UInt64; + + static UInt64 apply(const char * s, const size_t len) + { + return uint64_t hash=wyhash(s, len, 0, _wyp); + } + static UInt64 combineHashes(UInt64 h1, UInt64 h2) + { + union + { + UInt64 u64[2]; + char chars[8]; + }; + u64[0] = h1; + u64[2] = h2; + return apply(chars, 8); + } + + static constexpr bool use_int_hash_for_pods = false; +}; struct NameIntHash32 { static constexpr auto name = "intHash32"; }; struct NameIntHash64 { static constexpr auto name = "intHash64"; }; @@ -1406,4 +1430,6 @@ using FunctionHiveHash = FunctionAnyHash; using FunctionXxHash32 = FunctionAnyHash; using FunctionXxHash64 = FunctionAnyHash; +using FunctionWyHash64 = FunctionAnyHash; + }