// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once #include "td/utils/common.h" #include #include namespace td { template bool is_hash_table_key_empty(const KeyT &key) { return key == KeyT(); } inline uint32 randomize_hash(uint32 h) { h ^= h >> 16; h *= 0x85ebca6b; h ^= h >> 13; h *= 0xc2b2ae35; h ^= h >> 16; return h; } template struct Hash { uint32 operator()(const Type &value) const; }; template struct Hash { uint32 operator()(Type *pointer) const { return Hash()(reinterpret_cast(pointer)); } }; template <> inline uint32 Hash::operator()(const char &value) const { return randomize_hash(static_cast(value)); } template <> inline uint32 Hash::operator()(const int32 &value) const { return randomize_hash(static_cast(value)); } template <> inline uint32 Hash::operator()(const uint32 &value) const { return randomize_hash(value); } template <> inline uint32 Hash::operator()(const int64 &value) const { return randomize_hash(static_cast(value + (value >> 32))); } template <> inline uint32 Hash::operator()(const uint64 &value) const { return randomize_hash(static_cast(value + (value >> 32))); } template <> inline uint32 Hash::operator()(const string &value) const { return static_cast(std::hash()(value)); } inline uint32 combine_hashes(uint32 first_hash, uint32 second_hash) { return first_hash * 2023654985u + second_hash; } } // namespace td