diff options
Diffstat (limited to 'common/hashmap.h')
-rw-r--r-- | common/hashmap.h | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/common/hashmap.h b/common/hashmap.h index 45192256a9..2607828c45 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -29,15 +29,37 @@ #ifndef COMMON_HASHMAP_H #define COMMON_HASHMAP_H +/** + * @def DEBUG_HASH_COLLISIONS + * Enable the following #define if you want to check how many collisions the + * code produces (many collisions indicate either a bad hash function, or a + * hash table that is too small). + */ +#define DEBUG_HASH_COLLISIONS + +/** + * @def USE_HASHMAP_MEMORY_POOL + * Enable the following define to let HashMaps use a memory pool for the + nodes they contain. * This increases memory usage, but also can improve + speed quite a bit. + */ +#define USE_HASHMAP_MEMORY_POOL + + #include "common/func.h" #include "common/str.h" #include "common/util.h" -#define USE_HASHMAP_MEMORY_POOL +#ifdef DEBUG_HASH_COLLISIONS +#include "common/debug.h" +#endif + #ifdef USE_HASHMAP_MEMORY_POOL #include "common/memorypool.h" #endif + + namespace Common { // The sgi IRIX MIPSpro Compiler has difficulties with nested templates. @@ -47,11 +69,6 @@ namespace Common { template<class T> class IteratorImpl; #endif -// Enable the following #define if you want to check how many collisions the -// code produces (many collisions indicate either a bad hash function, or a -// hash table that is too small). -//#define DEBUG_HASH_COLLISIONS - /** * HashMap<Key,Val> maps objects of type Key to objects of type Val. @@ -460,7 +477,7 @@ int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const { #ifdef DEBUG_HASH_COLLISIONS _lookups++; - fprintf(stderr, "collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d\n", + debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d", _collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups), (const void *)this, _mask+1, _size); #endif @@ -498,7 +515,7 @@ int HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key & #ifdef DEBUG_HASH_COLLISIONS _lookups++; - fprintf(stderr, "collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d\n", + debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d", _collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups), (const void *)this, _mask+1, _size); #endif |