[Bf-blender-cvs] [9312b7b] temp-ghash-experiments: Add some real ghash tests.

Bastien Montagne noreply at git.blender.org
Sun Mar 1 21:28:15 CET 2015


Commit: 9312b7b3228d128e4f398edc8a1b59085a40b9a3
Author: Bastien Montagne
Date:   Sun Mar 1 17:40:12 2015 +0100
Branches: temp-ghash-experiments
https://developer.blender.org/rB9312b7b3228d128e4f398edc8a1b59085a40b9a3

Add some real ghash tests.

Those checks code behaves as expected, not its performances!

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

M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c
M	tests/gtests/blenlib/CMakeLists.txt

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

diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index c91fa53..41fe923 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -246,6 +246,9 @@ BLI_INLINE bool BLI_gsetIterator_done(GSetIterator *gsi) { return BLI_ghashItera
 	     BLI_gsetIterator_done(&gs_iter_) == false;                           \
 	     BLI_gsetIterator_step(&gs_iter_), i_++)
 
+int BLI_ghash_buckets_size(GHash *gh);
+int BLI_gset_buckets_size(GSet *gs);
+
 double BLI_ghash_calc_quality(
         GHash *gh, double *r_load, double *r_variance,
         double *r_prop_empty_buckets, double *r_prop_overloaded_buckets, int *r_biggest_bucket);
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index c52b2a5..a1f673d 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -1191,6 +1191,22 @@ GSet *BLI_gset_pair_new(const char *info)
 #include "BLI_math.h"
 
 /**
+ * \return number of buckets in the GHash.
+ */
+int BLI_ghash_buckets_size(GHash *gh)
+{
+#ifdef GHASH_USE_MODULO_BUCKETS
+	return hashsizes[gh->cursize];
+#else
+	return 1 << gh->bucket_bit;
+#endif
+}
+int BLI_set_buckets_size(GSet *gs)
+{
+	return BLI_ghash_buckets_size((GHash *)gs);
+}
+
+/**
  * Measure how well the hash function performs (1.0 is approx as good as random distribution),
  * and return a few other stats like load, variance of the distribution of the entries in the buckets, etc.
  *
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index d915992..152b656 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -43,4 +43,6 @@ BLENDER_TEST(BLI_path_util "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}")
 BLENDER_TEST(BLI_polyfill2d "bf_blenlib")
 BLENDER_TEST(BLI_listbase "bf_blenlib")
 BLENDER_TEST(BLI_hash_mm2a "bf_blenlib")
+BLENDER_TEST(BLI_ghash "bf_blenlib")
+
 BLENDER_TEST(BLI_ghash_performance "bf_blenlib")




More information about the Bf-blender-cvs mailing list