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 | |
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')
-rw-r--r-- | source/blender/blenlib/BLI_edgehash.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_ghash.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 19 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 7 |
4 files changed, 26 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h index 8e74ce3a9e3..c0529d9032d 100644 --- a/source/blender/blenlib/BLI_edgehash.h +++ b/source/blender/blenlib/BLI_edgehash.h @@ -102,7 +102,7 @@ EdgeSet *BLI_edgeset_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; EdgeSet *BLI_edgeset_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; int BLI_edgeset_size(EdgeSet *es) ATTR_WARN_UNUSED_RESULT; -bool BLI_edgeset_reinsert(EdgeSet *es, unsigned int v0, unsigned int v1); +bool BLI_edgeset_add(EdgeSet *es, unsigned int v0, unsigned int v1); void BLI_edgeset_insert(EdgeSet *es, unsigned int v0, unsigned int v1); bool BLI_edgeset_haskey(EdgeSet *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; void BLI_edgeset_free(EdgeSet *es); diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index 2aa79d6da8d..947386dc934 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -191,6 +191,7 @@ GSet *BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) ATTR_M int BLI_gset_size(GSet *gs) ATTR_WARN_UNUSED_RESULT; void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp); void BLI_gset_insert(GSet *gh, void *key); +bool BLI_gset_add(GSet *gs, void *key); bool BLI_gset_reinsert(GSet *gh, void *key, GSetKeyFreeFP keyfreefp); bool BLI_gset_haskey(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; bool BLI_gset_remove(GSet *gs, void *key, GSetKeyFreeFP keyfreefp); 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 * diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 51a22cc46ab..173d2a5a590 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -588,9 +588,12 @@ void BLI_edgeset_insert(EdgeSet *es, unsigned int v0, unsigned int v1) } /** - * Assign a new value to a key that may already be in edgehash. + * A version of BLI_edgeset_insert which checks first if the key is in the set. + * \returns true if a new key has been added. + * + * \note EdgeHash has no equivalent to this because typically the value would be different. */ -bool BLI_edgeset_reinsert(EdgeSet *es, unsigned int v0, unsigned int v1) +bool BLI_edgeset_add(EdgeSet *es, unsigned int v0, unsigned int v1) { unsigned int hash; EdgeEntry *e; |