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

Function dictAddRaw

src/dict.cpp:633–659  ·  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

631 * If key was added, the hash entry is returned to be manipulated by the caller.
632 */
633dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
634{
635 long index;
636 dictEntry *entry;
637 dictht *ht;
638
639 if (dictIsRehashing(d)) _dictRehashStep(d);
640
641 /* Get the index of the new element, or -1 if
642 * the element already exists. */
643 if ((index = _dictKeyIndex(d, key, dictHashKey(d,key), existing)) == -1)
644 return NULL;
645
646 /* Allocate the memory and store the new entry.
647 * Insert the element in top, with the assumption that in a database
648 * system it is more likely that recently added entries are accessed
649 * more frequently. */
650 ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
651 entry = (dictEntry*)zmalloc(sizeof(*entry), MALLOC_SHARED);
652 entry->next = ht->table[index];
653 ht->table[index] = entry;
654 ht->used++;
655
656 /* Set the hash entry fields. */
657 dictSetKey(d, entry, key);
658 return entry;
659}
660
661/* Add or Overwrite:
662 * Add an element, discarding the old value if the key already exists.

Callers 10

dictAddFunction · 0.85
dictReplaceFunction · 0.85
dictAddOrFindFunction · 0.85
pushValueMethod · 0.85
createIndexMethod · 0.85
expireSubKeyMethod · 0.85
setTypeAddFunction · 0.85
sentinelLeaderIncrFunction · 0.85

Calls 3

_dictRehashStepFunction · 0.85
zmallocFunction · 0.85
_dictKeyIndexFunction · 0.70

Tested by

no test coverage detected