C4 Engine
C4 Engine API Documentation

class HashTable

Defined in:  TSHash.h
The HashTable class encapsulates a dynamically resizable hash table.
Definition

template <class type> class HashTable : public HashTableBase

Member Functions
HashTable::GetHashTableElementCount Returns the number of elements in a hash table.
HashTable::InsertHashTableElement Inserts an element into a hash table.
HashTable::RemoveHashTableElement Removes a particular element from a hash table.
HashTable::RemoveAllHashTableElements Removes all elements from a hash table.
HashTable::PurgeHashTable Deletes all elements in a hash table.
HashTable::FindHashTableElement Finds an element in a hash table.
Template Parameters
type The type of the class that can be stored in the hash table. The class specified by this parameter should inherit directly from the HashTableElement class using the same template parameter.
Constructor

HashTable(int32 initialBucketCount, int32 maxAverageDepth);

Parameters
initialBucketCount The number of buckets initially used by the hash table. This must be a power of two.
maxAverageDepth The maximum average size of each bucket allowed before the hash table is expanded.
Description
The HashTable class template is a container used to organize a homogeneous set of objects. The class type of objects that are to be stored in the hash table must be a subclass of the HashTableElement class template using the same template parameter as the HashTable container. A particular object can be a member of only one hash table at a time.

Upon construction, a HashTable object is empty. The initial number of buckets used by the hash table is specified by the initialBucketCount parameter, which must be a power of two in size. When the average size of all the buckets exceeds the value specified by the maxAverageDepth parameter, the number of buckets is doubled, and the elements of the hash table are redistributed among the larger set of buckets.

When a HashTable object is destroyed, all of the members of the hash table are also destroyed. To avoid deleting the members of a hash table when a HashTable object is destroyed, first call the HashTable::RemoveAllHashTableElements function to remove all of the hash table's members.

The class specified by the type template parameter must define a type named KeyType and a function named GetKey that has one of the following two prototypes.
KeyType GetKey(voidconst;
const KeyType& GetKey(voidconst;
This function should return the key associated with the object for which it is called. The KeyType type must be capable of being compared to other key values using the == operator.

The class specified by the type template parameter must also define a function named Hash that has one of the following two prototypes.
static uint32 Hash(KeyType key);
static uint32 Hash(const KeyType& key);
This function should return a 32-bit hash value corresponding to the key passed to it.
Base Classes
HashTableBase Used internally to encapsulate common functionality that is independent of the template parameter.
See Also

HashTableElement