diff options
author | Chris Lattner <sabre@nondot.org> | 2007-10-03 21:12:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-10-03 21:12:09 +0000 |
commit | 99f6ab7e4cb0c9369f02dd492cc50e52344ef334 (patch) | |
tree | 1f856e127044f672bb26162ec1e89f185aa91f30 /llvm/lib/Support/FoldingSet.cpp | |
parent | f0e5011d21846bb2eef8b8578f8fb969e49d0e3f (diff) | |
download | bcm5719-llvm-99f6ab7e4cb0c9369f02dd492cc50e52344ef334.tar.gz bcm5719-llvm-99f6ab7e4cb0c9369f02dd492cc50e52344ef334.zip |
Add initial iterator support for folding set.
llvm-svn: 42589
Diffstat (limited to 'llvm/lib/Support/FoldingSet.cpp')
-rw-r--r-- | llvm/lib/Support/FoldingSet.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp index 424dff18bd8..d099d90fe24 100644 --- a/llvm/lib/Support/FoldingSet.cpp +++ b/llvm/lib/Support/FoldingSet.cpp @@ -151,6 +151,7 @@ static FoldingSetImpl::Node *GetNextPtr(void *NextInBucketPtr) { /// testing. static void **GetBucketPtr(void *NextInBucketPtr) { intptr_t Ptr = reinterpret_cast<intptr_t>(NextInBucketPtr); + assert((Ptr & 1) && "Not a bucket pointer"); return reinterpret_cast<void**>(Ptr & ~intptr_t(1)); } @@ -323,3 +324,34 @@ FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) { InsertNode(N, IP); return N; } + +//===----------------------------------------------------------------------===// +// FoldingSetIteratorImpl Implementation + +FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) { + // Skip to the first non-null non-self-cycle bucket. + while (*Bucket == 0 || GetNextPtr(*Bucket) == 0) + ++Bucket; + + NodePtr = static_cast<FoldingSetNode*>(*Bucket); +} + +void FoldingSetIteratorImpl::advance() { + // If there is another link within this bucket, go to it. + void *Probe = NodePtr->getNextInBucket(); + + if (FoldingSetNode *NextNodeInBucket = GetNextPtr(Probe)) + NodePtr = NextNodeInBucket; + else { + // Otherwise, this is the last link in this bucket. + void **Bucket = GetBucketPtr(Probe); + + // Skip to the next non-null non-self-cycle bucket. + do { + ++Bucket; + } while (*Bucket == 0 || GetNextPtr(*Bucket) == 0); + + NodePtr = static_cast<FoldingSetNode*>(*Bucket); + } +} + |