mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 05:29:24 +00:00
Add a clear() method to FoldingSet.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55210 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
169b5ed46e
commit
535de1a8c1
@ -143,6 +143,9 @@ public:
|
|||||||
void SetNextInBucket(void *N) { NextInFoldingSetBucket = N; }
|
void SetNextInBucket(void *N) { NextInFoldingSetBucket = N; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// clear - Remove all nodes from the folding set.
|
||||||
|
void clear();
|
||||||
|
|
||||||
/// RemoveNode - Remove a node from the folding set, returning true if one
|
/// RemoveNode - Remove a node from the folding set, returning true if one
|
||||||
/// was removed or false if the node was not in the folding set.
|
/// was removed or false if the node was not in the folding set.
|
||||||
bool RemoveNode(Node *N);
|
bool RemoveNode(Node *N);
|
||||||
|
@ -200,19 +200,26 @@ static void **GetBucketFor(const FoldingSetNodeID &ID,
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// FoldingSetImpl Implementation
|
// FoldingSetImpl Implementation
|
||||||
|
|
||||||
FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) : NumNodes(0) {
|
FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) {
|
||||||
assert(5 < Log2InitSize && Log2InitSize < 32 &&
|
assert(5 < Log2InitSize && Log2InitSize < 32 &&
|
||||||
"Initial hash table size out of range");
|
"Initial hash table size out of range");
|
||||||
NumBuckets = 1 << Log2InitSize;
|
NumBuckets = 1 << Log2InitSize;
|
||||||
Buckets = new void*[NumBuckets+1];
|
Buckets = new void*[NumBuckets+1];
|
||||||
memset(Buckets, 0, NumBuckets*sizeof(void*));
|
clear();
|
||||||
|
|
||||||
// Set the very last bucket to be a non-null "pointer".
|
|
||||||
Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
|
|
||||||
}
|
}
|
||||||
FoldingSetImpl::~FoldingSetImpl() {
|
FoldingSetImpl::~FoldingSetImpl() {
|
||||||
delete [] Buckets;
|
delete [] Buckets;
|
||||||
}
|
}
|
||||||
|
void FoldingSetImpl::clear() {
|
||||||
|
// Set all but the last bucket to null pointers.
|
||||||
|
memset(Buckets, 0, NumBuckets*sizeof(void*));
|
||||||
|
|
||||||
|
// Set the very last bucket to be a non-null "pointer".
|
||||||
|
Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
|
||||||
|
|
||||||
|
// Reset the node count to zero.
|
||||||
|
NumNodes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// GrowHashTable - Double the size of the hash table and rehash everything.
|
/// GrowHashTable - Double the size of the hash table and rehash everything.
|
||||||
///
|
///
|
||||||
@ -221,15 +228,9 @@ void FoldingSetImpl::GrowHashTable() {
|
|||||||
unsigned OldNumBuckets = NumBuckets;
|
unsigned OldNumBuckets = NumBuckets;
|
||||||
NumBuckets <<= 1;
|
NumBuckets <<= 1;
|
||||||
|
|
||||||
// Reset the node count to zero: we're going to reinsert everything.
|
|
||||||
NumNodes = 0;
|
|
||||||
|
|
||||||
// Clear out new buckets.
|
// Clear out new buckets.
|
||||||
Buckets = new void*[NumBuckets+1];
|
Buckets = new void*[NumBuckets+1];
|
||||||
memset(Buckets, 0, NumBuckets*sizeof(void*));
|
clear();
|
||||||
|
|
||||||
// Set the very last bucket to be a non-null "pointer".
|
|
||||||
Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
|
|
||||||
|
|
||||||
// Walk the old buckets, rehashing nodes into their new place.
|
// Walk the old buckets, rehashing nodes into their new place.
|
||||||
FoldingSetNodeID ID;
|
FoldingSetNodeID ID;
|
||||||
|
Loading…
Reference in New Issue
Block a user