14 #ifndef LLVM_ADT_STRINGMAP_H
15 #define LLVM_ADT_STRINGMAP_H
22 template<
typename ValueT>
24 template<
typename ValueT>
26 template<
typename ValueTy>
32 template<
typename ValueTy>
35 template <
typename InitTy>
94 void init(
unsigned Size);
117 template<
typename ValueTy>
118 class StringMapEntry :
public StringMapEntryBase {
140 const char *
getKeyData()
const {
return reinterpret_cast<const char*
>(
this+1);}
146 template<
typename AllocatorTy,
typename InitType>
148 AllocatorTy &Allocator,
150 unsigned KeyLength =
static_cast<unsigned>(KeyEnd-KeyStart);
156 unsigned AllocSize =
static_cast<unsigned>(
sizeof(
StringMapEntry))+
158 unsigned Alignment = alignOf<StringMapEntry>();
161 static_cast<StringMapEntry*
>(Allocator.Allocate(AllocSize,Alignment));
167 char *StrBuffer =
const_cast<char*
>(NewItem->getKeyData());
168 memcpy(StrBuffer, KeyStart, KeyLength);
169 StrBuffer[KeyLength] = 0;
176 template<
typename AllocatorTy>
178 AllocatorTy &Allocator) {
179 return Create(KeyStart, KeyEnd, Allocator, 0);
183 template<
typename InitType>
187 return Create(KeyStart, KeyEnd, A, InitVal);
191 return Create(KeyStart, KeyEnd, ValueTy());
198 char *Ptr =
reinterpret_cast<char*
>(&V) -
199 (reinterpret_cast<char*>(&EPtr->second) -
200 reinterpret_cast<char*
>(EPtr));
216 template<
typename AllocatorTy>
220 Allocator.Deallocate(
this);
235 template<
typename ValueTy,
typename AllocatorTy = MallocAllocator>
237 AllocatorTy Allocator;
254 assert(RHS.
empty() &&
255 "Copy ctor from non-empty stringmap not implemented yet!");
259 assert(RHS.
empty() &&
260 "assignment from non-empty stringmap not implemented yet!");
293 if (Bucket == -1)
return end();
299 if (Bucket == -1)
return end();
317 return find(Key) ==
end() ? 0 : 1;
348 static_cast<MapEntryTy*
>(Bucket)->Destroy(Allocator);
360 template <
typename InitTy>
401 if (I ==
end())
return false;
413 template<
typename ValueTy>
414 class StringMapConstIterator {
423 bool NoAdvance =
false)
425 if (!NoAdvance) AdvancePastEmptyBuckets();
436 return Ptr == RHS.Ptr;
439 return Ptr != RHS.Ptr;
444 AdvancePastEmptyBuckets();
452 void AdvancePastEmptyBuckets() {
458 template<
typename ValueTy>
459 class StringMapIterator :
public StringMapConstIterator<ValueTy> {
463 bool NoAdvance =
false)
StringMapEntryBase ** Ptr
const ValueTy & getValue() const
unsigned getNumItems() const
StringMapImpl(unsigned itemSize)
static const StringMapEntry & GetStringMapEntryFromValue(const ValueTy &V)
AllocatorCRefTy getAllocator() const
bool operator!=(const StringMapConstIterator &RHS) const
const_iterator find(StringRef Key) const
void setValue(const ValueTy &V)
StringMapEntryBase(unsigned Len)
StringMapEntry< ValueTy > value_type
int FindKey(StringRef Key) const
iterator find(StringRef Key)
unsigned LookupBucketFor(StringRef Key)
StringMapIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
static StringMapEntry * Create(const char *KeyStart, const char *KeyEnd)
StringMap(const StringMap &RHS)
void operator=(const StringMap &RHS)
unsigned getNumBuckets() const
StringMapEntry< ValueTy > * operator->() const
static StringMapEntry & GetStringMapEntryFromKeyData(const char *KeyData)
size_type count(StringRef Key) const
void Destroy(AllocatorTy &Allocator)
void swap(StringMapImpl &Other)
StringMapConstIterator< ValueTy > const_iterator
StringMapIterator< ValueTy > iterator
StringMapConstIterator operator++(int)
MapEntryTy & GetOrCreateValue(StringRef Key)
bool operator==(const StringMapConstIterator &RHS) const
StringMapEntryBase ** TheTable
StringMapEntry(unsigned strLen)
StringMapEntry< ValueTy > MapEntryTy
ReferenceAdder< const AllocatorTy >::result AllocatorCRefTy
const_iterator end() const
void Destroy()
Destroy this object, releasing memory back to the malloc allocator.
StringMapEntry(unsigned strLen, const ValueTy &V)
StringMap(unsigned InitialSize)
const_iterator begin() const
StringMapConstIterator(StringMapEntryBase **Bucket, bool NoAdvance=false)
bool erase(StringRef Key)
ValueTy lookup(StringRef Key) const
void RemoveKey(StringMapEntryBase *V)
StringMapEntry< ValueTy > value_type
static StringMapEntry * Create(const char *KeyStart, const char *KeyEnd, AllocatorTy &Allocator, InitType InitVal)
const char * getKeyData() const
static StringMapEntryBase * getTombstoneVal()
bool insert(MapEntryTy *KeyValue)
#define LLVM_DELETED_FUNCTION
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
StringMapConstIterator & operator++()
StringMap(unsigned InitialSize, AllocatorTy A)
MapEntryTy & GetOrCreateValue(StringRef Key, InitTy Val)
static void Initialize(StringMapEntry< ValueTy > &T, InitTy InitVal)
StringMapEntry< ValueTy > & operator*() const
const value_type * operator->() const
static StringMapEntry * Create(const char *KeyStart, const char *KeyEnd, AllocatorTy &Allocator)
unsigned getKeyLength() const
static StringMapEntry & GetStringMapEntryFromValue(ValueTy &V)
const value_type & operator*() const
StringMapEntryBase - Shared base class of StringMapEntry instances.
AllocatorRefTy getAllocator()
ValueTy & operator[](StringRef Key)
ReferenceAdder< AllocatorTy >::result AllocatorRefTy
static StringMapEntry * Create(const char *KeyStart, const char *KeyEnd, InitType InitVal)
Create - Create a StringMapEntry with normal malloc/free.