diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-05-29 08:00:11 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-06-13 18:47:12 +0400 |
commit | 365ff6698700fb23c8bd9d0509c49df71180431e (patch) | |
tree | 9f94247268e14830338cd8fdb8bdbb2a26f78bc7 /source/blender/blenlib/intern/BLI_ghash.c | |
parent | 8bd4b7361bb47d5ecaf005ef04ec58cdf73a3a48 (diff) |
GSet, GHash: Add BLI_gset_add, since its common to add members to a set
also rename BLI_edgeset_reinsert -> BLI_edgeset_add, in this case its the same.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_ghash.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index e55f20e99eb..b30553d0b5e 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -901,6 +901,25 @@ void BLI_gset_insert(GSet *gs, void *key) } /** + * A version of BLI_gset_insert which checks first if the key is in the set. + * \returns true if a new key has been added. + * + * \note GHash has no equivalent to this because typically the value would be different. + */ +bool BLI_gset_add(GSet *gs, void *key) +{ + const unsigned int hash = ghash_keyhash((GHash *)gs, key); + Entry *e = ghash_lookup_entry_ex((GHash *)gs, key, hash); + if (e) { + return false; + } + else { + ghash_insert_ex_keyonly((GHash *)gs, key, hash); + return true; + } +} + +/** * Adds the key to the set (duplicates are managed). * Matching #BLI_ghash_reinsert * |