10 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H 11 #define LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H 27 class BinaryStreamReader;
28 class BinaryStreamWriter;
35 template <
typename ValueT,
typename TraitsT>
class HashTable;
37 template <
typename ValueT,
typename TraitsT>
40 std::forward_iterator_tag,
41 std::pair<uint32_t, ValueT>> {
46 : Map(&Map), Index(Index), IsEnd(IsEnd) {}
70 return (Map == R.Map) && (Index == R.Index);
72 const std::pair<uint32_t, ValueT> &
operator*()
const {
77 while (Index < Map->Buckets.size()) {
88 bool isEnd()
const {
return IsEnd; }
89 uint32_t index()
const {
return Index; }
104 template <
typename ValueT,
typename TraitsT = PdbHashTraits<ValueT>>
114 using BucketList = std::vector<std::pair<uint32_t, ValueT>>;
121 Buckets.resize(Capacity);
128 if (H->Capacity == 0)
130 "Invalid Hash Table Capacity");
131 if (H->Size > maxLoad(H->Capacity))
132 return make_error<RawError>(raw_error_code::corrupt_file,
133 "Invalid Hash Table Size");
135 Buckets.resize(H->Capacity);
139 if (Present.count() != H->Size)
140 return make_error<RawError>(raw_error_code::corrupt_file,
141 "Present bit vector does not match size!");
145 if (Present.intersects(
Deleted))
146 return make_error<RawError>(raw_error_code::corrupt_file,
147 "Present bit vector interesects deleted!");
155 Buckets[
P].second = *Value;
164 constexpr
int BitsPerWord = 8 *
sizeof(
uint32_t);
166 int NumBitsP = Present.find_last() + 1;
167 int NumBitsD =
Deleted.find_last() + 1;
175 Size += NumWordsP *
sizeof(
uint32_t);
180 Size += NumWordsD *
sizeof(
uint32_t);
191 H.Capacity = capacity();
201 for (
const auto &Entry : *
this) {
226 uint32_t H = Traits.hashLookupKey(K) % capacity();
231 if (Traits.storageKeyToLookupKey(Buckets[I].first) == K)
244 I = (I + 1) % capacity();
251 return iterator(*
this, *FirstUnused,
true);
257 return set_as_internal(K, std::move(V),
None);
260 template <
typename Key>
ValueT get(
const Key &K)
const {
261 auto Iter = find_as(K);
263 return (*Iter).second;
278 template <
typename Key>
280 auto Entry = find_as(K);
281 if (Entry !=
end()) {
282 assert(isPresent(Entry.index()));
283 assert(Traits.storageKeyToLookupKey(Buckets[Entry.index()].first) == K);
285 Buckets[Entry.index()].second = V;
289 auto &
B = Buckets[Entry.index()];
290 assert(!isPresent(Entry.index()));
292 B.first = InternalKey ? *InternalKey : Traits.lookupKeyToStorageKey(K);
294 Present.
set(Entry.index());
295 Deleted.
reset(Entry.index());
307 uint32_t MaxLoad = maxLoad(capacity());
308 if (S < maxLoad(capacity()))
310 assert(capacity() != UINT32_MAX &&
"Can't grow Hash table!");
312 uint32_t NewCapacity = (capacity() <= INT32_MAX) ? MaxLoad * 2 : UINT32_MAX;
318 for (
auto I : Present) {
319 auto LookupKey = Traits.storageKeyToLookupKey(Buckets[
I].
first);
320 NewMap.set_as_internal(LookupKey, Buckets[
I].
second, Buckets[
I].first);
326 assert(capacity() == NewCapacity);
335 #endif // LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Error load(BinaryStreamReader &Stream)
uint32_t lookupKeyToStorageKey(uint32_t N)
const_iterator end(StringRef path)
Get end iterator over path.
HashTableIterator & operator++()
This class represents lattice values for constants.
Error writeSparseBitVector(BinaryStreamWriter &Writer, SparseBitVector<> &Vec)
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
iterator find_as(const Key &K) const
Find the entry whose key has the specified hash value, using the specified traits defining hash funct...
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
uint32_t capacity() const
const std::pair< uint32_t, ValueT > & operator*() const
HashTableIterator & operator=(const HashTableIterator &R)
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Error readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
bool set_as(const Key &K, ValueT V)
Set the entry using a key type that the specified Traits can convert from a real key to an internal k...
static ErrorSuccess success()
Create a success value.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
HashTable(TraitsT Traits)
bool operator==(const HashTableIterator &R) const
uint32_t hashLookupKey(uint32_t N) const
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
HashTable(uint32_t Capacity, TraitsT Traits)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
HashTableIterator(const HashTable< ValueT, TraitsT > &Map)
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
Error commit(BinaryStreamWriter &Writer) const
uint32_t calculateSerializedLength() const
uint32_t storageKeyToLookupKey(uint32_t N) const
bool isPresent(uint32_t K) const
Provides read only access to a subclass of BinaryStream.
bool isDeleted(uint32_t K) const