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

Function dictAddRaw

app/redis-6.2.6/src/dict.c:319–345  ·  view source on GitHub ↗

Low level add or find: * This function adds the entry but instead of setting a value returns the * dictEntry structure to the user, that will make sure to fill the value * field as they wish. * * This function is also directly exposed to the user API to be called * mainly in order to store non-pointers inside the hash value, example: * * entry = dictAddRaw(dict,mykey,NULL); * if (entry !=

Source from the content-addressed store, hash-verified

317 * If key was added, the hash entry is returned to be manipulated by the caller.
318 */
319dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
320{
321 long index;
322 dictEntry *entry;
323 dictht *ht;
324
325 if (dictIsRehashing(d)) _dictRehashStep(d);
326
327 /* Get the index of the new element, or -1 if
328 * the element already exists. */
329 if ((index = _dictKeyIndex(d, key, dictHashKey(d,key), existing)) == -1)
330 return NULL;
331
332 /* Allocate the memory and store the new entry.
333 * Insert the element in top, with the assumption that in a database
334 * system it is more likely that recently added entries are accessed
335 * more frequently. */
336 ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
337 entry = zmalloc(sizeof(*entry));
338 entry->next = ht->table[index];
339 ht->table[index] = entry;
340 ht->used++;
341
342 /* Set the hash entry fields. */
343 dictSetKey(d, entry, key);
344 return entry;
345}
346
347/* Add or Overwrite:
348 * Add an element, discarding the old value if the key already exists.

Callers 7

dictAddFunction · 0.85
dictReplaceFunction · 0.85
dictAddOrFindFunction · 0.85
sentinelLeaderIncrFunction · 0.85
setTypeAddFunction · 0.85

Calls 3

_dictRehashStepFunction · 0.85
zmallocFunction · 0.85
_dictKeyIndexFunction · 0.70

Tested by

no test coverage detected