Extended HashMap debug output

svn-id: r34051
This commit is contained in:
Max Horn 2008-08-20 10:18:59 +00:00
parent 35b02acb39
commit 47429f2197
2 changed files with 35 additions and 0 deletions

View file

@ -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