14#ifndef WPIUTIL_WPI_DENSEMAPINFO_H
15#define WPIUTIL_WPI_DENSEMAPINFO_H
26namespace densemap::detail {
29inline uint64_t
mix(uint64_t x) {
30 x *= 0xbf58476d1ce4e5b9u;
40 uint64_t x = (uint64_t)a << 32 | (uint64_t)b;
51template<
typename T,
typename Enable =
void>
70 static constexpr uintptr_t Log2MaxAlign = 12;
73 uintptr_t Val =
static_cast<uintptr_t
>(-1);
75 return reinterpret_cast<T*
>(Val);
79 uintptr_t Val =
static_cast<uintptr_t
>(-2);
81 return reinterpret_cast<T*
>(Val);
85 return (
unsigned((uintptr_t)PtrVal) >> 4) ^
86 (unsigned((uintptr_t)PtrVal) >> 9);
89 static bool isEqual(
const T *LHS,
const T *RHS) {
return LHS == RHS; }
96 static unsigned getHashValue(
const char& Val) {
return Val * 37U; }
98 static bool isEqual(
const char &LHS,
const char &RHS) {
107 static unsigned getHashValue(
const unsigned char &Val) {
return Val * 37U; }
109 static bool isEqual(
const unsigned char &LHS,
const unsigned char &RHS) {
118 static unsigned getHashValue(
const unsigned short &Val) {
return Val * 37U; }
120 static bool isEqual(
const unsigned short &LHS,
const unsigned short &RHS) {
129 static unsigned getHashValue(
const unsigned& Val) {
return Val * 37U; }
131 static bool isEqual(
const unsigned& LHS,
const unsigned& RHS) {
142 if constexpr (
sizeof(Val) == 4)
148 static bool isEqual(
const unsigned long& LHS,
const unsigned long& RHS) {
162 static bool isEqual(
const unsigned long long& LHS,
163 const unsigned long long& RHS) {
173 static bool isEqual(
const short &LHS,
const short &RHS) {
return LHS == RHS; }
180 static unsigned getHashValue(
const int& Val) {
return (
unsigned)(Val * 37U); }
182 static bool isEqual(
const int& LHS,
const int& RHS) {
190 return (1UL << (
sizeof(
long) * 8 - 1)) - 1UL;
196 return (
unsigned)(Val * 37UL);
199 static bool isEqual(
const long& LHS,
const long& RHS) {
206 static inline long long getEmptyKey() {
return 0x7fffffffffffffffLL; }
210 return (
unsigned)(Val * 37ULL);
214 const long long& RHS) {
220template<
typename T,
typename U>
227 return std::make_pair(FirstInfo::getEmptyKey(),
228 SecondInfo::getEmptyKey());
232 return std::make_pair(FirstInfo::getTombstoneKey(),
233 SecondInfo::getTombstoneKey());
238 SecondInfo::getHashValue(PairVal.second));
246 SecondInfo::getHashValue(Second));
250 return FirstInfo::isEqual(LHS.first, RHS.first) &&
251 SecondInfo::isEqual(LHS.second, RHS.second);
267 template <
unsigned I>
269 using EltType = std::tuple_element_t<I, Tuple>;
270 std::integral_constant<bool, I + 1 ==
sizeof...(Ts)> atEnd;
273 getHashValueImpl<I + 1>(values, atEnd));
276 template <
unsigned I>
282 std::integral_constant<bool, 0 ==
sizeof...(Ts)> atEnd;
283 return getHashValueImpl<0>(values, atEnd);
286 template <
unsigned I>
288 using EltType = std::tuple_element_t<I, Tuple>;
289 std::integral_constant<bool, I + 1 ==
sizeof...(Ts)> atEnd;
291 isEqualImpl<I + 1>(lhs, rhs, atEnd);
294 template <
unsigned I>
300 std::integral_constant<bool, 0 ==
sizeof...(Ts)> atEnd;
301 return isEqualImpl<0>(lhs, rhs, atEnd);
306template <
typename Enum>
311 static Enum
getEmptyKey() {
return static_cast<Enum
>(Info::getEmptyKey()); }
314 return static_cast<Enum
>(Info::getTombstoneKey());
321 static bool isEqual(
const Enum &LHS,
const Enum &RHS) {
return LHS == RHS; }
detail namespace with internal helper functions
Definition input_adapters.h:32
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
uint64_t mix(uint64_t x)
Definition DenseMapInfo.h:29
unsigned combineHashValue(unsigned a, unsigned b)
Simplistic combination of 32-bit hash values into 32-bit hash values.
Definition DenseMapInfo.h:39
Foonathan namespace.
Definition ntcore_cpp.h:26
static bool isEqual(const Enum &LHS, const Enum &RHS)
Definition DenseMapInfo.h:321
std::underlying_type_t< Enum > UnderlyingType
Definition DenseMapInfo.h:308
static Enum getEmptyKey()
Definition DenseMapInfo.h:311
static unsigned getHashValue(const Enum &Val)
Definition DenseMapInfo.h:317
static Enum getTombstoneKey()
Definition DenseMapInfo.h:313
static T * getTombstoneKey()
Definition DenseMapInfo.h:78
static T * getEmptyKey()
Definition DenseMapInfo.h:72
static unsigned getHashValue(const T *PtrVal)
Definition DenseMapInfo.h:84
static bool isEqual(const T *LHS, const T *RHS)
Definition DenseMapInfo.h:89
static char getTombstoneKey()
Definition DenseMapInfo.h:95
static char getEmptyKey()
Definition DenseMapInfo.h:94
static bool isEqual(const char &LHS, const char &RHS)
Definition DenseMapInfo.h:98
static unsigned getHashValue(const char &Val)
Definition DenseMapInfo.h:96
static unsigned getHashValue(const int &Val)
Definition DenseMapInfo.h:180
static int getEmptyKey()
Definition DenseMapInfo.h:178
static bool isEqual(const int &LHS, const int &RHS)
Definition DenseMapInfo.h:182
static int getTombstoneKey()
Definition DenseMapInfo.h:179
static unsigned getHashValue(const long &Val)
Definition DenseMapInfo.h:195
static long getEmptyKey()
Definition DenseMapInfo.h:189
static long getTombstoneKey()
Definition DenseMapInfo.h:193
static bool isEqual(const long &LHS, const long &RHS)
Definition DenseMapInfo.h:199
static long long getTombstoneKey()
Definition DenseMapInfo.h:207
static bool isEqual(const long long &LHS, const long long &RHS)
Definition DenseMapInfo.h:213
static unsigned getHashValue(const long long &Val)
Definition DenseMapInfo.h:209
static long long getEmptyKey()
Definition DenseMapInfo.h:206
static short getEmptyKey()
Definition DenseMapInfo.h:170
static unsigned getHashValue(const short &Val)
Definition DenseMapInfo.h:172
static short getTombstoneKey()
Definition DenseMapInfo.h:171
static bool isEqual(const short &LHS, const short &RHS)
Definition DenseMapInfo.h:173
static Pair getTombstoneKey()
Definition DenseMapInfo.h:231
static bool isEqual(const Pair &LHS, const Pair &RHS)
Definition DenseMapInfo.h:249
static Pair getEmptyKey()
Definition DenseMapInfo.h:226
static unsigned getHashValue(const Pair &PairVal)
Definition DenseMapInfo.h:236
static unsigned getHashValuePiecewise(const T &First, const U &Second)
Definition DenseMapInfo.h:244
std::pair< T, U > Pair
Definition DenseMapInfo.h:222
static bool isEqualImpl(const Tuple &, const Tuple &, std::true_type)
Definition DenseMapInfo.h:295
std::tuple< Ts... > Tuple
Definition DenseMapInfo.h:257
static Tuple getEmptyKey()
Definition DenseMapInfo.h:259
static unsigned getHashValueImpl(const Tuple &values, std::false_type)
Definition DenseMapInfo.h:268
static unsigned getHashValueImpl(const Tuple &, std::true_type)
Definition DenseMapInfo.h:277
static unsigned getHashValue(const std::tuple< Ts... > &values)
Definition DenseMapInfo.h:281
static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs, std::false_type)
Definition DenseMapInfo.h:287
static bool isEqual(const Tuple &lhs, const Tuple &rhs)
Definition DenseMapInfo.h:299
static Tuple getTombstoneKey()
Definition DenseMapInfo.h:263
static unsigned getEmptyKey()
Definition DenseMapInfo.h:127
static unsigned getHashValue(const unsigned &Val)
Definition DenseMapInfo.h:129
static unsigned getTombstoneKey()
Definition DenseMapInfo.h:128
static bool isEqual(const unsigned &LHS, const unsigned &RHS)
Definition DenseMapInfo.h:131
static bool isEqual(const unsigned char &LHS, const unsigned char &RHS)
Definition DenseMapInfo.h:109
static unsigned char getEmptyKey()
Definition DenseMapInfo.h:105
static unsigned char getTombstoneKey()
Definition DenseMapInfo.h:106
static unsigned getHashValue(const unsigned char &Val)
Definition DenseMapInfo.h:107
static unsigned long getEmptyKey()
Definition DenseMapInfo.h:138
static bool isEqual(const unsigned long &LHS, const unsigned long &RHS)
Definition DenseMapInfo.h:148
static unsigned getHashValue(const unsigned long &Val)
Definition DenseMapInfo.h:141
static unsigned long getTombstoneKey()
Definition DenseMapInfo.h:139
static unsigned long long getTombstoneKey()
Definition DenseMapInfo.h:156
static unsigned long long getEmptyKey()
Definition DenseMapInfo.h:155
static unsigned getHashValue(const unsigned long long &Val)
Definition DenseMapInfo.h:158
static bool isEqual(const unsigned long long &LHS, const unsigned long long &RHS)
Definition DenseMapInfo.h:162
static unsigned short getEmptyKey()
Definition DenseMapInfo.h:116
static unsigned getHashValue(const unsigned short &Val)
Definition DenseMapInfo.h:118
static unsigned short getTombstoneKey()
Definition DenseMapInfo.h:117
static bool isEqual(const unsigned short &LHS, const unsigned short &RHS)
Definition DenseMapInfo.h:120
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition Hashing.h:65
typename std::enable_if< B, T >::type enable_if_t
Definition base.h:297