2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-16 02:01:18 +01:00
|
|
|
#include <AK/Forward.h>
|
2020-02-10 11:55:34 +01:00
|
|
|
#include <AK/HashFunctions.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
2019-06-29 19:14:03 +02:00
|
|
|
struct GenericTraits {
|
2019-08-14 11:47:38 +02:00
|
|
|
using PeekType = T;
|
2021-05-08 12:11:37 +03:00
|
|
|
using ConstPeekType = T;
|
2019-08-07 15:05:10 +02:00
|
|
|
static constexpr bool is_trivial() { return false; }
|
2020-12-23 11:35:01 -07:00
|
|
|
static constexpr bool equals(const T& a, const T& b) { return a == b; }
|
2019-06-29 19:14:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct Traits : public GenericTraits<T> {
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|
2021-07-12 22:38:03 +04:30
|
|
|
template<typename T>
|
|
|
|
requires(IsIntegral<T>) struct Traits<T> : public GenericTraits<T> {
|
2020-01-03 19:56:33 +13:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
2021-07-12 22:38:03 +04:30
|
|
|
static constexpr unsigned hash(T value)
|
|
|
|
{
|
|
|
|
if constexpr (sizeof(T) < 8)
|
|
|
|
return int_hash(value);
|
|
|
|
else
|
|
|
|
return u64_hash(value);
|
|
|
|
}
|
2020-01-03 19:56:33 +13:00
|
|
|
};
|
|
|
|
|
2018-10-11 16:52:30 +02:00
|
|
|
template<typename T>
|
2019-08-14 11:47:38 +02:00
|
|
|
struct Traits<T*> : public GenericTraits<T*> {
|
2018-10-27 09:33:24 +02:00
|
|
|
static unsigned hash(const T* p)
|
|
|
|
{
|
2019-06-22 21:21:57 +02:00
|
|
|
return int_hash((unsigned)(__PTRDIFF_TYPE__)p);
|
2018-10-27 09:33:24 +02:00
|
|
|
}
|
2019-08-07 11:53:21 +02:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
2019-06-29 19:14:03 +02:00
|
|
|
static bool equals(const T* a, const T* b) { return a == b; }
|
2018-10-11 16:52:30 +02:00
|
|
|
};
|
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
}
|
2020-02-16 02:01:18 +01:00
|
|
|
|
|
|
|
using AK::GenericTraits;
|
|
|
|
using AK::Traits;
|