diff options
author | Chris Lattner <sabre@nondot.org> | 2007-01-27 07:59:10 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-01-27 07:59:10 +0000 |
commit | 0b930852cf1a9899ae82dd6c31b43e754a77dcb0 (patch) | |
tree | e67e5cea4cc09e19fa639cc56c22cf24bada4be9 /lib/Support/SmallPtrSet.cpp | |
parent | af3056c97e56106af7c3b9a5c856d1dc1d21e358 (diff) |
implement SmallPtrSet::erase
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33581 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | lib/Support/SmallPtrSet.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp index 48552a56fc..1eea7272e0 100644 --- a/lib/Support/SmallPtrSet.cpp +++ b/lib/Support/SmallPtrSet.cpp @@ -45,6 +45,33 @@ bool SmallPtrSetImpl::insert(void *Ptr) { 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; |