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

Function _dictClear

src/dict.cpp:803–836  ·  view source on GitHub ↗

Destroy an entire dictionary */

Source from the content-addressed store, hash-verified

801
802/* Destroy an entire dictionary */
803int _dictClear(dict *d, dictht *ht, void(callback)(void *)) {
804 unsigned long i;
805
806 /* Free all the elements */
807 for (i = 0; i < ht->size && ht->used > 0; i++) {
808 dictEntry *he, *nextHe;
809
810 if (callback && (i & 65535) == 0) callback(d->privdata);
811
812 if ((he = ht->table[i]) == NULL) continue;
813 dictEntry *deNull = nullptr;
814 __atomic_store(&ht->table[i], &deNull, __ATOMIC_RELEASE);
815 while(he) {
816 nextHe = he->next;
817 if (d->asyncdata && (ssize_t)i < d->rehashidx) {
818 dictFreeVal(d, he);
819 he->v.val = nullptr;
820 he->next = d->asyncdata->deGCList;
821 d->asyncdata->deGCList = he;
822 } else {
823 dictFreeKey(d, he);
824 dictFreeVal(d, he);
825 zfree(he);
826 }
827 ht->used--;
828 he = nextHe;
829 }
830 }
831 /* Free the table and the allocated cache structure */
832 asyncFreeDictTable(ht->table);
833 /* Re-initialize the table */
834 _dictReset(ht);
835 return DICT_OK; /* never fails */
836}
837
838/* Clear & Release the hash table */
839void dictRelease(dict *d)

Callers 2

dictReleaseFunction · 0.70
dictEmptyFunction · 0.70

Calls 3

zfreeFunction · 0.85
asyncFreeDictTableFunction · 0.70
_dictResetFunction · 0.70

Tested by

no test coverage detected