31 #ifndef LLVM_ADT_SCOPEDHASHTABLE_H
32 #define LLVM_ADT_SCOPEDHASHTABLE_H
39 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
40 typename AllocatorTy = MallocAllocator>
43 template <
typename K,
typename V>
52 const K &
getKey()
const {
return Key; }
60 template <
typename AllocatorTy>
63 const K &key,
const V &val,
64 AllocatorTy &Allocator) {
68 New->NextInScope = nextInScope;
69 New->NextForKey = nextForKey;
73 template <
typename AllocatorTy>
77 Allocator.Deallocate(
this);
81 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K>,
82 typename AllocatorTy = MallocAllocator>
105 return LastValInScope;
108 LastValInScope = Val;
113 template <
typename K,
typename V,
typename KInfo = DenseMapInfo<K> >
120 assert(Node &&
"Dereference end()");
121 return Node->getValue();
124 return &Node->getValue();
128 return Node == RHS.Node;
131 return Node != RHS.Node;
135 assert(Node &&
"incrementing past end()");
136 Node = Node->getNextForKey();
145 template <
typename K,
typename V,
typename KInfo,
typename AllocatorTy>
146 class ScopedHashTable {
156 AllocatorTy Allocator;
165 assert(CurScope == 0 && TopLevelMap.empty() &&
"Scope imbalance!");
176 return TopLevelMap.count(Key);
181 if (I != TopLevelMap.end())
182 return I->second->getValue();
187 void insert(
const K &Key,
const V &Val) {
197 TopLevelMap.find(Key);
198 if (I == TopLevelMap.end())
return end();
210 assert(S &&
"No scope active!");
212 KeyEntry =
ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val,
214 S->setLastValInScope(KeyEntry);
220 template <
typename K,
typename V,
typename KInfo,
typename Allocator>
221 ScopedHashTableScope<K, V, KInfo, Allocator>::
222 ScopedHashTableScope(ScopedHashTable<K, V, KInfo, Allocator> &ht) : HT(ht) {
223 PrevScope = HT.CurScope;
228 template <
typename K,
typename V,
typename KInfo,
typename Allocator>
230 assert(HT.CurScope ==
this &&
"Scope imbalance!");
231 HT.CurScope = PrevScope;
236 if (ThisEntry->getNextForKey() == 0) {
237 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
239 HT.TopLevelMap.erase(ThisEntry->getKey());
242 assert(KeyEntry == ThisEntry &&
"Scope imbalance!");
250 ThisEntry->
Destroy(HT.getAllocator());
ScopedHashTableVal * getNextInScope()
ScopedHashTableIterator operator++(int)
ReferenceAdder< const AllocatorTy >::result AllocatorCRefTy
void insertIntoScope(ScopeTy *S, const K &Key, const V &Val)
AllocatorCRefTy getAllocator() const
const V & getValue() const
bool operator!=(const ScopedHashTableIterator &RHS) const
AllocatorRefTy getAllocator()
static ScopedHashTableVal * Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator)
bool operator==(const ScopedHashTableIterator &RHS) const
ScopedHashTableScope< K, V, KInfo, AllocatorTy > ScopeTy
ScopedHashTableScope * getParentScope()
const ScopedHashTableVal * getNextForKey() const
ScopedHashTableVal * getNextForKey()
const ScopeTy * getCurScope() const
ScopedHashTable(AllocatorTy A)
void insert(const K &Key, const V &Val)
iterator begin(const K &Key)
#define LLVM_DELETED_FUNCTION
ReferenceAdder< AllocatorTy >::result AllocatorRefTy
Access to the allocator.
ScopedHashTableIterator & operator++()
ScopedHashTableIterator(ScopedHashTableVal< K, V > *node)
void Destroy(AllocatorTy &Allocator)
bool count(const K &Key) const
ScopedHashTableIterator< K, V, KInfo > iterator
const ScopedHashTableScope * getParentScope() const