GClasses
GClasses::GHashTable Class Reference

Detailed Description

Implements a typical hash table. (It doesn't take ownership of the objects you add, so you must still delete them yourself.)

#include <GHashTable.h>

Inheritance diagram for GClasses::GHashTable:
GClasses::GHashTableBase

Public Member Functions

 GHashTable (size_t nInitialBucketCount)
 
virtual ~GHashTable ()
 
void add (const void *pKey, const void *pValue)
 Adds a pointer key and value pair to the hash table. The key can not be NULL. More...
 
virtual bool areKeysEqual (const char *pKey1, const char *pKey2)
 Returns true iff the two keys are equal. More...
 
bool get (const void *pKey, void **ppOutValue)
 Gets a value based on the key. More...
 
virtual size_t hash (const char *pKey, size_t nBucketCount)
 Computes a hash of the key. More...
 
void remove (const void *pKey)
 Removes an entry from the hash table. More...
 
- Public Member Functions inherited from GClasses::GHashTableBase
virtual ~GHashTableBase ()
 
size_t revisionNumber ()
 Returns a number that changes when the contents of this table are modified (This is useful for detecting invalidated iterators) More...
 
size_t size ()
 Returns the number of items in this hash table. More...
 

Static Public Member Functions

static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure. More...
 

Additional Inherited Members

- Protected Member Functions inherited from GClasses::GHashTableBase
 GHashTableBase (size_t nInitialBucketCount)
 
void _Add (const char *pKey, const void *pValue)
 Adds a key/value pair to the hash table. More...
 
size_t _Count (const char *pKey)
 Returns the number of values with the specified key. More...
 
template<class T >
bool _Get (const char *pKey, T **pOutValue)
 Returns true and the first occurrence of a value with the specified key if one exists. More...
 
void _Remove (const char *pKey)
 Removes the first found occurrence of the specified key. More...
 
void _Resize (size_t nNewSize)
 
- Protected Attributes inherited from GClasses::GHashTableBase
size_t m_nBucketCount
 
size_t m_nCount
 
size_t m_nModCount
 
struct HashBucketm_pBuckets
 
struct HashBucketm_pFirstEmpty
 

Constructor & Destructor Documentation

GClasses::GHashTable::GHashTable ( size_t  nInitialBucketCount)
inline
virtual GClasses::GHashTable::~GHashTable ( )
inlinevirtual

Member Function Documentation

void GClasses::GHashTable::add ( const void *  pKey,
const void *  pValue 
)
inline

Adds a pointer key and value pair to the hash table. The key can not be NULL.

virtual bool GClasses::GHashTable::areKeysEqual ( const char *  pKey1,
const char *  pKey2 
)
inlinevirtual

Returns true iff the two keys are equal.

Implements GClasses::GHashTableBase.

bool GClasses::GHashTable::get ( const void *  pKey,
void **  ppOutValue 
)
inline

Gets a value based on the key.

virtual size_t GClasses::GHashTable::hash ( const char *  pKey,
size_t  nBucketCount 
)
inlinevirtual

Computes a hash of the key.

Implements GClasses::GHashTableBase.

void GClasses::GHashTable::remove ( const void *  pKey)
inline

Removes an entry from the hash table.

static void GClasses::GHashTable::test ( )
static

Performs unit tests for this class. Throws an exception if there is a failure.