Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-07-14 17:59:47 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-07-14 17:59:47 +0400
commit8554fa2fad63c20ff0c23894ad0b41087d149a32 (patch)
tree5fffd70a0875d1de39e566f212b2dbe9debbceb7 /source/blender/blenlib/intern/BLI_ghash.c
parent8a04bed7240d5bca7de4eb1dcbb8415692ece8c1 (diff)
GHash, EdgeHash: add debugging function to measure the hash quality
Can use to check on improvements to hash functions.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_ghash.c')
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index b30553d0b5e..d24c180dae6 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -996,3 +996,39 @@ GSet *BLI_gset_pair_new(const char *info)
}
/** \} */
+
+
+/** \name Debugging & Introspection
+ * \{ */
+#ifdef DEBUG
+
+/**
+ * Measure how well the hash function performs
+ * (1.0 is approx as good as random distribution).
+ */
+double BLI_ghash_calc_quality(GHash *gh)
+{
+ uint64_t sum = 0;
+ unsigned int i;
+
+ if (gh->nentries == 0)
+ return -1.0;
+
+ for (i = 0; i < gh->nbuckets; i++) {
+ uint64_t count = 0;
+ Entry *e;
+ for (e = gh->buckets[i]; e; e = e->next) {
+ count += 1;
+ }
+ sum += count * (count + 1);
+ }
+ return ((double)sum * (double)gh->nbuckets /
+ ((double)gh->nentries * (gh->nentries + 2 * gh->nbuckets - 1)));
+}
+double BLI_gset_calc_quality(GSet *gs)
+{
+ return BLI_ghash_calc_quality((GHash *)gs);
+}
+
+#endif
+/** \} */