** 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. */
| 10428 | ** the hash table passed as the second argument. |
| 10429 | */ |
| 10430 | static int idxHashAdd( |
| 10431 | int *pRc, |
| 10432 | IdxHash *pHash, |
| 10433 | const char *zKey, |
| 10434 | const char *zVal |
| 10435 | ){ |
| 10436 | int nKey = STRLEN(zKey); |
| 10437 | int iHash = idxHashString(zKey, nKey); |
| 10438 | int nVal = (zVal ? STRLEN(zVal) : 0); |
| 10439 | IdxHashEntry *pEntry; |
| 10440 | assert( iHash>=0 ); |
| 10441 | for(pEntry=pHash->aHash[iHash]; pEntry; pEntry=pEntry->pHashNext){ |
| 10442 | if( STRLEN(pEntry->zKey)==nKey && 0==memcmp(pEntry->zKey, zKey, nKey) ){ |
| 10443 | return 1; |
| 10444 | } |
| 10445 | } |
| 10446 | pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1); |
| 10447 | if( pEntry ){ |
| 10448 | pEntry->zKey = (char*)&pEntry[1]; |
| 10449 | memcpy(pEntry->zKey, zKey, nKey); |
| 10450 | if( zVal ){ |
| 10451 | pEntry->zVal = &pEntry->zKey[nKey+1]; |
| 10452 | memcpy(pEntry->zVal, zVal, nVal); |
| 10453 | } |
| 10454 | pEntry->pHashNext = pHash->aHash[iHash]; |
| 10455 | pHash->aHash[iHash] = pEntry; |
| 10456 | |
| 10457 | pEntry->pNext = pHash->pFirst; |
| 10458 | pHash->pFirst = pEntry; |
| 10459 | } |
| 10460 | return 0; |
| 10461 | } |
| 10462 | |
| 10463 | /* |
| 10464 | ** If zKey/nKey is present in the hash table, return a pointer to the |
no test coverage detected