summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-04-10 12:27:08 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-10 12:39:44 +0200
commitae6b09f4dcea65e4ba0e9bb70d7c0322bab958a6 (patch)
tree4daeabc71930387cceca67fc9c1c932a119e7255 /AK
parent69ca27d3d7868ca2e19153b636455e2e8fbfada1 (diff)
downloadserenity-ae6b09f4dcea65e4ba0e9bb70d7c0322bab958a6.zip
AK: Add hash traits for floating-point primitives
This allows us to use float and double as hash keys.
Diffstat (limited to 'AK')
-rw-r--r--AK/Traits.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/AK/Traits.h b/AK/Traits.h
index fc67ce4b9d..539174b7d0 100644
--- a/AK/Traits.h
+++ b/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); }