[Bf-blender-cvs] [b6f0c9e] temp-ghash-setops: Some improvements/tweaks from review.
Bastien Montagne
noreply at git.blender.org
Fri Mar 20 16:58:27 CET 2015
Commit: b6f0c9e25ad8071a979f06eec148dffbb21931d9
Author: Bastien Montagne
Date: Fri Mar 20 15:15:26 2015 +0100
Branches: temp-ghash-setops
https://developer.blender.org/rBb6f0c9e25ad8071a979f06eec148dffbb21931d9
Some improvements/tweaks from review.
===================================================================
M source/blender/blenlib/intern/BLI_ghash.c
M tests/gtests/blenlib/BLI_ghash_test.cc
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index fbcc603..975a583 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -603,7 +603,7 @@ static GHash *ghash_copy(GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP val
* If \a gh1 is NULL, a new GHash will be created first (avoids modifying \a gh1 in place).
* If \a reverse is True, entries present in latest GHash will override those in former GHash.
*/
-static GHash *ghash_union(
+static GHash *ghash_merge(
const bool reverse,
GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
@@ -1159,6 +1159,7 @@ bool BLI_ghash_isdisjoint(GHash *gh1, GHash *gh2)
/* Note: For now, take a basic, brute force approach.
* If we switch from modulo to masking, we may have ways to optimize this, though. */
unsigned int i;
+ const bool need_hashing = (gh1->nbuckets != gh2->nbuckets);
BLI_assert(gh1->cmpfp == gh2->cmpfp);
BLI_assert(gh1->hashfp == gh2->hashfp);
@@ -1172,8 +1173,7 @@ bool BLI_ghash_isdisjoint(GHash *gh1, GHash *gh2)
Entry *e;
for (e = gh1->buckets[i]; e; e = e->next) {
- const unsigned int hash = ghash_entryhash(gh1, e);
- const unsigned int gh2_bucket_index = ghash_bucket_index(gh2, hash);
+ const unsigned int gh2_bucket_index = need_hashing ? ghash_bucket_index(gh2, ghash_entryhash(gh2, e)) : i;
if (ghash_lookup_entry_ex(gh2, e->key, gh2_bucket_index)) {
return false;
}
@@ -1189,6 +1189,7 @@ bool BLI_ghash_isdisjoint(GHash *gh1, GHash *gh2)
bool BLI_ghash_isequal(GHash *gh1, GHash *gh2)
{
unsigned int i;
+ const bool need_hashing = (gh1->nbuckets != gh2->nbuckets);
BLI_assert(gh1->cmpfp == gh2->cmpfp);
BLI_assert(gh1->hashfp == gh2->hashfp);
@@ -1201,8 +1202,7 @@ bool BLI_ghash_isequal(GHash *gh1, GHash *gh2)
Entry *e;
for (e = gh1->buckets[i]; e; e = e->next) {
- const unsigned int hash = ghash_entryhash(gh1, e);
- unsigned int gh2_bucket_index = ghash_bucket_index(gh2, hash);
+ const unsigned int gh2_bucket_index = need_hashing ? ghash_bucket_index(gh2, ghash_entryhash(gh2, e)) : i;
if (!ghash_lookup_entry_ex(gh2, e->key, gh2_bucket_index)) {
return false;
}
@@ -1221,6 +1221,7 @@ bool BLI_ghash_isequal(GHash *gh1, GHash *gh2)
bool BLI_ghash_issubset(GHash *gh1, GHash *gh2)
{
unsigned int i;
+ const bool need_hashing = (gh1->nbuckets != gh2->nbuckets);
BLI_assert(gh1->cmpfp == gh2->cmpfp);
BLI_assert(gh1->hashfp == gh2->hashfp);
@@ -1233,8 +1234,7 @@ bool BLI_ghash_issubset(GHash *gh1, GHash *gh2)
Entry *e;
for (e = gh2->buckets[i]; e; e = e->next) {
- const unsigned int hash = ghash_entryhash(gh2, e);
- const unsigned int gh1_bucket_index = ghash_bucket_index(gh1, hash);
+ const unsigned int gh1_bucket_index = need_hashing ? ghash_bucket_index(gh1, ghash_entryhash(gh1, e)) : i;
if (!ghash_lookup_entry_ex(gh1, e->key, gh1_bucket_index)) {
return false;
}
@@ -1719,7 +1719,7 @@ GSet *BLI_gset_union(GSetKeyCopyFP keycopyfp, GSet *gs1, GSet *gs2, ...)
va_list arg;
va_start(arg, gs2);
- gs_ret = (GSet *)ghash_union(false, keycopyfp, NULL, NULL, NULL, (GHash *)gs1, (GHash *)gs2, arg);
+ gs_ret = (GSet *)ghash_merge(false, keycopyfp, NULL, NULL, NULL, (GHash *)gs1, (GHash *)gs2, arg);
va_end(arg);
return gs_ret;
diff --git a/tests/gtests/blenlib/BLI_ghash_test.cc b/tests/gtests/blenlib/BLI_ghash_test.cc
index 90d0d28..2903406 100644
--- a/tests/gtests/blenlib/BLI_ghash_test.cc
+++ b/tests/gtests/blenlib/BLI_ghash_test.cc
@@ -255,7 +255,7 @@ TEST(ghash, Subset)
}
/* Check Union (straight only since no ghash ops here). */
-TEST(ghash, Union)
+TEST(gset, Union)
{
GSet *gset_1 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
GSet *gset_2 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
@@ -308,7 +308,7 @@ TEST(ghash, Union)
}
/* Check Intersection. */
-TEST(ghash, Intersection)
+TEST(gset, Intersection)
{
GSet *gset_1 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
GSet *gset_2 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
@@ -350,7 +350,7 @@ TEST(ghash, Intersection)
}
/* Check Difference. */
-TEST(ghash, Difference)
+TEST(gset, Difference)
{
GSet *gset_1 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
GSet *gset_2 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
@@ -392,7 +392,7 @@ TEST(ghash, Difference)
}
/* Check Symmetric Difference. */
-TEST(ghash, SymmDiff)
+TEST(gset, SymmDiff)
{
GSet *gset_1 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
GSet *gset_2 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
More information about the Bf-blender-cvs
mailing list