LLVM: include/llvm/ADT/CachedHashString.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef LLVM_ADT_CACHEDHASHSTRING_H
21#define LLVM_ADT_CACHEDHASHSTRING_H
22
25
26namespace llvm {
27
28
30 const char *P;
33
34public:
35
38
40 : P(S.data()), Size(S.size()), Hash(Hash) {
41 assert(S.size() <= std::numeric_limits<uint32_t>::max());
42 }
43
45 const char *data() const { return P; }
48};
49
64 return LHS.hash() == RHS.hash() &&
66 }
67};
68
69
70
71
72class CachedHashString {
74
75 char *P;
78
80 static char *getTombstoneKeyPtr() {
82 }
83
84 bool isEmptyOrTombstone() const {
85 return P == getEmptyKeyPtr() || P == getTombstoneKeyPtr();
86 }
87
88 struct ConstructEmptyOrTombstoneTy {};
89
90 CachedHashString(ConstructEmptyOrTombstoneTy, char *EmptyOrTombstonePtr)
91 : P(EmptyOrTombstonePtr), Size(0), Hash(0) {
92 assert(isEmptyOrTombstone());
93 }
94
95
96
97public:
99
100
103
108
109
110
112 : Size(Other.Size), Hash(Other.Hash) {
113 if (Other.isEmptyOrTombstone()) {
114 P = Other.P;
115 } else {
116 P = new char[Size];
117 memcpy(P, Other.P, Size);
118 }
119 }
120
125
128 Other.P = getEmptyKeyPtr();
129 }
130
132 if (!isEmptyOrTombstone())
133 delete[] P;
134 }
135
139
144
145 friend void swap(CachedHashString &LHS, CachedHashString &RHS) {
150 }
151};
152
155 return CachedHashString(CachedHashString::ConstructEmptyOrTombstoneTy(),
156 CachedHashString::getEmptyKeyPtr());
157 }
159 return CachedHashString(CachedHashString::ConstructEmptyOrTombstoneTy(),
160 CachedHashString::getTombstoneKeyPtr());
161 }
165 return S.hash();
166 }
169 if (LHS.hash() != RHS.hash())
170 return false;
171 if (LHS.P == CachedHashString::getEmptyKeyPtr())
172 return RHS.P == CachedHashString::getEmptyKeyPtr();
173 if (LHS.P == CachedHashString::getTombstoneKeyPtr())
174 return RHS.P == CachedHashString::getTombstoneKeyPtr();
175
176
177
178 return LHS.val() == RHS.val();
179 }
180};
181
182}
183
184#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines DenseMapInfo traits for DenseMap.
A container which contains a StringRef plus a precomputed hash.
Definition CachedHashString.h:29
uint32_t size() const
Definition CachedHashString.h:46
const char * data() const
Definition CachedHashString.h:45
CachedHashStringRef(StringRef S, uint32_t Hash)
Definition CachedHashString.h:39
CachedHashStringRef(StringRef S)
Definition CachedHashString.h:36
uint32_t hash() const
Definition CachedHashString.h:47
StringRef val() const
Definition CachedHashString.h:44
A container which contains a string, which it owns, plus a precomputed hash.
Definition CachedHashString.h:72
uint32_t hash() const
Definition CachedHashString.h:138
CachedHashString & operator=(CachedHashString Other)
Definition CachedHashString.h:121
CachedHashString(const char *S)
Definition CachedHashString.h:98
CachedHashString(StringRef S, uint32_t Hash)
Definition CachedHashString.h:104
friend void swap(CachedHashString &LHS, CachedHashString &RHS)
Definition CachedHashString.h:145
CachedHashString(StringRef S)
Definition CachedHashString.h:101
CachedHashString(const CachedHashString &Other)
Definition CachedHashString.h:111
uint32_t size() const
Definition CachedHashString.h:137
CachedHashString(CachedHashString &&Other) noexcept
Definition CachedHashString.h:126
StringRef val() const
Definition CachedHashString.h:136
~CachedHashString()
Definition CachedHashString.h:131
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
This is an optimization pass for GlobalISel generic memory operations.
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static unsigned getHashValue(const CachedHashStringRef &S)
Definition CachedHashString.h:57
static CachedHashStringRef getEmptyKey()
Definition CachedHashString.h:51
static CachedHashStringRef getTombstoneKey()
Definition CachedHashString.h:54
static unsigned getHashValue(const CachedHashString &S)
Definition CachedHashString.h:162
static CachedHashString getEmptyKey()
Definition CachedHashString.h:154
static CachedHashString getTombstoneKey()
Definition CachedHashString.h:158
static bool isEqual(const CachedHashString &LHS, const CachedHashString &RHS)
Definition CachedHashString.h:167
An information struct used to provide DenseMap with the various necessary components for a given valu...