mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:47: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:
parent
69ca27d3d7
commit
ae6b09f4dc
2 changed files with 38 additions and 0 deletions
14
AK/Traits.h
14
AK/Traits.h
|
@ -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); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue