MCPcopy Create free account
hub / github.com/OSGeo/gdal / CPLHashSetRehash

Function CPLHashSetRehash

port/cpl_hash_set.cpp:264–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262/************************************************************************/
263
264static void CPLHashSetRehash(CPLHashSet *set)
265{
266 int nNewAllocatedSize = anPrimes[set->nIndiceAllocatedSize];
267 CPLList **newTabList = static_cast<CPLList **>(
268 CPLCalloc(sizeof(CPLList *), nNewAllocatedSize));
269#ifdef HASH_DEBUG
270 CPLDebug("CPLHASH",
271 "hashSet=%p, nSize=%d, nCollisions=%d, "
272 "fCollisionRate=%.02f",
273 set, set->nSize, set->nCollisions,
274 set->nCollisions * 100.0 / set->nSize);
275 set->nCollisions = 0;
276#endif
277 for (int i = 0; i < set->nAllocatedSize; i++)
278 {
279 CPLList *cur = set->tabList[i];
280 while (cur)
281 {
282 const unsigned long nNewHashVal =
283 set->fnHashFunc(cur->pData) % nNewAllocatedSize;
284#ifdef HASH_DEBUG
285 if (newTabList[nNewHashVal])
286 set->nCollisions++;
287#endif
288 CPLList *psNext = cur->psNext;
289 cur->psNext = newTabList[nNewHashVal];
290 newTabList[nNewHashVal] = cur;
291 cur = psNext;
292 }
293 }
294 CPLFree(set->tabList);
295 set->tabList = newTabList;
296 set->nAllocatedSize = nNewAllocatedSize;
297 set->bRehash = false;
298}
299
300/************************************************************************/
301/* CPLHashSetFindPtr() */

Callers 2

CPLHashSetInsertFunction · 0.85
CPLHashSetRemoveInternalFunction · 0.85

Calls 2

CPLCallocFunction · 0.85
CPLDebugFunction · 0.85

Tested by

no test coverage detected