ScopedHashTable.h (218893) | ScopedHashTable.h (221345) |
---|---|
1//===- ScopedHashTable.h - A simple scoped hash table ---------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 82 unchanged lines hidden (view full) --- 91 /// or null if none have been inserted yet. 92 ScopedHashTableVal<K, V> *LastValInScope; 93 void operator=(ScopedHashTableScope&); // DO NOT IMPLEMENT 94 ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT 95public: 96 ScopedHashTableScope(ScopedHashTable<K, V, KInfo, AllocatorTy> &HT); 97 ~ScopedHashTableScope(); 98 | 1//===- ScopedHashTable.h - A simple scoped hash table ---------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 82 unchanged lines hidden (view full) --- 91 /// or null if none have been inserted yet. 92 ScopedHashTableVal<K, V> *LastValInScope; 93 void operator=(ScopedHashTableScope&); // DO NOT IMPLEMENT 94 ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT 95public: 96 ScopedHashTableScope(ScopedHashTable<K, V, KInfo, AllocatorTy> &HT); 97 ~ScopedHashTableScope(); 98 |
99 ScopedHashTableScope *getParentScope() { return PrevScope; } 100 const ScopedHashTableScope *getParentScope() const { return PrevScope; } 101 |
|
99private: 100 friend class ScopedHashTable<K, V, KInfo, AllocatorTy>; 101 ScopedHashTableVal<K, V> *getLastValInScope() { 102 return LastValInScope; 103 } 104 void setLastValInScope(ScopedHashTableVal<K, V> *Val) { 105 LastValInScope = Val; 106 } --- 29 unchanged lines hidden (view full) --- 136 ScopedHashTableIterator operator++(int) { // Postincrement 137 ScopedHashTableIterator tmp = *this; ++*this; return tmp; 138 } 139}; 140 141 142template <typename K, typename V, typename KInfo, typename AllocatorTy> 143class ScopedHashTable { | 102private: 103 friend class ScopedHashTable<K, V, KInfo, AllocatorTy>; 104 ScopedHashTableVal<K, V> *getLastValInScope() { 105 return LastValInScope; 106 } 107 void setLastValInScope(ScopedHashTableVal<K, V> *Val) { 108 LastValInScope = Val; 109 } --- 29 unchanged lines hidden (view full) --- 139 ScopedHashTableIterator operator++(int) { // Postincrement 140 ScopedHashTableIterator tmp = *this; ++*this; return tmp; 141 } 142}; 143 144 145template <typename K, typename V, typename KInfo, typename AllocatorTy> 146class ScopedHashTable { |
147public: 148 /// ScopeTy - This is a helpful typedef that allows clients to get easy access 149 /// to the name of the scope for this hash table. 150 typedef ScopedHashTableScope<K, V, KInfo, AllocatorTy> ScopeTy; 151private: |
|
144 typedef ScopedHashTableVal<K, V> ValTy; 145 DenseMap<K, ValTy*, KInfo> TopLevelMap; | 152 typedef ScopedHashTableVal<K, V> ValTy; 153 DenseMap<K, ValTy*, KInfo> TopLevelMap; |
146 ScopedHashTableScope<K, V, KInfo, AllocatorTy> *CurScope; | 154 ScopeTy *CurScope; |
147 148 AllocatorTy Allocator; 149 150 ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED 151 void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED 152 friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>; 153public: 154 ScopedHashTable() : CurScope(0) {} 155 ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {} 156 ~ScopedHashTable() { 157 assert(CurScope == 0 && TopLevelMap.empty() && "Scope imbalance!"); 158 } 159 | 155 156 AllocatorTy Allocator; 157 158 ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED 159 void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED 160 friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>; 161public: 162 ScopedHashTable() : CurScope(0) {} 163 ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {} 164 ~ScopedHashTable() { 165 assert(CurScope == 0 && TopLevelMap.empty() && "Scope imbalance!"); 166 } 167 |
160 /// ScopeTy - This is a helpful typedef that allows clients to get easy access 161 /// to the name of the scope for this hash table. 162 typedef ScopedHashTableScope<K, V, KInfo, AllocatorTy> ScopeTy; | |
163 164 /// Access to the allocator. 165 typedef typename ReferenceAdder<AllocatorTy>::result AllocatorRefTy; 166 typedef typename ReferenceAdder<const AllocatorTy>::result AllocatorCRefTy; 167 AllocatorRefTy getAllocator() { return Allocator; } 168 AllocatorCRefTy getAllocator() const { return Allocator; } 169 170 bool count(const K &Key) const { --- 4 unchanged lines hidden (view full) --- 175 typename DenseMap<K, ValTy*, KInfo>::iterator I = TopLevelMap.find(Key); 176 if (I != TopLevelMap.end()) 177 return I->second->getValue(); 178 179 return V(); 180 } 181 182 void insert(const K &Key, const V &Val) { | 168 169 /// Access to the allocator. 170 typedef typename ReferenceAdder<AllocatorTy>::result AllocatorRefTy; 171 typedef typename ReferenceAdder<const AllocatorTy>::result AllocatorCRefTy; 172 AllocatorRefTy getAllocator() { return Allocator; } 173 AllocatorCRefTy getAllocator() const { return Allocator; } 174 175 bool count(const K &Key) const { --- 4 unchanged lines hidden (view full) --- 180 typename DenseMap<K, ValTy*, KInfo>::iterator I = TopLevelMap.find(Key); 181 if (I != TopLevelMap.end()) 182 return I->second->getValue(); 183 184 return V(); 185 } 186 187 void insert(const K &Key, const V &Val) { |
183 assert(CurScope && "No scope active!"); 184 185 ScopedHashTableVal<K, V> *&KeyEntry = TopLevelMap[Key]; 186 187 KeyEntry = ValTy::Create(CurScope->getLastValInScope(), KeyEntry, Key, Val, 188 Allocator); 189 CurScope->setLastValInScope(KeyEntry); | 188 insertIntoScope(CurScope, Key, Val); |
190 } 191 192 typedef ScopedHashTableIterator<K, V, KInfo> iterator; 193 194 iterator end() { return iterator(0); } 195 196 iterator begin(const K &Key) { 197 typename DenseMap<K, ValTy*, KInfo>::iterator I = 198 TopLevelMap.find(Key); 199 if (I == TopLevelMap.end()) return end(); 200 return iterator(I->second); 201 } | 189 } 190 191 typedef ScopedHashTableIterator<K, V, KInfo> iterator; 192 193 iterator end() { return iterator(0); } 194 195 iterator begin(const K &Key) { 196 typename DenseMap<K, ValTy*, KInfo>::iterator I = 197 TopLevelMap.find(Key); 198 if (I == TopLevelMap.end()) return end(); 199 return iterator(I->second); 200 } |
201 202 ScopeTy *getCurScope() { return CurScope; } 203 const ScopeTy *getCurScope() const { return CurScope; } 204 205 /// insertIntoScope - This inserts the specified key/value at the specified 206 /// (possibly not the current) scope. While it is ok to insert into a scope 207 /// that isn't the current one, it isn't ok to insert *underneath* an existing 208 /// value of the specified key. 209 void insertIntoScope(ScopeTy *S, const K &Key, const V &Val) { 210 assert(S && "No scope active!"); 211 ScopedHashTableVal<K, V> *&KeyEntry = TopLevelMap[Key]; 212 KeyEntry = ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val, 213 Allocator); 214 S->setLastValInScope(KeyEntry); 215 } |
|
202}; 203 204/// ScopedHashTableScope ctor - Install this as the current scope for the hash 205/// table. 206template <typename K, typename V, typename KInfo, typename Allocator> 207ScopedHashTableScope<K, V, KInfo, Allocator>:: 208 ScopedHashTableScope(ScopedHashTable<K, V, KInfo, Allocator> &ht) : HT(ht) { 209 PrevScope = HT.CurScope; --- 33 unchanged lines hidden --- | 216}; 217 218/// ScopedHashTableScope ctor - Install this as the current scope for the hash 219/// table. 220template <typename K, typename V, typename KInfo, typename Allocator> 221ScopedHashTableScope<K, V, KInfo, Allocator>:: 222 ScopedHashTableScope(ScopedHashTable<K, V, KInfo, Allocator> &ht) : HT(ht) { 223 PrevScope = HT.CurScope; --- 33 unchanged lines hidden --- |