From 47429f219750033c011dadfd5e9106cd5bfcb5b9 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 20 Aug 2008 10:18:59 +0000 Subject: Extended HashMap debug output svn-id: r34051 --- common/hashmap.cpp | 31 +++++++++++++++++++++++++++++++ common/hashmap.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/common/hashmap.cpp b/common/hashmap.cpp index 4749234740..2bd1d48b92 100644 --- a/common/hashmap.cpp +++ b/common/hashmap.cpp @@ -89,5 +89,36 @@ uint nextTableSize(uint x) { return primes[i]; } +#ifdef DEBUG_HASH_COLLISIONS +static double + g_collisions = 0, + g_lookups = 0, + g_collPerLook = 0, + g_arrsize = 0, + g_nele = 0; +static int g_max_arrsize = 0, g_max_nele = 0; +static int g_totalHashmaps = 0; + +void updateHashCollisionStats(int collisions, int lookups, int arrsize, int nele) { + g_collisions += collisions; + g_lookups += lookups; + if (lookups) + g_collPerLook += (double)collisions / (double)lookups; + g_arrsize += arrsize; + g_nele += nele; + g_totalHashmaps++; + + g_max_arrsize = MAX(g_max_arrsize, arrsize); + g_max_nele = MAX(g_max_nele, nele); + + fprintf(stdout, "%d hashmaps: colls %.1f; lookups %.1f; ratio %.3f%%; size %f (max: %d); capacity %f (max: %d)\n", + g_totalHashmaps, + g_collisions / g_totalHashmaps, + g_lookups / g_totalHashmaps, + 100 * g_collPerLook / g_totalHashmaps, + g_nele / g_totalHashmaps, g_max_nele, + g_arrsize / g_totalHashmaps, g_max_arrsize); +} +#endif } // End of namespace Common diff --git a/common/hashmap.h b/common/hashmap.h index 69f367de97..9b819db5e1 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -338,6 +338,10 @@ HashMap::~HashMap() { freeNode(_arr[ctr]); delete[] _arr; +#ifdef DEBUG_HASH_COLLISIONS + extern void updateHashCollisionStats(int, int, int, int); + updateHashCollisionStats(_collisions, _lookups, _arrsize, _nele); +#endif } /** -- cgit v1.2.3