14 #ifndef WPIUTIL_WPI_DENSEMAPINFO_H
15 #define WPIUTIL_WPI_DENSEMAPINFO_H
17 #include "wpi/ArrayRef.h"
18 #include "wpi/Hashing.h"
19 #include "wpi/StringRef.h"
20 #include "wpi/PointerLikeTypeTraits.h"
39 static inline T* getEmptyKey() {
40 uintptr_t Val =
static_cast<uintptr_t
>(-1);
41 Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
42 return reinterpret_cast<T*
>(Val);
45 static inline T* getTombstoneKey() {
46 uintptr_t Val =
static_cast<uintptr_t
>(-2);
47 Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
48 return reinterpret_cast<T*
>(Val);
51 static unsigned getHashValue(
const T *PtrVal) {
52 return (
unsigned((uintptr_t)PtrVal) >> 4) ^
53 (unsigned((uintptr_t)PtrVal) >> 9);
56 static bool isEqual(
const T *LHS,
const T *RHS) {
return LHS == RHS; }
61 static inline char getEmptyKey() {
return ~0; }
62 static inline char getTombstoneKey() {
return ~0 - 1; }
63 static unsigned getHashValue(
const char& Val) {
return Val * 37U; }
65 static bool isEqual(
const char &LHS,
const char &RHS) {
72 static inline unsigned short getEmptyKey() {
return 0xFFFF; }
73 static inline unsigned short getTombstoneKey() {
return 0xFFFF - 1; }
74 static unsigned getHashValue(
const unsigned short &Val) {
return Val * 37U; }
76 static bool isEqual(
const unsigned short &LHS,
const unsigned short &RHS) {
83 static inline unsigned getEmptyKey() {
return ~0U; }
84 static inline unsigned getTombstoneKey() {
return ~0U - 1; }
85 static unsigned getHashValue(
const unsigned& Val) {
return Val * 37U; }
87 static bool isEqual(
const unsigned& LHS,
const unsigned& RHS) {
94 static inline unsigned long getEmptyKey() {
return ~0UL; }
95 static inline unsigned long getTombstoneKey() {
return ~0UL - 1L; }
97 static unsigned getHashValue(
const unsigned long& Val) {
98 return (
unsigned)(Val * 37UL);
101 static bool isEqual(
const unsigned long& LHS,
const unsigned long& RHS) {
108 static inline unsigned long long getEmptyKey() {
return ~0ULL; }
109 static inline unsigned long long getTombstoneKey() {
return ~0ULL - 1ULL; }
111 static unsigned getHashValue(
const unsigned long long& Val) {
112 return (
unsigned)(Val * 37ULL);
115 static bool isEqual(
const unsigned long long& LHS,
116 const unsigned long long& RHS) {
123 static inline short getEmptyKey() {
return 0x7FFF; }
124 static inline short getTombstoneKey() {
return -0x7FFF - 1; }
125 static unsigned getHashValue(
const short &Val) {
return Val * 37U; }
126 static bool isEqual(
const short &LHS,
const short &RHS) {
return LHS == RHS; }
131 static inline int getEmptyKey() {
return 0x7fffffff; }
132 static inline int getTombstoneKey() {
return -0x7fffffff - 1; }
133 static unsigned getHashValue(
const int& Val) {
return (
unsigned)(Val * 37U); }
135 static bool isEqual(
const int& LHS,
const int& RHS) {
142 static inline long getEmptyKey() {
143 return (1UL << (
sizeof(
long) * 8 - 1)) - 1UL;
146 static inline long getTombstoneKey() {
return getEmptyKey() - 1L; }
148 static unsigned getHashValue(
const long& Val) {
149 return (
unsigned)(Val * 37UL);
152 static bool isEqual(
const long& LHS,
const long& RHS) {
159 static inline long long getEmptyKey() {
return 0x7fffffffffffffffLL; }
160 static inline long long getTombstoneKey() {
return -0x7fffffffffffffffLL-1; }
162 static unsigned getHashValue(
const long long& Val) {
163 return (
unsigned)(Val * 37ULL);
166 static bool isEqual(
const long long& LHS,
167 const long long& RHS) {
173 template<
typename T,
typename U>
175 using Pair = std::pair<T, U>;
179 static inline Pair getEmptyKey() {
180 return std::make_pair(FirstInfo::getEmptyKey(),
181 SecondInfo::getEmptyKey());
184 static inline Pair getTombstoneKey() {
185 return std::make_pair(FirstInfo::getTombstoneKey(),
186 SecondInfo::getTombstoneKey());
189 static unsigned getHashValue(
const Pair& PairVal) {
190 uint64_t key = (uint64_t)FirstInfo::getHashValue(PairVal.first) << 32
191 | (uint64_t)SecondInfo::getHashValue(PairVal.second);
200 return (
unsigned)key;
203 static bool isEqual(
const Pair &LHS,
const Pair &RHS) {
204 return FirstInfo::isEqual(LHS.first, RHS.first) &&
205 SecondInfo::isEqual(LHS.second, RHS.second);
212 return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(0)),
216 static inline StringRef getTombstoneKey() {
217 return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(1)),
221 static unsigned getHashValue(
StringRef Val) {
222 assert(Val.
data() != getEmptyKey().data() &&
"Cannot hash the empty key!");
223 assert(Val.
data() != getTombstoneKey().data() &&
224 "Cannot hash the tombstone key!");
225 return (
unsigned)(hash_value(Val));
229 if (RHS.
data() == getEmptyKey().data())
230 return LHS.
data() == getEmptyKey().data();
231 if (RHS.
data() == getTombstoneKey().data())
232 return LHS.
data() == getTombstoneKey().data();
240 return ArrayRef<T>(
reinterpret_cast<const T *
>(~static_cast<uintptr_t>(0)),
245 return ArrayRef<T>(
reinterpret_cast<const T *
>(~static_cast<uintptr_t>(1)),
250 assert(Val.data() != getEmptyKey().data() &&
"Cannot hash the empty key!");
251 assert(Val.data() != getTombstoneKey().data() &&
252 "Cannot hash the tombstone key!");
253 return (
unsigned)(hash_value(Val));
257 if (RHS.data() == getEmptyKey().data())
258 return LHS.data() == getEmptyKey().data();
259 if (RHS.data() == getTombstoneKey().data())
260 return LHS.data() == getTombstoneKey().data();
267 #endif // LLVM_ADT_DENSEMAPINFO_H
Definition: SmallVector.h:946
Definition: DenseMapInfo.h:29
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const noexcept
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49