22 assert(((initSize & (initSize - 1)) == 0) &&
23 "Init Size must be a power of 2 or zero!");
32 throw std::bad_alloc();
59 throw std::bad_alloc();
62 auto newHashArray =
reinterpret_cast<unsigned*
>(newTableArray + newSize + 1);
70 unsigned fullHash = hashTable[i];
71 unsigned newBucket = fullHash & (newSize - 1);
72 if (!newTableArray[newBucket]) {
74 newTableArray[newBucket] = bucket;
75 newHashArray [newBucket] = fullHash;
78 unsigned probeSize = 1;
80 newBucket = (newBucket + probeSize++) & (newSize - 1);
81 }
while (newTableArray[newBucket]);
82 newTableArray[newBucket] = bucket;
83 newHashArray[newBucket] = fullHash;
95 template<
bool CASE_SENSITIVE>
101 template<
bool CASE_SENSITIVE>
104 if (CASE_SENSITIVE) {
112 template<
bool CASE_SENSITIVE>
118 template<
bool CASE_SENSITIVE>
121 if (numBuckets == 0) {
124 unsigned fullHashValue = hash<CASE_SENSITIVE>(name);
125 unsigned bucketNo = fullHashValue & (numBuckets - 1);
126 unsigned* hashTable = getHashTable();
128 unsigned probeAmt = 1;
129 int firstTombstone = -1;
136 if (firstTombstone != -1) {
137 hashTable[firstTombstone] = fullHashValue;
138 return firstTombstone;
140 hashTable[bucketNo] = fullHashValue;
142 }
else if (bucketItem == getTombstoneVal()) {
144 if (firstTombstone == -1) firstTombstone = bucketNo;
145 }
else if (hashTable[bucketNo] == fullHashValue) {
151 auto itemStr =
reinterpret_cast<char*
>(bucketItem) + itemSize;
152 if (equal<CASE_SENSITIVE>(
160 bucketNo = (bucketNo + probeAmt) & (numBuckets - 1);
165 template<
bool CASE_SENSITIVE>
168 if (numBuckets == 0)
return -1;
170 unsigned fullHashValue = hash<CASE_SENSITIVE>(key);
171 unsigned bucketNo = fullHashValue & (numBuckets - 1);
172 unsigned* hashTable = getHashTable();
174 unsigned probeAmt = 1;
180 }
else if (bucketItem == getTombstoneVal()) {
182 }
else if (hashTable[bucketNo] == fullHashValue) {
184 auto itemStr =
reinterpret_cast<char*
>(bucketItem) + itemSize;
185 if (equal<CASE_SENSITIVE>(
191 bucketNo = (bucketNo + probeAmt) & (numBuckets - 1);
196 template<
bool CASE_SENSITIVE>
199 auto vStr =
reinterpret_cast<char*
>(v) + itemSize;
201 assert(v == v2 &&
"Didn't find key?"); (void)v2;
204 template<
bool CASE_SENSITIVE>
207 int bucket = findKey(key);
208 if (bucket == -1)
return nullptr;
211 theTable[bucket] = getTombstoneVal();
214 assert(numItems + numTombstones <= numBuckets);
uint32_t xxhash_case(string_ref key)
unsigned * getHashTable() const
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
StringMapImpl(unsigned itemSize, unsigned initSize)
static StringMapEntryBase * getTombstoneVal()
unsigned lookupBucketFor(string_ref key)
Non-templatized base class of StringMap.
StringMapImpl2(unsigned itemSize, unsigned initSize)
unsigned getKeyLength() const
uint32_t xxhash(string_ref key)
int findKey(string_ref key) const
void removeKey(StringMapEntryBase *V)
StringMapEntryBase ** theTable