diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-07-14 17:59:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-07-14 17:59:47 +0400 |
commit | 8554fa2fad63c20ff0c23894ad0b41087d149a32 (patch) | |
tree | 5fffd70a0875d1de39e566f212b2dbe9debbceb7 /source/blender/blenlib/intern/edgehash.c | |
parent | 8a04bed7240d5bca7de4eb1dcbb8415692ece8c1 (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/edgehash.c')
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index aa571bbc1c5..b4b3f0dbda3 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -623,3 +623,38 @@ void BLI_edgeset_free(EdgeSet *es) } /** \} */ + +/** \name Debugging & Introspection + * \{ */ +#ifdef DEBUG + +/** + * Measure how well the hash function performs + * (1.0 is approx as good as random distribution). + */ +double BLI_edgehash_calc_quality(EdgeHash *eh) +{ + uint64_t sum = 0; + unsigned int i; + + if (eh->nentries == 0) + return -1.0; + + for (i = 0; i < eh->nbuckets; i++) { + uint64_t count = 0; + EdgeEntry *e; + for (e = eh->buckets[i]; e; e = e->next) { + count += 1; + } + sum += count * (count + 1); + } + return ((double)sum * (double)eh->nbuckets / + ((double)eh->nentries * (eh->nentries + 2 * eh->nbuckets - 1))); +} +double BLI_edgeset_calc_quality(EdgeSet *es) +{ + return BLI_edgehash_calc_quality((EdgeHash *)es); +} + +#endif +/** \} */ |