9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H 10 #define LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H 26 class BinaryStreamReader;
27 class BinaryStreamWriter;
36 template <
typename ValueT>
39 std::forward_iterator_tag,
40 const std::pair<uint32_t, ValueT>> {
45 : Map(&Map), Index(Index), IsEnd(IsEnd) {}
70 return (Map == R.Map) && (Index == R.Index);
72 const std::pair<uint32_t, ValueT> &
operator*()
const {
80 std::forward_iterator_tag,
81 const std::pair<uint32_t, ValueT>>::operator++;
83 while (Index < Map->Buckets.size()) {
94 bool isEnd()
const {
return IsEnd; }
95 uint32_t index()
const {
return Index; }
102 template <
typename ValueT>
109 using BucketList = std::vector<std::pair<uint32_t, ValueT>>;
117 Buckets.resize(Capacity);
124 if (H->Capacity == 0)
126 "Invalid Hash Table Capacity");
127 if (H->Size > maxLoad(H->Capacity))
128 return make_error<RawError>(raw_error_code::corrupt_file,
129 "Invalid Hash Table Size");
131 Buckets.resize(H->Capacity);
135 if (Present.count() != H->Size)
136 return make_error<RawError>(raw_error_code::corrupt_file,
137 "Present bit vector does not match size!");
141 if (Present.intersects(
Deleted))
142 return make_error<RawError>(raw_error_code::corrupt_file,
143 "Present bit vector intersects deleted!");
151 Buckets[
P].second = *
Value;
160 constexpr
int BitsPerWord = 8 *
sizeof(
uint32_t);
162 int NumBitsP = Present.find_last() + 1;
163 int NumBitsD =
Deleted.find_last() + 1;
171 Size += NumWordsP *
sizeof(
uint32_t);
176 Size += NumWordsD *
sizeof(
uint32_t);
187 H.Capacity = capacity();
197 for (
const auto &
Entry : *
this) {
221 template <
typename Key,
typename TraitsT>
223 uint32_t H = Traits.hashLookupKey(K) % capacity();
228 if (Traits.storageKeyToLookupKey(Buckets[I].first) == K)
241 I = (I + 1) % capacity();
253 template <
typename Key,
typename TraitsT>
255 return set_as_internal(K, std::move(V), Traits,
None);
258 template <
typename Key,
typename TraitsT>
260 auto Iter = find_as(K, Traits);
262 return (*Iter).second;
276 template <
typename Key,
typename TraitsT>
279 auto Entry = find_as(K, Traits);
282 assert(Traits.storageKeyToLookupKey(Buckets[
Entry.index()].first) == K);
284 Buckets[
Entry.index()].second = V;
288 auto &
B = Buckets[
Entry.index()];
291 B.first = InternalKey ? *InternalKey : Traits.lookupKeyToStorageKey(K);
304 template <
typename TraitsT>
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, Traits,
327 assert(capacity() == NewCapacity);
336 #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.
const std::pair< uint32_t, ValueT > & operator*() const
HashTableIterator & operator++()
const_iterator end(StringRef path)
Get end iterator over path.
This class represents lattice values for constants.
bool set_as(const Key &K, ValueT V, TraitsT &Traits)
Set the entry using a key type that the specified Traits can convert from a real key to an internal k...
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...
HashTableIterator & operator=(const HashTableIterator &R)
uint32_t calculateSerializedLength() const
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Error readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V)
const_iterator begin() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const_iterator find_as(const Key &K, TraitsT &Traits) const
Find the entry whose key has the specified hash value, using the specified traits defining hash funct...
Provides write only access to a subclass of WritableBinaryStream.
Error commit(BinaryStreamWriter &Writer) const
HashTableIterator(const HashTable< ValueT > &Map)
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
bool operator==(const HashTableIterator &R) const
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.
bool isDeleted(uint32_t K) const
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Error load(BinaryStreamReader &Stream)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const_iterator end() const
bool isPresent(uint32_t K) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint32_t capacity() const
Lightweight error class with error context and mandatory checking.
Provides read only access to a subclass of BinaryStream.
HashTable(uint32_t Capacity)