14 #ifndef LLVM_ADT_STRINGMAP_H
15 #define LLVM_ADT_STRINGMAP_H
25 #include <initializer_list>
31 template<
typename ValueT>
33 template<
typename ValueT>
35 template<
typename ValueTy>
70 RHS.TheTable =
nullptr;
73 RHS.NumTombstones = 0;
101 void init(
unsigned Size);
105 uintptr_t Val =
static_cast<uintptr_t
>(-1);
106 Val <<= PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable;
127 template<
typename ValueTy>
128 class StringMapEntry :
public StringMapEntryBase {
134 template <
typename... InitTy>
151 const char *
getKeyData()
const {
return reinterpret_cast<const char*
>(
this+1);}
157 template <
typename AllocatorTy,
typename... InitTy>
159 InitTy &&... InitVals) {
160 unsigned KeyLength = Key.
size();
164 unsigned AllocSize =
static_cast<unsigned>(
sizeof(
StringMapEntry))+
169 static_cast<StringMapEntry*
>(Allocator.Allocate(AllocSize,Alignment));
172 new (NewItem)
StringMapEntry(KeyLength, std::forward<InitTy>(InitVals)...);
175 char *StrBuffer =
const_cast<char*
>(NewItem->getKeyData());
177 memcpy(StrBuffer, Key.
data(), KeyLength);
178 StrBuffer[KeyLength] = 0;
183 template <
typename... InitType>
186 return Create(Key, A, std::forward<InitType>(InitVal)...);
190 return Create(Key, ValueTy());
202 template<
typename AllocatorTy>
208 Allocator.Deallocate(static_cast<void *>(
this), AllocSize);
222 template<
typename ValueTy,
typename AllocatorTy = MallocAllocator>
224 AllocatorTy Allocator;
242 for (
const auto &
P :
List) {
248 :
StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {}
258 Allocator(RHS.Allocator) {
278 static_cast<MapEntryTy *>(Bucket)->getKey(), Allocator,
279 static_cast<MapEntryTy *>(Bucket)->getValue());
280 HashTable[
I] = RHSHashTable[
I];
317 if (Bucket == -1)
return end();
323 if (Bucket == -1)
return end();
342 return find(Key) ==
end() ? 0 : 1;
368 std::pair<iterator, bool>
insert(std::pair<StringRef, ValueTy> KV) {
369 return try_emplace(KV.first, std::move(KV.second));
376 template <
typename... ArgsTy>
403 static_cast<MapEntryTy*
>(Bucket)->Destroy(Allocator);
426 if (I ==
end())
return false;
439 static_cast<MapEntryTy*
>(Bucket)->Destroy(Allocator);
447 template <
typename ValueTy>
class StringMapConstIterator {
457 bool NoAdvance =
false)
459 if (!NoAdvance) AdvancePastEmptyBuckets();
470 return Ptr == RHS.Ptr;
473 return Ptr != RHS.Ptr;
478 AdvancePastEmptyBuckets();
486 void AdvancePastEmptyBuckets() {
492 template<
typename ValueTy>
493 class StringMapIterator :
public StringMapConstIterator<ValueTy> {
498 bool NoAdvance =
false)
512 #endif // LLVM_ADT_STRINGMAP_H
StringMapEntryBase ** Ptr
const ValueTy & getValue() const
unsigned getNumItems() const
StringMapImpl(unsigned itemSize)
bool operator!=(const StringMapConstIterator &RHS) const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
const_iterator find(StringRef Key) const
void setValue(const ValueTy &V)
StringMapEntryBase(unsigned Len)
unsigned RehashTable(unsigned BucketNo=0)
RehashTable - Grow the table, redistributing values into the buckets with the appropriate mod-of-hash...
StringMapEntry< ValueTy > value_type
int FindKey(StringRef Key) const
FindKey - Look up the bucket that contains the specified key.
iterator find(StringRef Key)
unsigned LookupBucketFor(StringRef Key)
LookupBucketFor - Look up the bucket that the specified string should end up in.
StringMapIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
StringMap(const StringMap &RHS)
unsigned getNumBuckets() const
StringMap & operator=(StringMap RHS)
StringMapEntry< ValueTy > * operator->() const
static StringMapEntry & GetStringMapEntryFromKeyData(const char *KeyData)
GetStringMapEntryFromKeyData - Given key data that is known to be embedded into a StringMapEntry...
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
const AllocatorTy & getAllocator() const
StringMapImpl - This is the base class of StringMap that is shared among all of its instantiations...
void Destroy(AllocatorTy &Allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
void swap(StringMapImpl &Other)
StringMapConstIterator< ValueTy > const_iterator
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
StringMap(StringMap &&RHS)
StringMapIterator< ValueTy > iterator
StringMapConstIterator operator++(int)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
bool operator==(const StringMapConstIterator &RHS) const
StringMapEntryBase ** TheTable
StringMapEntry(unsigned strLen)
StringMapEntry< ValueTy > MapEntryTy
const_iterator end() const
Greedy Register Allocator
void Destroy()
Destroy this object, releasing memory back to the malloc allocator.
StringMap(unsigned InitialSize)
void init(unsigned Size)
Allocate the table with the specified number of buckets and otherwise setup the map as empty...
const_iterator begin() const
StringMapConstIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
static StringMapEntry * Create(StringRef Key, AllocatorTy &Allocator, InitTy &&...InitVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
bool erase(StringRef Key)
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map...
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
AllocatorTy & getAllocator()
void RemoveKey(StringMapEntryBase *V)
RemoveKey - Remove the specified StringMapEntry from the table, but do not delete it...
std::pair< iterator, bool > insert(std::pair< StringRef, ValueTy > KV)
insert - Inserts the specified key/value pair into the map if the key isn't already in the map...
StringMapEntry< ValueTy > value_type
const char * getKeyData() const
getKeyData - Return the start of the string data that is the key for this value.
static StringMapEntryBase * getTombstoneVal()
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
StringMapConstIterator & operator++()
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
StringMap(unsigned InitialSize, AllocatorTy A)
StringMapEntry< ValueTy > & operator*() const
const value_type * operator->() const
StringMapEntry(unsigned strLen, InitTy &&...InitVals)
unsigned getKeyLength() const
static StringMapEntry * Create(StringRef Key)
StringMap(std::initializer_list< std::pair< StringRef, ValueTy >> List)
StringMapIterator()=default
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringMapImpl(StringMapImpl &&RHS)
const value_type & operator*() const
StringMapEntryBase - Shared base class of StringMapEntry instances.
static StringMapEntry * Create(StringRef Key, InitType &&...InitVal)
Create - Create a StringMapEntry with normal malloc/free.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
ValueTy & operator[](StringRef Key)
Lookup the ValueTy for the Key, or create a default constructed value if the key is not in the map...
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
StringMapConstIterator()=default