MCPcopy Create free account
hub / github.com/F-Stack/f-stack / _dictKeyIndex

Function _dictKeyIndex

app/redis-6.2.6/src/dict.c:1028–1051  ·  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

1026 * Note that if we are in the process of rehashing the hash table, the
1027 * index is always returned in the context of the second (new) hash table. */
1028static long _dictKeyIndex(dict *d, const void *key, uint64_t hash, dictEntry **existing)
1029{
1030 unsigned long idx, table;
1031 dictEntry *he;
1032 if (existing) *existing = NULL;
1033
1034 /* Expand the hash table if needed */
1035 if (_dictExpandIfNeeded(d) == DICT_ERR)
1036 return -1;
1037 for (table = 0; table <= 1; table++) {
1038 idx = hash & d->ht[table].sizemask;
1039 /* Search if this slot does not already contain the given key */
1040 he = d->ht[table].table[idx];
1041 while(he) {
1042 if (key==he->key || dictCompareKeys(d, key, he->key)) {
1043 if (existing) *existing = he;
1044 return -1;
1045 }
1046 he = he->next;
1047 }
1048 if (!dictIsRehashing(d)) break;
1049 }
1050 return idx;
1051}
1052
1053void dictEmpty(dict *d, void(callback)(void*)) {
1054 _dictClear(d,&d->ht[0],callback);

Callers 1

dictAddRawFunction · 0.70

Calls 1

_dictExpandIfNeededFunction · 0.70

Tested by

no test coverage detected