[Bf-blender-cvs] [4e3bc21] temp-ghash-setops: Remove public GHash API for union/inter/diff/symmdiff.

Bastien Montagne noreply at git.blender.org
Fri Mar 20 12:07:22 CET 2015


Commit: 4e3bc21492b6ea3e78766ff3ab4446c3c88399e2
Author: Bastien Montagne
Date:   Fri Mar 20 12:00:00 2015 +0100
Branches: temp-ghash-setops
https://developer.blender.org/rB4e3bc21492b6ea3e78766ff3ab4446c3c88399e2

Remove public GHash API for union/inter/diff/symmdiff.

This is dead easy to add back when we want (or use other naming if we really
like them better), core code remains exactly the same anyway.

Note we keep checks (isdisjoint, isequal, etc.) for ghashes though, those are
pure-keys non-modifying operations anyway, so here set ops for ghash are
definitively valid (equivalent of set ops on dict.keys() views in py).

===================================================================

M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c
M	tests/gtests/blenlib/BLI_ghash_test.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index 49af452..7769391 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -94,24 +94,6 @@ bool   BLI_ghash_isequal(GHash *gh1, GHash *gh2);
 bool   BLI_ghash_issubset(GHash *gh1, GHash *gh2);
 bool   BLI_ghash_issuperset(GHash *gh1, GHash *gh2);
 
-GHash *BLI_ghash_union(GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp, GHash *gh1, GHash *gh2, ...);
-GHash *BLI_ghash_union_reversed(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...);
-GHash *BLI_ghash_intersection(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...);
-GHash *BLI_ghash_difference(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...);
-GHash *BLI_ghash_symmetric_difference(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...);
-
 /* *** */
 
 GHashIterator *BLI_ghashIterator_new(GHash *gh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index a497782..fbcc603 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -1255,121 +1255,6 @@ bool BLI_ghash_issuperset(GHash *gh1, GHash *gh2)
 	return BLI_ghash_issubset(gh2, gh1);
 }
 
-/**
- * Union, from left to right.
- * Similar to python's \a PyDict_Merge(a, b, false).
- * If \a gh1 is NULL, a new GHash is returned, otherwise \a gh1 is modified in place.
- *
- * Notes:
- *     * All given GHash shall share the same comparison and hashing functions!
- *     * All given GHash **must** be valid GHash (no GSet allowed here).
- */
-GHash *BLI_ghash_union(GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp, GHash *gh1, GHash *gh2, ...)
-{
-	GHash *gh_ret;
-	va_list arg;
-
-	va_start(arg, gh2);
-	gh_ret = ghash_union(false, keycopyfp, valcopyfp, NULL, NULL, gh1, gh2, arg);
-	va_end(arg);
-
-	return gh_ret;
-}
-
-/**
- * Union, from right to left (less efficient, since it may have to allocate and then free key/val pairs).
- * Similar to python's \a PyDict_Merge(a, b, true).
- * If \a gh1 is NULL, a new GHash is returned, otherwise \a gh1 is modified in place and returned.
- *
- * Notes:
- *     * All given GHash shall share the same comparison and hashing functions!
- *     * All given GHash **must** be valid GHash (no GSet allowed here).
- */
-GHash *BLI_ghash_union_reversed(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...)
-{
-	GHash *gh_ret;
-	va_list arg;
-
-	va_start(arg, gh2);
-	gh_ret = ghash_union(true, keycopyfp, valcopyfp, keyfreefp, valfreefp, gh1, gh2, arg);
-	va_end(arg);
-
-	return gh_ret;
-}
-
-/**
- * Intersection (i.e. entries which keys exist in all gh1, gh2, ...).
- * If \a gh1 is NULL, a new GHash is returned, otherwise \a gh1 is modified in place and returned.
- *
- * Notes:
- *     * All given GHash shall share the same comparison and hashing functions!
- *     * First given GHash **must** be a valid GHash, subsequent ones may be GSet.
- */
-GHash *BLI_ghash_intersection(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...)
-{
-	GHash *gh_ret;
-	va_list arg;
-
-	va_start(arg, gh2);
-	gh_ret = ghash_intersection(keycopyfp, valcopyfp, keyfreefp, valfreefp, gh1, gh2, arg);
-	va_end(arg);
-
-	return gh_ret;
-}
-
-/**
- * Difference, i.e. remove all entries in \a gh1 which keys are present in \a gh2 or any subsequent given GHash.
- * If \a gh1 is NULL, a new GHash is returned, otherwise \a gh1 is modified in place and returned.
- *
- * Notes:
- *     * All given GHash shall share the same comparison and hashing functions!
- *     * First given GHash **must** be a valid GHash, subsequent ones may be GSet.
- */
-GHash *BLI_ghash_difference(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...)
-{
-	GHash *gh_ret;
-	va_list arg;
-
-	va_start(arg, gh2);
-	gh_ret = ghash_difference(keycopyfp, valcopyfp, keyfreefp, valfreefp, gh1, gh2, arg);
-	va_end(arg);
-
-	return gh_ret;
-}
-
-/**
- * Symmetric difference,
- * i.e. such as \a gh1 to only contain entries which keys are present in one and only one of all given ghash.
- * If \a gh1 is NULL, a new GHash is returned, otherwise \a gh1 is modified in place and returned.
- *
- * Notes:
- *     * All given GHash shall share the same comparison and hashing functions!
- *     * All given GHash **must** be valid GHash (no GSet allowed here).
- */
-GHash *BLI_ghash_symmetric_difference(
-        GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp,
-        GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp,
-        GHash *gh1, GHash *gh2, ...)
-{
-	GHash *gh_ret;
-	va_list arg;
-
-	va_start(arg, gh2);
-	gh_ret = ghash_symmetric_difference(keycopyfp, valcopyfp, keyfreefp, valfreefp, gh1, gh2, arg);
-	va_end(arg);
-
-	return gh_ret;
-}
-
 /** \} */
 
 
