File indexing completed on 2025-01-18 10:04:58
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);
0032 uint64_t MurmurHash64A(const void* theKey, int theLen, uint64_t theSeed);
0033
0034 template <typename T1, typename T = size_t>
0035 typename std::enable_if<sizeof(T) == 8, uint64_t>::type
0036 hash_combine(const T1& theValue, const int theLen = sizeof(T1), const T theSeed = 0xA329F1D3A586ULL)
0037 {
0038 return MurmurHash::MurmurHash64A(&theValue, theLen, theSeed);
0039 }
0040
0041 template <typename T1, typename T = size_t>
0042 typename std::enable_if<sizeof(T) != 8, T>::type
0043 hash_combine(const T1& theValue, const int theLen = sizeof(T1), const T theSeed = 0xc70f6907U)
0044 {
0045 return static_cast<T>(MurmurHash::MurmurHash2A(&theValue, theLen, theSeed));
0046 }
0047
0048 template <typename T = size_t>
0049 constexpr T optimalSeed()
0050 {
0051 return sizeof(T) == 8 ? static_cast<T>(0xA329F1D3A586ULL) : static_cast<T>(0xc70f6907U);
0052 }
0053 };
0054
0055
0056
0057
0058
0059
0060
0061 namespace FNVHash
0062 {
0063 uint32_t FNVHash1A(const void* theKey, int theLen, uint32_t theSeed);
0064 uint64_t FNVHash64A(const void* theKey, int theLen, uint64_t theSeed);
0065
0066 template <typename T1, typename T = size_t>
0067 static typename std::enable_if<sizeof(T) == 8, uint64_t>::type
0068 hash_combine(const T1& theValue, const int theLen = sizeof(T1), const T theSeed = 14695981039346656037ULL)
0069 {
0070 return FNVHash::FNVHash64A(&theValue, theLen, theSeed);
0071 }
0072
0073 template <typename T1, typename T = size_t>
0074 static typename std::enable_if<sizeof(T) != 8, T>::type
0075 hash_combine(const T1& theValue, const int theLen = sizeof(T1), const T theSeed = 2166136261U)
0076 {
0077 return static_cast<T>(FNVHash::FNVHash1A(&theValue, theLen, theSeed));
0078 }
0079
0080 template <typename T = size_t>
0081 constexpr T optimalSeed()
0082 {
0083 return sizeof(T) == 8 ? static_cast<T>(14695981039346656037ULL) : static_cast<T>(2166136261U);
0084 }
0085 };
0086
0087 template <typename T1, typename T = size_t>
0088 T hash(const T1 theValue) noexcept
0089 {
0090 return opencascade::MurmurHash::hash_combine<T1, T>(theValue);
0091 }
0092
0093 template <typename T1, typename T = size_t>
0094 T hashBytes(const T1* theKey, int theLen)
0095 {
0096 return opencascade::MurmurHash::hash_combine<T1, T>(*theKey, theLen);
0097 }
0098
0099 template <typename T1, typename T = size_t>
0100 T hash_combine(const T1 theValue, const int theLen, const T theSeed)
0101 {
0102 return opencascade::MurmurHash::hash_combine<T1, T>(theValue, theLen, theSeed);
0103 }
0104 }
0105
0106 #include <Standard_HashUtils.lxx>
0107
0108 #endif