/** * Inserts a new value to a key that may already be in ghash. * * Avoids #BLI_smallhash_remove, #BLI_smallhash_insert calls (double lookups) * * \returns true if a new key has been added. */ bool BLI_smallhash_reinsert(SmallHash *sh, uintptr_t key, void *item) { SmallHashEntry *e = smallhash_lookup(sh, key); if (e) { e->val = item; return false; } else { BLI_smallhash_insert(sh, key, item); return true; } }
bool BLI_smallhash_remove(SmallHash *sh, uintptr_t key) { SmallHashEntry *e = smallhash_lookup(sh, key); if (e) { e->key = SMHASH_KEY_UNUSED; e->val = SMHASH_CELL_UNUSED; sh->nentries--; return true; } else { return false; } }
bool BLI_smallhash_haskey(SmallHash *sh, uintptr_t key) { SmallHashEntry *e = smallhash_lookup(sh, key); return (e != NULL); }
void *BLI_smallhash_lookup(SmallHash *sh, uintptr_t key) { SmallHashEntry *e = smallhash_lookup(sh, key); return e ? e->val : NULL; }