File indexing completed on 2026-11-29 10:55:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _Standard_HashUtils_HeaderFile
0015 #define _Standard_HashUtils_HeaderFile
0016
0017 #include <Standard_Macro.hxx>
0018
0019 #include <cstdint>
0020 #include <cstddef>
0021 #include <functional>
0022 #include <type_traits>
0023
0024 namespace opencascade
0025 {
0026
0027
0028
0029 namespace MurmurHash
0030 {
0031 uint32_t MurmurHash2A(const void* theKey, int theLen, uint32_t theSeed) noexcept;
0032 uint64_t MurmurHash64A(const void* theKey, int theLen, uint64_t theSeed) noexcept;
0033
0034 template <typename T1, typename T = size_t>
0035 typename std::enable_if<sizeof(T) == 8, uint64_t>::type hash_combine(
0036 const T1& theValue,
0037 const int theLen = sizeof(T1),
0038 const T theSeed = 0xA329F1D3A586ULL) noexcept
0039 {
0040 return MurmurHash::MurmurHash64A(&theValue, theLen, theSeed);
0041 }
0042
0043 template <typename T1, typename T = size_t>
0044 typename std::enable_if<sizeof(T) != 8, T>::type hash_combine(
0045 const T1& theValue,
0046 const int theLen = sizeof(T1),
0047 const T theSeed = 0xc70f6907U) noexcept
0048 {
0049 return static_cast<T>(MurmurHash::MurmurHash2A(&theValue, theLen, theSeed));
0050 }
0051
0052 template <typename T = size_t>
0053 constexpr T optimalSeed() noexcept
0054 {
0055 return sizeof(T) == 8 ? static_cast<T>(0xA329F1D3A586ULL) : static_cast<T>(0xc70f6907U);
0056 }
0057 };
0058
0059
0060
0061
0062
0063
0064
0065 namespace FNVHash
0066 {
0067 uint32_t FNVHash1A(const void* theKey, int theLen, uint32_t theSeed) noexcept;
0068 uint64_t FNVHash64A(const void* theKey, int theLen, uint64_t theSeed) noexcept;
0069
0070 template <typename T1, typename T = size_t>
0071 static typename std::enable_if<sizeof(T) == 8, uint64_t>::type hash_combine(
0072 const T1& theValue,
0073 const int theLen = sizeof(T1),
0074 const T theSeed = 14695981039346656037ULL) noexcept
0075 {
0076 return FNVHash::FNVHash64A(&theValue, theLen, theSeed);
0077 }
0078
0079 template <typename T1, typename T = size_t>
0080 static typename std::enable_if<sizeof(T) != 8, T>::type hash_combine(
0081 const T1& theValue,
0082 const int theLen = sizeof(T1),
0083 const T theSeed = 2166136261U) noexcept
0084 {
0085 return static_cast<T>(FNVHash::FNVHash1A(&theValue, theLen, theSeed));
0086 }
0087
0088 template <typename T = size_t>
0089 constexpr T optimalSeed() noexcept
0090 {
0091 return sizeof(T) == 8 ? static_cast<T>(14695981039346656037ULL) : static_cast<T>(2166136261U);
0092 }
0093 };
0094
0095 template <typename T1, typename T = size_t>
0096 T hash(const T1& theValue) noexcept
0097 {
0098 return opencascade::MurmurHash::hash_combine<T1, T>(theValue);
0099 }
0100
0101 template <typename T1, typename T = size_t>
0102 T hashBytes(const T1* theKey, int theLen) noexcept
0103 {
0104 return opencascade::MurmurHash::hash_combine<T1, T>(*theKey, theLen);
0105 }
0106
0107 template <typename T1, typename T = size_t>
0108 T hash_combine(const T1& theValue, const int theLen, const T theSeed) noexcept
0109 {
0110 return opencascade::MurmurHash::hash_combine<T1, T>(theValue, theLen, theSeed);
0111 }
0112 }
0113
0114 #include <Standard_HashUtils.lxx>
0115
0116 #endif