aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2008-08-20 10:18:59 +0000
committerMax Horn2008-08-20 10:18:59 +0000
commit47429f219750033c011dadfd5e9106cd5bfcb5b9 (patch)
treef3775dba37cccc6304b18c8fc2984577a3d5b9c8
parent35b02acb39f9291a198e49bca425b131ae550096 (diff)
downloadscummvm-rg350-47429f219750033c011dadfd5e9106cd5bfcb5b9.tar.gz
scummvm-rg350-47429f219750033c011dadfd5e9106cd5bfcb5b9.tar.bz2
scummvm-rg350-47429f219750033c011dadfd5e9106cd5bfcb5b9.zip
Extended HashMap debug output
svn-id: r34051
-rw-r--r--common/hashmap.cpp31
-rw-r--r--common/hashmap.h4
2 files changed, 35 insertions, 0 deletions
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<Key, Val, HashFunc, EqualFunc>::~HashMap() {
freeNode(_arr[ctr]);
delete[] _arr;
+#ifdef DEBUG_HASH_COLLISIONS
+ extern void updateHashCollisionStats(int, int, int, int);
+ updateHashCollisionStats(_collisions, _lookups, _arrsize, _nele);
+#endif
}
/**