MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / HashTableAddRaw

Function HashTableAddRaw

src/util/dict.c:395–429  ·  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 = HashTableAddRaw(dict,mykey,NULL); * if (ent

Source from the content-addressed store, hash-verified

393 * If key was added, the hash entry is returned to be manipulated by the caller.
394 */
395dictEntry *HashTableAddRaw
396(
397 dict *d,
398 void *key,
399 dictEntry **existing
400) {
401 long index;
402 dictEntry *entry;
403 int htidx;
404
405 if (dictIsRehashing(d)) _dictRehashStep(d);
406
407 /* Get the index of the new element, or -1 if
408 * the element already exists. */
409 if ((index = _dictKeyIndex(d, key, dictHashKey(d,key), existing)) == -1)
410 return NULL;
411
412 /* Allocate the memory and store the new entry.
413 * Insert the element in top, with the assumption that in a database
414 * system it is more likely that recently added entries are accessed
415 * more frequently. */
416 htidx = dictIsRehashing(d) ? 1 : 0;
417 size_t metasize = HashTableEntryMetadataSize(d);
418 entry = malloc(sizeof(*entry) + metasize);
419 if (metasize > 0) {
420 memset(HashTableEntryMetadata(entry), 0, metasize);
421 }
422 entry->next = d->ht_table[htidx][index];
423 d->ht_table[htidx][index] = entry;
424 d->ht_used[htidx]++;
425
426 /* Set the hash entry fields. */
427 HashTableSetKey(d, entry, key);
428 return entry;
429}
430
431/* Add or Overwrite:
432 * Add an element, discarding the old value if the key already exists.

Callers 6

_list2dictFunction · 0.85
AR_DEDUPFunction · 0.85
HashTableAddFunction · 0.85
HashTableReplaceFunction · 0.85
HashTableAddOrFindFunction · 0.85
_GetGroupFunction · 0.85

Calls 4

_dictRehashStepFunction · 0.85
_dictKeyIndexFunction · 0.85
HashTableEntryMetadataFunction · 0.85
HashTableSetKeyFunction · 0.85

Tested by

no test coverage detected