[llvm-commits] CVS: llvm/lib/Support/SmallPtrSet.cpp
Chris Lattner
sabre at nondot.org
Fri Jan 26 23:59:26 PST 2007
Changes in directory llvm/lib/Support:
SmallPtrSet.cpp updated: 1.2 -> 1.3
---
Log message:
implement SmallPtrSet::erase
---
Diffs of the changes: (+27 -0)
SmallPtrSet.cpp | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+)
Index: llvm/lib/Support/SmallPtrSet.cpp
diff -u llvm/lib/Support/SmallPtrSet.cpp:1.2 llvm/lib/Support/SmallPtrSet.cpp:1.3
--- llvm/lib/Support/SmallPtrSet.cpp:1.2 Sat Jan 27 01:18:32 2007
+++ llvm/lib/Support/SmallPtrSet.cpp Sat Jan 27 01:59:10 2007
@@ -45,6 +45,33 @@
return true;
}
+bool SmallPtrSetImpl::erase(void *Ptr) {
+ if (isSmall()) {
+ // Check to see if it is in the set.
+ for (void **APtr = SmallArray, **E = SmallArray+NumElements;
+ APtr != E; ++APtr)
+ if (*APtr == Ptr) {
+ // If it is in the set, move everything over, replacing this element.
+ memmove(APtr, APtr+1, sizeof(void*)*(E-APtr-1));
+ // Clear the end element.
+ E[-1] = getEmptyMarker();
+ --NumElements;
+ return false;
+ }
+
+ return false;
+ }
+
+ // Okay, we know we have space. Find a hash bucket.
+ void **Bucket = const_cast<void**>(FindBucketFor(Ptr));
+ if (*Bucket != Ptr) return false; // Not in the set?
+
+ // Set this as a tombstone.
+ *Bucket = getTombstoneMarker();
+ --NumElements;
+ return true;
+}
+
void * const *SmallPtrSetImpl::FindBucketFor(void *Ptr) const {
unsigned Bucket = Hash(Ptr);
unsigned ArraySize = CurArraySize;
More information about the llvm-commits
mailing list