summaryrefslogtreecommitdiff
path: root/lib/Support/FoldingSet.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-03 21:12:09 +0000
committerChris Lattner <sabre@nondot.org>2007-10-03 21:12:09 +0000
commit116c3219df347f169b1bd24acca2d53ab0ae26ec (patch)
tree7b89c7d4fb946e59360da0d3978b114221df260f /lib/Support/FoldingSet.cpp
parent6ccc2d579e7e9f2bce353391aa487f218b3dc5c1 (diff)
downloadllvm-116c3219df347f169b1bd24acca2d53ab0ae26ec.tar.gz
llvm-116c3219df347f169b1bd24acca2d53ab0ae26ec.tar.bz2
llvm-116c3219df347f169b1bd24acca2d53ab0ae26ec.tar.xz
Add initial iterator support for folding set.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42589 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/FoldingSet.cpp')
-rw-r--r--lib/Support/FoldingSet.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp
index 424dff18bd..d099d90fe2 100644
--- a/lib/Support/FoldingSet.cpp
+++ b/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);
+ }
+}
+