CColor hash

This commit is contained in:
Jack Andersen 2019-05-07 17:49:27 -10:00
parent 92733a3bb7
commit 6c13d089fe
2 changed files with 18 additions and 0 deletions

View File

@ -331,3 +331,16 @@ inline CColor operator*(float lhs, const CColor& rhs) { return CColor(simd<float
inline CColor operator/(float lhs, const CColor& rhs) { return CColor(simd<float>(lhs) / rhs.mSimd).Clamp(); }
} // namespace zeus
namespace std {
template <>
struct hash<zeus::CColor> {
size_t operator()(const zeus::CColor& color) const noexcept {
size_t ret = std::hash<float>()(color.r());
zeus::hash_combine_impl(ret, std::hash<float>()(color.g()));
zeus::hash_combine_impl(ret, std::hash<float>()(color.b()));
zeus::hash_combine_impl(ret, std::hash<float>()(color.a()));
return ret;
}
};
}

View File

@ -14,6 +14,11 @@ using simd = athena::simd<T>;
using simd_floats = athena::simd_floats;
using simd_doubles = athena::simd_doubles;
#endif
template <typename SizeT>
constexpr void hash_combine_impl(SizeT& seed, SizeT value) {
seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
} // namespace zeus
constexpr int rotr(int x, int n) { return ((x >> n) | (x << (32 - n))); }