diff --git a/tests/gtests/blenlib/BLI_ghash_test.cc b/tests/gtests/blenlib/BLI_ghash_test.cc
index 8998774..90d0d28 100644
--- a/tests/gtests/blenlib/BLI_ghash_test.cc
+++ b/tests/gtests/blenlib/BLI_ghash_test.cc
@@ -15,13 +15,14 @@ extern "C" {
 /* Only keeping this in case here, for now. */
 #define PRINTF_GHASH_STATS(_gh) \
 { \
+	GHash *__gh = (GHash *)(_gh); \
 	double q, lf, var, pempty, poverloaded; \
 	int bigb; \
-	q = BLI_ghash_calc_quality_ex((_gh), &lf, &var, &pempty, &poverloaded, &bigb); \
+	q = BLI_ghash_calc_quality_ex(__gh, &lf, &var, &pempty, &poverloaded, &bigb); \
 	printf("GHash stats (%d entries):\n\t" \
 	       "Quality (the lower the better): %f\n\tVariance (the lower the better): %f\n\tLoad: %f\n\t" \
 	       "Empty buckets: %.2f%%\n\tOverloaded buckets: %.2f%% (biggest bucket: %d)\n", \
-	       BLI_ghash_size(_gh), q, var, lf, pempty * 100.0, poverloaded * 100.0, bigb); \
+	       BLI_ghash_size(__gh), q, var, lf, pempty * 100.0, poverloaded * 100.0, bigb); \
 } void (0)
 
 /* Note: for pure-ghash testing, nature of the keys and data have absolutely no importance! So here we just use mere
@@ -253,33 +254,31 @@ TEST(ghash, Subset)
 	BLI_ghash_free(ghash_2, NULL, NULL);
 }
 
-/* Check Union (straight and reversed). */
+/* Check Union (straight only since no ghash ops here). */
 TEST(ghash, Union)
 {
-	GHash *ghash_1 = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
-	GHash *ghash_2 = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
-	GHash *ghash_U, *ghash_U_rev;
+	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__);
+	GSet *gset_U;
 	unsigned int keys[TESTCASE_SIZE], *k;
 	int i;
 
 	init_keys(keys, 70);
 
 	for (i = TESTCASE_SIZE / 2, k = keys; i--; k++) {
-		BLI_ghash_insert(ghash_1, SET_UINT_IN_POINTER(*k), SET_UINT_IN_POINTER(*k));
+		BLI_gset_insert(gset_1, SET_UINT_IN_POINTER(*k));
 	}
 	for (i = 0, k = keys; i < TESTCASE_SIZE / 2; i++, k++) {
-		/* Because values should have no effect at all here. */
-		BLI_ghash_insert(ghash_2, SET_UINT_IN_POINTER(*k), SET_INT_IN_POINTER(i));
+		BLI_gset_insert(gset_2, SET_UINT_IN_POINTER(*k));
 	}
 
