From d5fea1b2352912d727afc50e2c91504033988e0c Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 3 Jan 2020 19:56:33 +1300 Subject: [PATCH] AK: Add a u64 Trait type This allows u64s to be used in HashMaps. --- AK/HashFunctions.h | 7 +++++++ AK/Traits.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/AK/HashFunctions.h b/AK/HashFunctions.h index ee09fb0cf3d..cbbd97942d1 100644 --- a/AK/HashFunctions.h +++ b/AK/HashFunctions.h @@ -17,3 +17,10 @@ inline unsigned pair_int_hash(u32 key1, u32 key2) { return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413))); } + +inline unsigned u64_hash(u64 key) +{ + u32 first = key & 0xFFFFFFFF; + u32 last = key >> 32; + return pair_int_hash(first, last); +} diff --git a/AK/Traits.h b/AK/Traits.h index f268e669403..c071d5f418e 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -37,6 +37,13 @@ struct Traits : public GenericTraits { static void dump(u16 u) { kprintf("%u", u); } }; +template<> +struct Traits : public GenericTraits { + static constexpr bool is_trivial() { return true; } + static unsigned hash(u64 u) { return u64_hash(u); } + static void dump(u64 u) { kprintf("%u", (unsigned)u); } // FIXME: Implement unsigned long long printf specifier, instead of this sadness :( +}; + template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; }