Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/BLI_ghash.c
| Show First 20 Lines • Show All 1,474 Lines • ▼ Show 20 Lines | |||||
| bool BLI_gset_haskey(GSet *gs, const void *key) | bool BLI_gset_haskey(GSet *gs, const void *key) | ||||
| { | { | ||||
| return (ghash_lookup_entry((GHash *)gs, key) != NULL); | return (ghash_lookup_entry((GHash *)gs, key) != NULL); | ||||
| } | } | ||||
| /** | /** | ||||
| * Returns the pointer to the key if it's found. | |||||
| */ | |||||
| void *BLI_gset_lookup(GSet *gs, const void *key) | |||||
| { | |||||
| Entry *e = ghash_lookup_entry((GHash *)gs, key); | |||||
| return e ? e->key : NULL; | |||||
| } | |||||
| /** | |||||
| * Returns the pointer to the key if it's found. | |||||
| */ | |||||
| void *BLI_gset_pop_key(GSet *gs, const void *key) | |||||
| { | |||||
| const unsigned int hash = ghash_keyhash((GHash *)gs, key); | |||||
| const unsigned int bucket_index = ghash_bucket_index((GHash *)gs, hash); | |||||
| Entry *e = ghash_remove_ex((GHash *)gs, key, NULL, NULL, bucket_index); | |||||
| if (e) { | |||||
| void *key_ret = e->key; | |||||
| BLI_mempool_free(((GHash *)gs)->entrypool, e); | |||||
| return key_ret; | |||||
| } | |||||
| else { | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Remove a random entry from \a gs, returning true if a key could be removed, false otherwise. | * Remove a random entry from \a gs, returning true if a key could be removed, false otherwise. | ||||
| * | * | ||||
| * \param r_key: The removed key. | * \param r_key: The removed key. | ||||
| * \param state: Used for efficient removal. | * \param state: Used for efficient removal. | ||||
| * \return true if there was something to pop, false if gset was already empty. | * \return true if there was something to pop, false if gset was already empty. | ||||
| */ | */ | ||||
| bool BLI_gset_pop( | bool BLI_gset_pop( | ||||
| GSet *gs, GSetIterState *state, | GSet *gs, GSetIterState *state, | ||||
| ▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines | |||||