// If small, this is # elts allocated consequtively
unsigned NumElements;
+ unsigned NumTombstones;
void *SmallArray[1]; // Must be last ivar.
public:
SmallPtrSetImpl(unsigned SmallSize) {
// Fill the array with empty markers.
memset(CurArray, -1, CurArraySize*sizeof(void*));
NumElements = 0;
+ NumTombstones = 0;
}
/// insert - This returns true if the pointer was new to the set, false if it
}
// If more than 3/4 of the array is full, grow.
- if (NumElements*4 >= CurArraySize*3)
+ if (NumElements*4 >= CurArraySize*3 ||
+ CurArraySize-(NumElements+NumTombstones) < CurArraySize/8)
Grow();
// Okay, we know we have space. Find a hash bucket.
if (*Bucket == Ptr) return false; // Already inserted, good.
// Otherwise, insert it!
+ if (*Bucket == getTombstoneMarker())
+ --NumTombstones;
*Bucket = Ptr;
++NumElements; // Track density.
return true;
// Set this as a tombstone.
*Bucket = getTombstoneMarker();
--NumElements;
+ ++NumTombstones;
return true;
}