2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2018-10-27 04:33:24 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-01-31 11:10:45 -03:00
|
|
|
#include <AK/Types.h>
|
2018-10-27 04:33:24 -03:00
|
|
|
|
2026-02-20 11:39:06 -03:00
|
|
|
// MurmurHash3 32-bit finalizer (fmix32).
|
|
|
|
|
constexpr unsigned u32_hash(u32 key)
|
2018-10-27 04:33:24 -03:00
|
|
|
{
|
2026-02-20 11:39:06 -03:00
|
|
|
key ^= key >> 16;
|
|
|
|
|
key *= 0x85ebca6bU;
|
|
|
|
|
key ^= key >> 13;
|
|
|
|
|
key *= 0xc2b2ae35U;
|
|
|
|
|
key ^= key >> 16;
|
2018-10-27 04:33:24 -03:00
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 11:39:06 -03:00
|
|
|
// MurmurHash3 64-bit finalizer (fmix64).
|
|
|
|
|
constexpr unsigned u64_hash(u64 key)
|
2018-10-27 04:33:24 -03:00
|
|
|
{
|
2026-02-20 11:39:06 -03:00
|
|
|
key ^= key >> 33;
|
|
|
|
|
key *= 0xff51afd7ed558ccdULL;
|
|
|
|
|
key ^= key >> 33;
|
|
|
|
|
key *= 0xc4ceb9fe1a85ec53ULL;
|
|
|
|
|
key ^= key >> 33;
|
|
|
|
|
return static_cast<unsigned>(key);
|
2018-10-27 04:33:24 -03:00
|
|
|
}
|
2020-01-03 03:56:33 -03:00
|
|
|
|
2026-02-20 11:39:06 -03:00
|
|
|
constexpr unsigned pair_int_hash(u32 key1, u32 key2)
|
2020-01-03 03:56:33 -03:00
|
|
|
{
|
2026-02-20 11:39:06 -03:00
|
|
|
return u64_hash((static_cast<u64>(key1) << 32) | key2);
|
2020-01-03 03:56:33 -03:00
|
|
|
}
|
2020-02-17 16:19:28 -03:00
|
|
|
|
2020-10-21 10:39:54 -03:00
|
|
|
constexpr unsigned ptr_hash(FlatPtr ptr)
|
2020-02-17 16:19:28 -03:00
|
|
|
{
|
2020-09-18 04:49:51 -03:00
|
|
|
if constexpr (sizeof(ptr) == 8)
|
2020-10-21 10:39:54 -03:00
|
|
|
return u64_hash(ptr);
|
2020-02-17 16:19:28 -03:00
|
|
|
else
|
2026-02-20 11:39:06 -03:00
|
|
|
return u32_hash(ptr);
|
2020-02-17 16:19:28 -03:00
|
|
|
}
|
2020-02-25 11:37:07 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
inline unsigned ptr_hash(void const* ptr)
|
2020-02-25 11:37:07 -03:00
|
|
|
{
|
2020-10-21 10:39:54 -03:00
|
|
|
return ptr_hash(FlatPtr(ptr));
|
2020-02-25 11:37:07 -03:00
|
|
|
}
|