MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / _dictKeyIndex

Function _dictKeyIndex

src/dict.cpp:1396–1419  ·  view source on GitHub ↗

Returns the index of a free slot that can be populated with * a hash entry for the given 'key'. * If the key already exists, -1 is returned * and the optional output parameter may be filled. * * Note that if we are in the process of rehashing the hash table, the * index is always returned in the context of the second (new) hash table. */

Source from the content-addressed store, hash-verified

1394 * Note that if we are in the process of rehashing the hash table, the
1395 * index is always returned in the context of the second (new) hash table. */
1396long _dictKeyIndex(dict *d, const void *key, uint64_t hash, dictEntry **existing)
1397{
1398 unsigned long idx, table;
1399 dictEntry *he;
1400 if (existing) *existing = NULL;
1401
1402 /* Expand the hash table if needed */
1403 if (_dictExpandIfNeeded(d) == DICT_ERR)
1404 return -1;
1405 for (table = 0; table <= 1; table++) {
1406 idx = hash & d->ht[table].sizemask;
1407 /* Search if this slot does not already contain the given key */
1408 he = d->ht[table].table[idx];
1409 while(he) {
1410 if (key==he->key || dictCompareKeys(d, key, he->key)) {
1411 if (existing) *existing = he;
1412 return -1;
1413 }
1414 he = he->next;
1415 }
1416 if (!dictIsRehashing(d)) break;
1417 }
1418 return idx;
1419}
1420
1421void dictEmpty(dict *d, void(callback)(void*)) {
1422 _dictClear(d,&d->ht[0],callback);

Callers 2

bulkInsertMethod · 0.70
dictAddRawFunction · 0.70

Calls 1

_dictExpandIfNeededFunction · 0.70

Tested by

no test coverage detected