diff options
Diffstat (limited to 'common/hashmap.h')
-rw-r--r-- | common/hashmap.h | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/common/hashmap.h b/common/hashmap.h index 0d4d7663f3..81a136f671 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -29,28 +29,46 @@ #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. // This and the other __sgi conditionals below work around these problems. -#if defined(__sgi) && !defined(__GNUC__) +// The Intel C++ Compiler suffers from the same problems. +#if (defined(__sgi) && !defined(__GNUC__)) || defined(__INTEL_COMPILER) 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. @@ -138,7 +156,7 @@ private: template<class NodeType> class IteratorImpl { friend class HashMap; -#if defined(__sgi) && !defined(__GNUC__) +#if (defined(__sgi) && !defined(__GNUC__)) || defined(__INTEL_COMPILER) template<class T> friend class Common::IteratorImpl; #else template<class T> friend class IteratorImpl; @@ -459,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 @@ -497,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 |