-	EXPECT_TRUE(BLI_ghash_isequal(ghash_1, ghash_2));
+	EXPECT_TRUE(BLI_gset_isequal(gset_1, gset_2));
 
-	ghash_U = BLI_ghash_union(NULL, NULL, NULL, ghash_1, ghash_2, NULL);
-	ghash_U_rev = BLI_ghash_union_reversed(NULL, NULL, NULL, NULL, NULL, ghash_1, ghash_2, NULL);
+	gset_U = BLI_gset_union(NULL, NULL, gset_1, gset_2, NULL);
 
-	EXPECT_TRUE(BLI_ghash_isequal(ghash_U, ghash_1));
-	EXPECT_TRUE(BLI_ghash_isequal(ghash_U_rev, ghash_1));
+	EXPECT_TRUE(BLI_gset_isequal(gset_U, gset_1));
 
+#if 0  /* Checking validity of values handling, not applicable to gset :/ */
 	for (i = 0, k = keys; i < TESTCASE_SIZE / 2; i++, k++) {
 		void *v = BLI_ghash_lookup(ghash_U, SET_UINT_IN_POINTER(*k));
 		EXPECT_EQ(*k, GET_UINT_FROM_POINTER(v));
@@ -287,164 +286,157 @@ TEST(ghash, Union)
 		v = BLI_ghash_lookup(ghash_U_rev, SET_UINT_IN_POINTER(*k));
 		EXPECT_EQ(i, GET_INT_FROM_POINTER(v));
 	}
+#endif
 
-	BLI_ghash_free(ghash_2, NULL, NULL);
-	BLI_ghash_free(ghash_U, NULL, NULL);
-	ghash_2 = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+	BLI_gset_free(gset_2, NULL);
+	BLI_gset_free(gset_U, NULL);
+	gset_2 = BLI_gset_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
 	for (i = TESTCASE_SIZE / 2, k = &keys[i]; i < TESTCASE_SIZE; i++, k++) {
-		/* Because values should have no effect at all here. */
-		BLI_ghash_insert(ghash_2, SET_UINT_IN_POINTER(*k), SET_INT_IN_POINTER(i));
+		BLI_gset_insert(gset_2, SET_UINT_IN_POINTER(*k));
 	}
 
-	EXPECT_TRUE(BLI_ghash_isdisjoint(ghash_1, ghash_2));
+	EXPECT_TRUE(BLI_gset_isdisjoint(gset_1, gset_2));
 
-	ghash_U = BLI_ghash_union(NULL, NULL, NULL, ghash_1, ghash_2, NULL);
+	gset_U = BLI_gset_union(NULL, NULL, gset_1, gset_2, NULL);
 
-	EXPECT_TRUE(BLI_ghash_issubset(ghash_U, ghash_1));
-	EXPECT_TRUE(BLI_ghash_issubset(ghash_U, ghash_2));
+	EXPECT_TRUE(BLI_gset_issubset(gset_U, gset_1));
+	EXPECT_TRUE(BLI_gset_issubset(gset_U, gset_2));
 
-	BLI_ghash_free(ghash_1, NULL, NULL);
-	BLI_ghash_free(ghash_2, NULL, NULL);
-	BLI_ghash_free(ghash_U, NULL, NULL);
-	BLI_ghash_free(ghash_U_rev, NULL, NULL);
+	BLI_gset_free(gset_1, NULL);
+	BLI_gset_free(gset_2, NULL);
+	BLI_gset_free(gset_U, NULL);
 }
 
 /* Check Intersection. */
 TEST(ghash, Intersection)
 {
-	GHash *ghash_1 = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
-	GHash *ghash_2 = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
-	GHash *ghash_I;
+	GSet *gset_1

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list