2#include <ossia/detail/config.hpp>
5#include <ankerl/unordered_dense.h>
18 using is_transparent = std::true_type;
19 using is_avalanching = std::true_type;
20 std::size_t operator()(
const std::string& s)
const noexcept
22 return ankerl::unordered_dense::hash<std::string>{}(s);
25 std::size_t operator()(std::string_view s)
const noexcept
27 return ankerl::unordered_dense::hash<std::string_view>{}(s);
30 template <std::
size_t N>
31 std::size_t operator()(
const char (&s)[N])
const noexcept
33 return ankerl::unordered_dense::hash<std::string_view>{}(std::string_view{s, N - 1});
40 using is_transparent = std::true_type;
43 OSSIA_INLINE OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK std::size_t
44 operator()(
const T* val)
const noexcept
46 static const constexpr std::size_t shift = constexpr_log2(1 +
sizeof(T));
47 return (
size_t)(val) >> shift;
51 OSSIA_INLINE OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK std::size_t
52 operator()(
const std::shared_ptr<T>& val)
const noexcept
54 static const constexpr std::size_t shift = constexpr_log2(1 +
sizeof(T));
55 return (
size_t)(val.get()) >> shift;
59template <std::
size_t ApproximateObjectSizeof>
60struct unknown_pointer_hash
62 using is_transparent = std::true_type;
65 OSSIA_INLINE OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK std::size_t
66 operator()(
const T* val)
const noexcept
68 static const constexpr std::size_t shift
69 = constexpr_log2(1 + ApproximateObjectSizeof);
70 return (
size_t)(val) >> shift;
74 OSSIA_INLINE OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK std::size_t
75 operator()(
const std::shared_ptr<T>& val)
const noexcept
77 static const constexpr std::size_t shift
78 = constexpr_log2(1 + ApproximateObjectSizeof);
79 return (
size_t)(val.get()) >> shift;
83template<
typename T>
struct is_shared_ptr : std::false_type {};
84template<
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
88struct hash : ankerl::unordered_dense::hash<T> { };
91requires std::is_pointer_v<T>
92struct hash<T> : egur_hash { };
95requires is_shared_ptr<T>::value
96struct hash<T> : egur_hash { };
99struct hash<std::string> : string_hash { };
101struct hash<std::string_view> : string_hash { };
105struct hash<const char*>;
113 using is_transparent = std::true_type;
114 bool operator()(
const std::string& s,
const std::string& s2)
const noexcept
118 bool operator()(std::string_view s,
const std::string& s2)
const noexcept
122 bool operator()(
const std::string& s, std::string_view s2)
const noexcept
126 bool operator()(std::string_view s, std::string_view s2)
const noexcept
131 template <std::
size_t N>
132 bool operator()(
const std::string& s,
const char (&s2)[N])
const noexcept
134 return operator()(s, std::string_view{s2, N-1});
137 template <std::
size_t N>
138 bool operator()(std::string_view s,
const char (&s2)[N])
const noexcept
140 return operator()(s, std::string_view{s2, N-1});
143 template <std::
size_t N>
144 bool operator()(
const char (&s)[N],
const std::string& s2)
const noexcept
146 return operator()(std::string_view{s, N-1}, s2);
149 template <std::
size_t N>
150 bool operator()(
const char (&s)[N], std::string_view s2)
const noexcept
152 return operator()(std::string_view{s, N-1}, s2);
159 using is_transparent = std::true_type;
160 template<
typename U,
typename V>
162 bool operator()(
const U* lhs,
const V* rhs)
const noexcept {
return lhs == rhs; }
164 template<
typename U,
typename V>
166 bool operator()(
const std::shared_ptr<U>& lhs,
const V* rhs)
const noexcept
168 return lhs.get() == rhs;
171 template<
typename U,
typename V>
173 bool operator()(
const U* lhs,
const std::shared_ptr<V>& rhs)
const noexcept
175 return lhs == rhs.get();
178 template<
typename U,
typename V>
181 operator()(
const std::shared_ptr<U>& lhs,
const std::shared_ptr<V>& rhs)
const noexcept
188struct equal_to : std::equal_to<T> { };
191struct equal_to<std::string> : string_equal { };
193struct equal_to<std::string_view> : string_equal { };
196requires std::is_pointer_v<T>
197struct equal_to<T> : pointer_equal { };
200requires is_shared_ptr<T>::value
201struct equal_to<T> : pointer_equal { };
205OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
constexpr inline void
206hash_combine(std::size_t& seed,
const T& k)
noexcept
209 seed ^= hash<T>{}(k) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
213OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
constexpr inline void
214hash_combine(std::size_t& seed,
const T* k)
noexcept
217 seed ^= egur_hash{}(k) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
220OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
221constexpr inline void hash_combine(uint64_t& seed, uint8_t k)
noexcept
223 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
226OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
227constexpr inline void hash_combine(uint64_t& seed, int8_t k)
noexcept
229 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
232OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
233constexpr inline void hash_combine(uint64_t& seed, uint16_t k)
noexcept
235 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
238OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
239constexpr inline void hash_combine(uint64_t& seed, int16_t k)
noexcept
241 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
244OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
245constexpr inline void hash_combine(uint64_t& seed, uint32_t k)
noexcept
247 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
250OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
251constexpr inline void hash_combine(uint64_t& seed, int32_t k)
noexcept
253 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
256OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
257constexpr inline void hash_combine(uint64_t& seed, int64_t k)
noexcept
259 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
262OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
263constexpr inline void hash_combine(uint32_t& seed, uint8_t k)
noexcept
265 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
268OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
269constexpr inline void hash_combine(uint32_t& seed, int8_t k)
noexcept
271 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
274OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
275constexpr inline void hash_combine(uint32_t& seed, uint16_t k)
noexcept
277 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
280OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
281constexpr inline void hash_combine(uint32_t& seed, int16_t k)
noexcept
283 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
286OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
287constexpr inline void hash_combine(uint32_t& seed, int32_t k)
noexcept
289 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
292OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
293constexpr inline void hash_combine(uint32_t& seed, uint64_t k)
noexcept
295 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
298OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
299constexpr inline void hash_combine(uint32_t& seed, int64_t k)
noexcept
301 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
304OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
305constexpr inline void hash_combine(uint32_t& h1, uint32_t k1)
noexcept
307 constexpr auto rotl32
308 = [](uint32_t x, int8_t r)
noexcept {
return (x << r) | (x >> (32 - r)); };
310 constexpr uint32_t c1 = 0xcc9e2d51;
311 constexpr uint32_t c2 = 0x1b873593;
319 h1 = h1 * 5 + 0xe6546b64;
322OSSIA_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
323constexpr inline void hash_combine(uint64_t& h, uint64_t k)
noexcept
325 constexpr auto m = UINT64_C(0xc6a4a7935bd1e995);
326 constexpr int r = 47;