aboutsummaryrefslogtreecommitdiff
path: root/common/hashmap.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-06-13 21:07:05 +0000
committerWillem Jan Palenstijn2009-06-13 21:07:05 +0000
commit6eed461c94bb04391b759c4bfed88588a8d170c1 (patch)
treeb92adbd07048a87bd60d8e2e7d7476c2e3a3f2aa /common/hashmap.cpp
parentcca9202372e5b8b9f6b5350488da26e4bd3ab8bc (diff)
downloadscummvm-rg350-6eed461c94bb04391b759c4bfed88588a8d170c1.tar.gz
scummvm-rg350-6eed461c94bb04391b759c4bfed88588a8d170c1.tar.bz2
scummvm-rg350-6eed461c94bb04391b759c4bfed88588a8d170c1.zip
Fix erase() sometimes hiding other hash elements.
Like CPython, we now use a dummy node to mark nodes as erased, so that lookup() can skip over it. All tests should now pass again. svn-id: r41496
Diffstat (limited to 'common/hashmap.cpp')
-rw-r--r--common/hashmap.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/common/hashmap.cpp b/common/hashmap.cpp
index 0fb03ec3f8..d8b84f61a5 100644
--- a/common/hashmap.cpp
+++ b/common/hashmap.cpp
@@ -58,6 +58,7 @@ uint hashit_lower(const char *p) {
#ifdef DEBUG_HASH_COLLISIONS
static double
g_collisions = 0,
+ g_dummyHits = 0,
g_lookups = 0,
g_collPerLook = 0,
g_capacity = 0,
@@ -66,9 +67,10 @@ static int g_max_capacity = 0, g_max_size = 0;
static int g_totalHashmaps = 0;
static int g_stats[4] = {0,0,0,0};
-void updateHashCollisionStats(int collisions, int lookups, int arrsize, int nele) {
+void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int arrsize, int nele) {
g_collisions += collisions;
g_lookups += lookups;
+ g_dummyHits += dummyHits;
if (lookups)
g_collPerLook += (double)collisions / (double)lookups;
g_capacity += arrsize;
@@ -87,9 +89,10 @@ void updateHashCollisionStats(int collisions, int lookups, int arrsize, int nele
g_max_capacity = MAX(g_max_capacity, arrsize);
g_max_size = MAX(g_max_size, nele);
- fprintf(stdout, "%d hashmaps: colls %.1f; lookups %.1f; ratio %.3f%%; size %f (max: %d); capacity %f (max: %d)\n",
+ fprintf(stdout, "%d hashmaps: colls %.1f; dummies hit %.1f, lookups %.1f; ratio %.3f%%; size %f (max: %d); capacity %f (max: %d)\n",
g_totalHashmaps,
g_collisions / g_totalHashmaps,
+ g_dummyHits / g_totalHashmaps,
g_lookups / g_totalHashmaps,
100 * g_collPerLook / g_totalHashmaps,
g_size / g_totalHashmaps, g_max_size,