1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:27:35 +00:00

AK: Add hash traits for floating-point primitives

This allows us to use float and double as hash keys.
This commit is contained in:
Andreas Kling 2022-04-10 12:27:08 +02:00
parent 69ca27d3d7
commit ae6b09f4dc
2 changed files with 38 additions and 0 deletions

View file

@ -40,6 +40,20 @@ requires(IsIntegral<T>) struct Traits<T> : public GenericTraits<T> {
}
};
#ifndef KERNEL
template<typename T>
requires(IsFloatingPoint<T>) struct Traits<T> : public GenericTraits<T> {
static constexpr bool is_trivial() { return true; }
static constexpr unsigned hash(T value)
{
if constexpr (sizeof(T) < 8)
return int_hash(bit_cast<u32>(value));
else
return u64_hash(bit_cast<u64>(value));
}
};
#endif
template<typename T>
requires(IsPointer<T> && !Detail::IsPointerOfType<char, T>) struct Traits<T> : public GenericTraits<T> {
static unsigned hash(T p) { return ptr_hash((FlatPtr)p); }