2 #include <ossia/detail/config.hpp>
5 #include <ankerl/unordered_dense.h>
11 #include <string_view>
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;
44 std::size_t 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;
52 std::size_t 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;
59 template<
typename T>
struct is_shared_ptr : std::false_type {};
60 template<
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
64 struct hash : ankerl::unordered_dense::hash<T> { };
67 requires std::is_pointer_v<T>
68 struct hash<T> : egur_hash { };
71 requires is_shared_ptr<T>::value
72 struct hash<T> : egur_hash { };
75 struct hash<std::string> : string_hash { };
77 struct hash<std::string_view> : string_hash { };
81 struct hash<const char*>;
89 using is_transparent = std::true_type;
90 bool operator()(
const std::string& s,
const std::string& s2)
const noexcept
94 bool operator()(std::string_view s,
const std::string& s2)
const noexcept
98 bool operator()(
const std::string& s, std::string_view s2)
const noexcept
102 bool operator()(std::string_view s, std::string_view s2)
const noexcept
107 template <std::
size_t N>
108 bool operator()(
const std::string& s,
const char (&s2)[N])
const noexcept
110 return operator()(s, std::string_view{s2, N-1});
113 template <std::
size_t N>
114 bool operator()(std::string_view s,
const char (&s2)[N])
const noexcept
116 return operator()(s, std::string_view{s2, N-1});
119 template <std::
size_t N>
120 bool operator()(
const char (&s)[N],
const std::string& s2)
const noexcept
122 return operator()(std::string_view{s, N-1}, s2);
125 template <std::
size_t N>
126 bool operator()(
const char (&s)[N], std::string_view s2)
const noexcept
128 return operator()(std::string_view{s, N-1}, s2);
135 using is_transparent = std::true_type;
136 template<
typename U,
typename V>
138 bool operator()(
const U* lhs,
const V* rhs)
const noexcept {
return lhs == rhs; }
140 template<
typename U,
typename V>
142 bool operator()(
const std::shared_ptr<U>& lhs,
const V* rhs)
const noexcept
144 return lhs.get() == rhs;
147 template<
typename U,
typename V>
149 bool operator()(
const U* lhs,
const std::shared_ptr<V>& rhs)
const noexcept
151 return lhs == rhs.get();
154 template<
typename U,
typename V>
157 operator()(
const std::shared_ptr<U>& lhs,
const std::shared_ptr<V>& rhs)
const noexcept
163 template <
typename T>
164 struct equal_to : std::equal_to<T> { };
167 struct equal_to<std::string> : string_equal { };
169 struct equal_to<std::string_view> : string_equal { };
171 template <
typename T>
172 requires std::is_pointer_v<T>
173 struct equal_to<T> : pointer_equal { };
175 template <
typename T>
176 requires is_shared_ptr<T>::value
177 struct equal_to<T> : pointer_equal { };
180 template <
typename T>
181 constexpr
inline void hash_combine(std::size_t& seed,
const T& k) noexcept
184 seed ^= hash<T>{}(k) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
187 template <
typename T>
188 constexpr
inline void hash_combine(std::size_t& seed,
const T* k) noexcept
191 seed ^= egur_hash{}(k) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
194 constexpr
inline void hash_combine(uint64_t& seed, uint8_t k) noexcept
196 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
198 constexpr
inline void hash_combine(uint64_t& seed, int8_t k) noexcept
200 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
202 constexpr
inline void hash_combine(uint64_t& seed, uint16_t k) noexcept
204 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
206 constexpr
inline void hash_combine(uint64_t& seed, int16_t k) noexcept
208 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
210 constexpr
inline void hash_combine(uint64_t& seed, uint32_t k) noexcept
212 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
214 constexpr
inline void hash_combine(uint64_t& seed, int32_t k) noexcept
216 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
218 constexpr
inline void hash_combine(uint64_t& seed, int64_t k) noexcept
220 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
223 constexpr
inline void hash_combine(uint32_t& seed, uint8_t k) noexcept
225 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
227 constexpr
inline void hash_combine(uint32_t& seed, int8_t k) noexcept
229 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
231 constexpr
inline void hash_combine(uint32_t& seed, uint16_t k) noexcept
233 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
235 constexpr
inline void hash_combine(uint32_t& seed, int16_t k) noexcept
237 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
239 constexpr
inline void hash_combine(uint32_t& seed, int32_t k) noexcept
241 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
243 constexpr
inline void hash_combine(uint32_t& seed, uint64_t k) noexcept
245 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
247 constexpr
inline void hash_combine(uint32_t& seed, int64_t k) noexcept
249 seed ^= k + 0x9e3779b9 + (seed << 6) + (seed >> 2);
252 constexpr
inline void hash_combine(uint32_t& h1, uint32_t k1) noexcept
254 constexpr
auto rotl32
255 = [](uint32_t x, int8_t r) noexcept {
return (x << r) | (x >> (32 - r)); };
257 constexpr uint32_t c1 = 0xcc9e2d51;
258 constexpr uint32_t c2 = 0x1b873593;
266 h1 = h1 * 5 + 0xe6546b64;
269 constexpr
inline void hash_combine(uint64_t& h, uint64_t k) noexcept
271 constexpr
auto m = UINT64_C(0xc6a4a7935bd1e995);
272 constexpr
int r = 47;