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

Function CPLHashSetInsert

port/cpl_hash_set.cpp:334–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332 */
333
334int CPLHashSetInsert(CPLHashSet *set, void *elt)
335{
336 CPLAssert(set != nullptr);
337 void **pElt = CPLHashSetFindPtr(set, elt);
338 if (pElt)
339 {
340 if (set->fnFreeEltFunc)
341 set->fnFreeEltFunc(*pElt);
342
343 *pElt = elt;
344 return FALSE;
345 }
346
347 if (set->nSize >= 2 * set->nAllocatedSize / 3 ||
348 (set->bRehash && set->nIndiceAllocatedSize > 0 &&
349 set->nSize <= set->nAllocatedSize / 2))
350 {
351 set->nIndiceAllocatedSize++;
352 CPLHashSetRehash(set);
353 }
354
355 const unsigned long nHashVal = set->fnHashFunc(elt) % set->nAllocatedSize;
356#ifdef HASH_DEBUG
357 if (set->tabList[nHashVal])
358 set->nCollisions++;
359#endif
360
361 CPLList *new_elt = CPLHashSetGetNewListElt(set);
362 new_elt->pData = elt;
363 new_elt->psNext = set->tabList[nHashVal];
364 set->tabList[nHashVal] = new_elt;
365 set->nSize++;
366
367 return TRUE;
368}
369
370/************************************************************************/
371/* CPLHashSetLookup() */

Callers 13

startElementCbkMethod · 0.85
OGRPGAddTableEntryFunction · 0.85
AddFieldDefnToSetMethod · 0.85
OpenMethod · 0.85
TEST_FFunction · 0.85
GetMetadataMethod · 0.85
GetMetadataItemMethod · 0.85
MarkAsSharedMethod · 0.85
CPLLoadSchemaStrInternalFunction · 0.85
GetFileListMethod · 0.85
GetFileListMethod · 0.85

Calls 3

CPLHashSetFindPtrFunction · 0.85
CPLHashSetRehashFunction · 0.85
CPLHashSetGetNewListEltFunction · 0.85

Tested by 1

TEST_FFunction · 0.68