Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

HashTable Class Template Reference

#include <hashtable.h>

Inheritance diagram for HashTable:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class HashTableType>
class NeoEngine::HashTable< HashTableType >

Hash table template Hash table storing pointers to objects of template type. The hash table never deletes any pointers stored in the hash table. Use the GetAllNodeData to get all the pointers stored if you want to delete the data objects.

Author:
Mattias Jansson (mattias@realityrift.com)


Public Types

enum  HASHTABLEDEF { DEFAULTSIZE = 256 }
 Hash table defines. More...


Public Member Functions

 HashTable (int iSize=DEFAULTSIZE)
virtual ~HashTable ()
HashTableType * Insert (const HashString &rstrKey, HashTableType *pkData)
HashTableType * Find (const HashString &rstrKey)
HashTableType * Delete (const HashString &rstrKey, HashTableType *pkData=0)
void GetAllNodes (std::vector< HashTableNode< HashTableType > * > *pvpkVector)
void GetAllNodeData (std::vector< HashTableType * > *pvpkVector)
void Clear ()

Protected Member Functions

HashTableNodeTypeLookupNode (const HashString &rstrKey, int iIndex=0)

Protected Attributes

HashTableNodeVec * m_pvkTable
int m_iSize
unsigned int m_uiElements


Member Enumeration Documentation

enum HASHTABLEDEF
 

Hash table defines.

Enumeration values:
DEFAULTSIZE  Default number of buckets


Constructor & Destructor Documentation

HashTable int  iSize = DEFAULTSIZE  ) 
 

Allocate and initialize hash table with the specified number of buckets

Parameters:
iSize Initial size of table

~HashTable  )  [virtual]
 

Deallocate memory. This will not deallocate the objects stored in the hash table, to do so you must use GetAllNodeData and deallocate the objects yourself.


Member Function Documentation

HashTable< HashTableType >::HashTableNodeType * LookupNode const HashString rstrKey,
int  iIndex = 0
[inline, protected]
 

Helper method to lookup a node

Parameters:
rstrKey Key name
iIndex Precalculated hash index
Returns:
Node associated with key

HashTableType * Insert const HashString rstrKey,
HashTableType *  pkData
 

Insert key value into hash table. The data will replace any data with the same key previously stored in the table. The old data pointer is returned by this method, it is not deallocated by the hash table.

Parameters:
rstrKey Key name
pkData Data pointer
Returns:
Ptr to old data for key if any, 0 if new key

HashTableType * Find const HashString rstrKey  ) 
 

Find data for key

Parameters:
rstrKey Key name
Returns:
Data ptr if key found, 0 if not found

HashTableType * Delete const HashString rstrKey,
HashTableType *  pkData = 0
 

Remove key from hash table. The data for the key is returned by this method, it is not deallocated by the hash table, you must do this manually if needed.

Parameters:
rstrKey Key name
pkData If not null, delete only if pointer for key match pData
Returns:
Data ptr associated with key if key in table, 0 if not

void GetAllNodes std::vector< HashTableNode< HashTableType > * > *  pvpkVector  ) 
 

Get pointers to all hash table nodes. You must not deallocate the nodes, or the hash table will cause unpredictable crashes. Deallocating the data pointers in the nodes is perfectly alright, as long as you do not try to use these pointers later (naturally).

Parameters:
pvpkVector Vector recieving all nodes

void GetAllNodeData std::vector< HashTableType * > *  pvpkVector  ) 
 

Get all data pointers stored for all keys in the hash table. You can use this method if you need to deallocate the data objects before deleting the hash table.

Parameters:
pvpkVector Vector recieving all node data pointers

void Clear  ) 
 

Clear hash table. This will not deallocate any data objects stored in the table, to do this you must use GetAllNodeData() method and deallocate the objects manually.


Member Data Documentation

HashTableNodeVec* m_pvkTable [protected]
 

Hash table

int m_iSize [protected]
 

Number of rows in table

unsigned int m_uiElements [protected]
 

Number of objects


The documentation for this class was generated from the following file:
Generated on Wed Jan 21 14:21:11 2004 for NeoEngine by doxygen 1.3.5