[Scummvm-cvs-logs] SF.net SVN: scummvm: [21432] scummvm/trunk/common/assocarray.h

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Mar 24 09:14:05 CET 2006


Revision: 21432
Author:   fingolfin
Date:     2006-03-24 09:13:24 -0800 (Fri, 24 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21432&view=rev

Log Message:
-----------
Changed the DEBUG_HASH_COLLISIONS feature: Now measures the ratio between lookup collisions and total number of lookups

Modified Paths:
--------------
    scummvm/trunk/common/assocarray.h
Modified: scummvm/trunk/common/assocarray.h
===================================================================
--- scummvm/trunk/common/assocarray.h	2006-03-24 16:53:32 UTC (rev 21431)
+++ scummvm/trunk/common/assocarray.h	2006-03-24 17:13:24 UTC (rev 21432)
@@ -113,7 +113,7 @@
 	uint _arrsize, _nele;
 	
 #ifdef DEBUG_HASH_COLLISIONS
-	mutable int _collisions;
+	mutable int _collisions, _lookups;
 #endif
 
 	int lookup(const Key &key) const;
@@ -154,13 +154,19 @@
 
 	while (_arr[ctr] != NULL && !data_eq(_arr[ctr]->key, key)) {
 		ctr++;
+#ifdef DEBUG_HASH_COLLISIONS
+		_collisions++;
+#endif
 
 		if (ctr == _arrsize)
 			ctr = 0;
 	}
 	
 #ifdef DEBUG_HASH_COLLISIONS
-	fprintf(stderr, "collisions = %d in AssocArray %p\n", _collisions, (const void *)this);
+	_lookups++;
+	fprintf(stderr, "collisions %d, lookups %d, ratio %f in AssocArray %p; size %d num elements %d\n",
+		_collisions, _lookups, ((double) _collisions / (double)_lookups),
+		(const void *)this, _arrsize, _nele);
 #endif
 
 	return ctr;
@@ -239,6 +245,7 @@
 	
 #ifdef DEBUG_HASH_COLLISIONS
 	_collisions = 0;
+	_lookups = 0;
 #endif
 }
 
@@ -303,9 +310,10 @@
 //      (*this)[old_arr[ctr]->key] = old_arr[ctr]->dat;
 		dex = hashit(old_arr[ctr]->key, _arrsize);
 
-		while (_arr[dex] != NULL)
+		while (_arr[dex] != NULL) {
 			if (++dex == _arrsize)
 				dex = 0;
+		}
 
 		_arr[dex] = old_arr[ctr];
 		_nele++;
@@ -326,12 +334,6 @@
 		_arr[ctr] = new aa_ref_t(key);
 		_nele++;
 
-#ifdef DEBUG_HASH_COLLISIONS
-		if (ctr != hashit(key, _arrsize)) {
-			_collisions++;
-//			fprintf(stderr, "collisions = %d\n", _collisions);
-		}
-#endif
 		// Only fill array to fifty percent
 		if (_nele > _arrsize / 2) {
 			expand_array();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list