#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_HASH_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_HASH_TRAITS_H_
#include <string.h>
#include <concepts>
#include <limits>
#include <memory>
#include <type_traits>
#include <utility>
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
#include "third_party/blink/renderer/platform/wtf/hash_table_deleted_value_type.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
namespace WTF {
template <typename T>
struct HashTraits;
class String;
namespace internal {
template <typename T>
struct GenericHashTraitsBase { … };
template <typename T, auto empty_value, auto deleted_value>
struct IntOrEnumHashTraits : internal::GenericHashTraitsBase<T> { … };
}
template <typename T, T empty_value = 0, T deleted_value = static_cast<T>(-1)>
struct IntHashTraits
: internal::IntOrEnumHashTraits<T, empty_value, deleted_value> { … };
template <typename T>
struct EnumHashTraits : internal::IntOrEnumHashTraits<T, -128, -127> { … };
template <typename T>
struct GenericHashTraits : internal::GenericHashTraitsBase<T> { … };
GenericHashTraits<T>;
GenericHashTraits<T>;
GenericHashTraits<T>;
template <typename T>
struct IntWithZeroKeyHashTraits
: IntHashTraits<T,
std::numeric_limits<T>::max(),
std::numeric_limits<T>::max() - 1> { … };
struct AlreadyHashedTraits : GenericHashTraits<unsigned> { … };
struct AlreadyHashedWithZeroKeyTraits : IntWithZeroKeyHashTraits<unsigned> { … };
GenericHashTraits<P *>;
GenericHashTraits<scoped_refptr<P>>;
GenericHashTraits<std::unique_ptr<T>>;
template <typename T>
struct HashTraits : GenericHashTraits<T> { … };
template <typename T>
struct SimpleClassHashTraits : GenericHashTraits<T> { … };
template <>
struct HashTraits<String>;
namespace internal {
template <typename Traits, typename Enabled = void>
struct HashTraitsEmptyValueChecker { … };
HashTraitsEmptyValueChecker<Traits, std::enable_if_t<std::is_same_v<decltype(Traits::IsEmptyValue(std::declval<typename Traits::TraitType>())), bool>>>;
template <typename Traits, typename Enabled = void>
struct HashTraitsDeletedValueHelper { … };
HashTraitsDeletedValueHelper<Traits, std::enable_if_t<std::is_same_v<decltype(Traits::IsDeletedValue(std::declval<typename Traits::TraitType>())), bool>>>;
}
template <typename Traits, typename T>
inline bool IsHashTraitsEmptyValue(const T& value) { … }
template <typename Traits, typename T>
inline bool IsHashTraitsDeletedValue(const T& value) { … }
template <typename Traits, typename T>
inline void ConstructHashTraitsDeletedValue(T& slot) { … }
template <typename Traits, typename T>
inline bool IsHashTraitsEmptyOrDeletedValue(const T& value) { … }
template <typename T,
auto field,
typename FieldTraits = HashTraits<
std::remove_reference_t<decltype(std::declval<T>().*field)>>>
struct OneFieldHashTraits : GenericHashTraits<T> {
using TraitType = T;
static unsigned GetHash(const T& p) { … }
static bool Equal(const T& a, const T& b) { … }
static constexpr bool kSafeToCompareToEmptyOrDeleted =
FieldTraits::kSafeToCompareToEmptyOrDeleted;
static constexpr bool kEmptyValueIsZero = FieldTraits::kEmptyValueIsZero;
static T EmptyValue() { … }
static bool IsEmptyValue(const T& value) { … }
static void ConstructDeletedValue(T& slot) { … }
static bool IsDeletedValue(const T& value) { … }
static constexpr unsigned kMinimumTableSize = FieldTraits::kMinimumTableSize;
template <typename U = void>
struct NeedsToForbidGCOnMove {
static const bool value =
FieldTraits::template NeedsToForbidGCOnMove<>::value;
};
};
template <
typename T,
auto first_field,
auto second_field,
typename FirstTraits = HashTraits<
std::remove_reference_t<decltype(std::declval<T>().*first_field)>>,
typename SecondTraits = HashTraits<
std::remove_reference_t<decltype(std::declval<T>().*second_field)>>>
struct TwoFieldsHashTraits : OneFieldHashTraits<T, first_field, FirstTraits> {
using TraitType = T;
static unsigned GetHash(const T& p) { … }
static bool Equal(const T& a, const T& b) { … }
static constexpr bool kSafeToCompareToEmptyOrDeleted =
FirstTraits::kSafeToCompareToEmptyOrDeleted &&
SecondTraits::kSafeToCompareToEmptyOrDeleted;
static constexpr bool kEmptyValueIsZero =
FirstTraits::kEmptyValueIsZero && SecondTraits::kEmptyValueIsZero;
static T EmptyValue() { … }
static bool IsEmptyValue(const T& value) { … }
template <typename U = void>
struct NeedsToForbidGCOnMove {
static const bool value =
FirstTraits::template NeedsToForbidGCOnMove<>::value ||
SecondTraits::template NeedsToForbidGCOnMove<>::value;
};
};
template <typename FirstTraitsArg,
typename SecondTraitsArg,
typename P = std::pair<typename FirstTraitsArg::TraitType,
typename SecondTraitsArg::TraitType>>
struct PairHashTraits : TwoFieldsHashTraits<P,
&P::first,
&P::second,
FirstTraitsArg,
SecondTraitsArg> {
using TraitType = P;
using FirstTraits = FirstTraitsArg;
using SecondTraits = SecondTraitsArg;
};
HashTraits<std::pair<First, Second>>;
template <typename T>
unsigned GetHash(const T& key) { … }
}
AlreadyHashedTraits;
AlreadyHashedWithZeroKeyTraits;
EnumHashTraits;
GenericHashTraits;
HashTraits;
IntHashTraits;
IntWithZeroKeyHashTraits;
OneFieldHashTraits;
PairHashTraits;
SimpleClassHashTraits;
TwoFieldsHashTraits;
#endif