From 47df16f8965a3946570e48054c5bbd5b46a9ee54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Fri, 19 Jan 2024 14:28:18 +0100 Subject: [PATCH] Style is not happy with orphan headers --- src/Core/FieldHash.h | 147 ------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 src/Core/FieldHash.h diff --git a/src/Core/FieldHash.h b/src/Core/FieldHash.h deleted file mode 100644 index e0d1b997065..00000000000 --- a/src/Core/FieldHash.h +++ /dev/null @@ -1,147 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -namespace -{ -static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8); -using size_t_equivalent = std::conditional_t; - -inline size_t hash64(UInt64 x) -{ - return static_cast(intHash64(x)); -} - -inline size_t hash32(UInt32 x) -{ - /// It's ok to just treat it as 64bits - return static_cast(hash64(x)); -} - -inline size_t hash_size_t(size_t x) -{ - if constexpr (sizeof(size_t) == 4) - return hash32(std::bit_cast(x)); - else - return hash64(std::bit_cast(x)); -} - -inline size_t combine_hashes(size_t h1, size_t h2) -{ - return hash_size_t(h1) ^ h2; -} -} - - -namespace std -{ -/// Extends std::hash to support DB::Field so it can be used in std::unordered_map and similar structures -template <> -struct hash -{ - size_t operator()(const DB::Field & field) const noexcept - { - using Which = DB::Field::Types::Which; - size_t type_hash = ::hash32(field.getType()); - switch (field.getType()) - { - case Which::Null: - return 0; - case Which::Bool: - [[fallthrough]]; - case Which::UInt64: - return ::combine_hashes(type_hash, ::hash64(field.get())); - case Which::IPv6: - [[fallthrough]]; - case Which::UUID: - [[fallthrough]]; - case Which::UInt128: { - UInt128 n = field.get(); - size_t h1 = ::hash64(n.items[0]); - size_t h2 = ::hash64(n.items[1]); - return ::combine_hashes(type_hash, ::combine_hashes(h1, h2)); - } - case Which::UInt256: { - UInt256 n = field.get(); - size_t h1 = ::hash64(n.items[0]); - size_t h2 = ::hash64(n.items[1]); - size_t h3 = ::hash64(n.items[2]); - size_t h4 = ::hash64(n.items[3]); - return ::combine_hashes(::combine_hashes(type_hash, ::combine_hashes(h1, h2)), ::combine_hashes(h3, h4)); - } - case Which::Int64: { - UInt64 n = std::bit_cast(&field.get()); - return ::combine_hashes(type_hash, n); - } - case Which::Int128: { - UInt128 n = std::bit_cast(field.get()); - size_t h1 = ::hash64(n.items[0]); - size_t h2 = ::hash64(n.items[1]); - return ::combine_hashes(type_hash, ::combine_hashes(h1, h2)); - } - case Which::Int256: { - UInt256 n = std::bit_cast(field.get()); - size_t h1 = ::hash64(n.items[0]); - size_t h2 = ::hash64(n.items[1]); - size_t h3 = ::hash64(n.items[2]); - size_t h4 = ::hash64(n.items[3]); - return ::combine_hashes(::combine_hashes(type_hash, ::combine_hashes(h1, h2)), ::combine_hashes(h3, h4)); - } - case Which::IPv4: { - UInt32 n = field.get(); - return ::combine_hashes(type_hash, ::hash32(n)); - } - case Which::Float64: - return ::combine_hashes(type_hash, std::hash{}(field.get())); - case Which::String: - return ::combine_hashes(type_hash, std::hash{}(field.get())); - case Which::Array: { - auto const & array = field.get(); - size_t res = type_hash; - for (const auto & e : array) - res = ::combine_hashes(res, std::hash{}(e)); - return res; - } - case Which::Tuple: { - auto const & tuple = field.get(); - size_t res = type_hash; - for (const auto & e : tuple) - res = ::combine_hashes(res, std::hash{}(e)); - return res; - } - case Which::Map: { - auto const & map = field.get(); - size_t res = type_hash; - for (const auto & e : map) - res = ::combine_hashes(res, std::hash{}(e)); - return res; - } - case Which::Object: { - auto const & object = field.get(); - size_t res = type_hash; - for (const auto & e : object) - res = ::combine_hashes(res, ::combine_hashes(std::hash{}(e.first), std::hash{}(e.second))); - return res; - } - case Which::Decimal32: - return ::combine_hashes(type_hash, std::hash{}(field.get())); - case Which::Decimal64: - return ::combine_hashes(type_hash, std::hash{}(field.get())); - case Which::Decimal128: - return ::combine_hashes(type_hash, std::hash{}(field.get())); - case Which::Decimal256: - return ::combine_hashes(type_hash, std::hash{}(field.get())); - case Which::AggregateFunctionState: { - auto const & agg = field.get(); - return ::combine_hashes(type_hash, ::combine_hashes(std::hash{}(agg.name), std::hash{}(agg.data))); - } - case Which::CustomType: - return ::combine_hashes(type_hash, std::hash{}(field.get().toString())); - } - } -}; -}