23 void SmallPtrSetImplBase::shrink_and_clear() {
24 assert(!isSmall() &&
"Can't shrink a small set!");
33 assert(
CurArray &&
"Failed to allocate memory?");
37 std::pair<const void *const *, bool>
44 return std::make_pair(APtr,
false);
49 return std::make_pair(
SmallArray + (NumElements - 1),
true);
65 const void **Bucket =
const_cast<const void**
>(FindBucketFor(Ptr));
67 return std::make_pair(Bucket,
false);
74 return std::make_pair(Bucket,
true);
94 void **Bucket =
const_cast<void**
>(FindBucketFor(Ptr));
95 if (*Bucket != Ptr)
return false;
104 const void *
const *SmallPtrSetImplBase::FindBucketFor(
const void *Ptr)
const {
107 unsigned ProbeAmt = 1;
108 const void *
const *Array =
CurArray;
109 const void *
const *Tombstone =
nullptr;
115 return Tombstone ? Tombstone : Array+Bucket;
124 Tombstone = Array+Bucket;
127 Bucket = (Bucket + ProbeAmt++) & (ArraySize-1);
133 void SmallPtrSetImplBase::Grow(
unsigned NewSize) {
138 bool WasSmall = isSmall();
141 CurArray = (
const void**)malloc(
sizeof(
void*) * NewSize);
142 assert(
CurArray &&
"Failed to allocate memory?");
144 memset(
CurArray, -1, NewSize*
sizeof(
void*));
149 for (
const void **BucketPtr = OldBuckets, **E = OldBuckets+NumElements;
150 BucketPtr != E; ++BucketPtr) {
151 const void *Elt = *BucketPtr;
152 *
const_cast<void**
>(FindBucketFor(Elt)) = const_cast<void*>(Elt);
156 for (
const void **BucketPtr = OldBuckets, **E = OldBuckets+OldSize;
157 BucketPtr != E; ++BucketPtr) {
159 const void *Elt = *BucketPtr;
161 *const_cast<void**>(FindBucketFor(Elt)) = const_cast<void*>(Elt);
174 if (that.isSmall()) {
179 assert(
CurArray &&
"Failed to allocate memory?");
199 NumElements = that.NumElements;
203 if (that.isSmall()) {
209 that.CurArray = that.SmallArray;
213 that.CurArraySize = SmallSize;
214 assert(that.CurArray == that.SmallArray);
215 that.NumElements = 0;
216 that.NumTombstones = 0;
222 assert(&RHS !=
this &&
"Self-copy should be handled by the caller.");
224 if (isSmall() && RHS.isSmall())
226 "Cannot assign sets with different small sizes");
238 const void **
T = (
const void**)realloc(
CurArray,
244 assert(
CurArray &&
"Failed to allocate memory?");
259 assert(&RHS !=
this &&
"Self-move should be handled by the caller.");
267 memcpy(
CurArray, RHS.CurArray,
sizeof(
void*)*RHS.CurArraySize);
270 RHS.CurArray = RHS.SmallArray;
275 NumElements = RHS.NumElements;
279 RHS.CurArraySize = SmallSize;
280 assert(RHS.CurArray == RHS.SmallArray);
282 RHS.NumTombstones = 0;
286 if (
this == &RHS)
return;
289 if (!this->isSmall() && !RHS.isSmall()) {
301 if (!this->isSmall() && RHS.isSmall()) {
315 if (this->isSmall() && !RHS.isSmall()) {
328 assert(this->isSmall() && RHS.isSmall());
static void * getTombstoneMarker()
unsigned Log2_32_Ceil(uint32_t Value)
Log2_32_Ceil - This function returns the ceil log base 2 of the specified value, 32 if the value is z...
#define LLVM_UNLIKELY(EXPR)
#define LLVM_LIKELY(EXPR)
void MoveFrom(unsigned SmallSize, SmallPtrSetImplBase &&RHS)
void swap(SmallPtrSetImplBase &RHS)
swap - Swaps the elements of two sets.
unsigned CurArraySize
CurArraySize - The allocated size of CurArray, always a power of two.
const void ** CurArray
CurArray - This is the current set of buckets.
static void * getEmptyMarker()
void CopyFrom(const SmallPtrSetImplBase &RHS)
CopyFrom - implement operator= from a smallptrset that has the same pointer type, but may have a diff...
bool erase_imp(const void *Ptr)
erase_imp - If the set contains the specified pointer, remove it and return true, otherwise return fa...
const void ** SmallArray
SmallArray - Points to a fixed size set of buckets, used in 'small mode'.
SmallPtrSetImplBase(const void **SmallStorage, const SmallPtrSetImplBase &that)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
SmallPtrSetImplBase - This is the common code shared among all the SmallPtrSet<>'s, which is almost everything.
std::pair< const void *const *, bool > insert_imp(const void *Ptr)
insert_imp - This returns true if the pointer was new to the set, false if it was already in the set...