llvm.org GIT mirror llvm / 535de1a
Add a clear() method to FoldingSet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55210 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
2 changed file(s) with 16 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
142142 void SetNextInBucket(void *N) { NextInFoldingSetBucket = N; }
143143 };
144144
145 /// clear - Remove all nodes from the folding set.
146 void clear();
147
145148 /// RemoveNode - Remove a node from the folding set, returning true if one
146149 /// was removed or false if the node was not in the folding set.
147150 bool RemoveNode(Node *N);
199199 //===----------------------------------------------------------------------===//
200200 // FoldingSetImpl Implementation
201201
202 FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) : NumNodes(0) {
202 FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) {
203203 assert(5 < Log2InitSize && Log2InitSize < 32 &&
204204 "Initial hash table size out of range");
205205 NumBuckets = 1 << Log2InitSize;
206206 Buckets = new void*[NumBuckets+1];
207 clear();
208 }
209 FoldingSetImpl::~FoldingSetImpl() {
210 delete [] Buckets;
211 }
212 void FoldingSetImpl::clear() {
213 // Set all but the last bucket to null pointers.
207214 memset(Buckets, 0, NumBuckets*sizeof(void*));
208
215
209216 // Set the very last bucket to be a non-null "pointer".
210217 Buckets[NumBuckets] = reinterpret_cast(-1);
211 }
212 FoldingSetImpl::~FoldingSetImpl() {
213 delete [] Buckets;
218
219 // Reset the node count to zero.
220 NumNodes = 0;
214221 }
215222
216223 /// GrowHashTable - Double the size of the hash table and rehash everything.
220227 unsigned OldNumBuckets = NumBuckets;
221228 NumBuckets <<= 1;
222229
223 // Reset the node count to zero: we're going to reinsert everything.
224 NumNodes = 0;
225
226230 // Clear out new buckets.
227231 Buckets = new void*[NumBuckets+1];
228 memset(Buckets, 0, NumBuckets*sizeof(void*));
229
230 // Set the very last bucket to be a non-null "pointer".
231 Buckets[NumBuckets] = reinterpret_cast(-1);
232 clear();
232233
233234 // Walk the old buckets, rehashing nodes into their new place.
234235 FoldingSetNodeID ID;