MCPcopy Create free account
hub / github.com/audacity/audacity / idxHashAdd

Function idxHashAdd

lib-src/sqlite/shell.c:8587–8618  ·  view source on GitHub ↗

** If zKey is already present in the hash table, return non-zero and do ** nothing. Otherwise, add an entry with key zKey and payload string zVal to ** the hash table passed as the second argument. */

Source from the content-addressed store, hash-verified

8585** the hash table passed as the second argument.
8586*/
8587static int idxHashAdd(
8588 int *pRc,
8589 IdxHash *pHash,
8590 const char *zKey,
8591 const char *zVal
8592){
8593 int nKey = STRLEN(zKey);
8594 int iHash = idxHashString(zKey, nKey);
8595 int nVal = (zVal ? STRLEN(zVal) : 0);
8596 IdxHashEntry *pEntry;
8597 assert( iHash>=0 );
8598 for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){
8599 if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){
8600 return 1;
8601 }
8602 }
8603 pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
8604 if( pEntry ){
8605 pEntry->zKey = (char*)&pEntry[1];
8606 memcpy(pEntry->zKey, zKey, nKey);
8607 if( zVal ){
8608 pEntry->zVal = &pEntry->zKey[nKey+1];
8609 memcpy(pEntry->zVal, zVal, nVal);
8610 }
8611 pEntry->pHashNext = pHash->aHash[iHash];
8612 pHash->aHash[iHash] = pEntry;
8613
8614 pEntry->pNext = pHash->pFirst;
8615 pHash->pFirst = pEntry;
8616 }
8617 return 0;
8618}
8619
8620/*
8621** If zKey/nKey is present in the hash table, return a pointer to the

Callers 2

idxCreateFromConsFunction · 0.85
idxFindIndexesFunction · 0.85

Calls 2

idxHashStringFunction · 0.85
idxMallocFunction · 0.85

Tested by

no test coverage detected