diff options
-rw-r--r-- | source/blender/blenlib/BLI_edgehash.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_ghash.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 10 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 10 |
4 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h index b4ca25bed4f..8e74ce3a9e3 100644 --- a/source/blender/blenlib/BLI_edgehash.h +++ b/source/blender/blenlib/BLI_edgehash.h @@ -53,6 +53,7 @@ void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp); void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val); bool BLI_edgehash_reinsert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val); void *BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; +void *BLI_edgehash_lookup_default(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val_default) ATTR_WARN_UNUSED_RESULT; void **BLI_edgehash_lookup_p(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; bool BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; int BLI_edgehash_size(EdgeHash *eh) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index d762876a55a..2aa79d6da8d 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -66,6 +66,7 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfre void BLI_ghash_insert(GHash *gh, void *key, void *val); bool BLI_ghash_reinsert(GHash *gh, void *key, void *val, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); void *BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; +void *BLI_ghash_lookup_default(GHash *gh, const void *key, void *val_default) ATTR_WARN_UNUSED_RESULT; void **BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; bool BLI_ghash_remove(GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 1df48885637..7b48744bcdf 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -384,6 +384,16 @@ void *BLI_ghash_lookup(GHash *gh, const void *key) } /** + * A version of #BLI_ghash_lookup which accepts a fallback argument. + */ +void *BLI_ghash_lookup_default(GHash *gh, const void *key, void *val_default) +{ + Entry *e = ghash_lookup_entry(gh, key); + IS_GHASH_ASSERT(gh); + return e ? e->val : val_default; +} + +/** * Lookup a pointer to the value of \a key in \a gh. * * \param key The key to lookup. diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 8558e5773c7..51a22cc46ab 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -356,6 +356,16 @@ void *BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) } /** + * A version of #BLI_edgehash_lookup which accepts a fallback argument. + */ +void *BLI_edgehash_lookup_default(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val_default) +{ + EdgeEntry *e = edgehash_lookup_entry(eh, v0, v1); + IS_EDGEHASH_ASSERT(eh); + return e ? e->val : val_default; +} + +/** * Return boolean true/false if edge (v0,v1) in hash. */ bool BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) |