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

Function CPLHashSetRemoveInternal

port/cpl_hash_set.cpp:398–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396/************************************************************************/
397
398static bool CPLHashSetRemoveInternal(CPLHashSet *set, const void *elt,
399 bool bDeferRehash)
400{
401 CPLAssert(set != nullptr);
402 if (set->nIndiceAllocatedSize > 0 && set->nSize <= set->nAllocatedSize / 2)
403 {
404 set->nIndiceAllocatedSize--;
405 if (bDeferRehash)
406 set->bRehash = true;
407 else
408 CPLHashSetRehash(set);
409 }
410
411 int nHashVal = static_cast<int>(set->fnHashFunc(elt) % set->nAllocatedSize);
412 CPLList *cur = set->tabList[nHashVal];
413 CPLList *prev = nullptr;
414 while (cur)
415 {
416 if (set->fnEqualFunc(cur->pData, elt))
417 {
418 if (prev)
419 prev->psNext = cur->psNext;
420 else
421 set->tabList[nHashVal] = cur->psNext;
422
423 if (set->fnFreeEltFunc)
424 set->fnFreeEltFunc(cur->pData);
425
426 CPLHashSetReturnListElt(set, cur);
427#ifdef HASH_DEBUG
428 if (set->tabList[nHashVal])
429 set->nCollisions--;
430#endif
431 set->nSize--;
432 return true;
433 }
434 prev = cur;
435 cur = cur->psNext;
436 }
437 return false;
438}
439
440/************************************************************************/
441/* CPLHashSetRemove() */

Callers 2

CPLHashSetRemoveFunction · 0.85

Calls 2

CPLHashSetRehashFunction · 0.85
CPLHashSetReturnListEltFunction · 0.85

Tested by

no test coverage detected