Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

HashTable Class Template Reference

Template class representing a hash array. More...

#include <hashtable.h>

Inheritance diagram for HashTable:

Collection List of all members.

Public Methods

 HashTable (void)
 A constructor.

virtual ~HashTable (void)
 A destructor. More...

virtual T_ * find (Key_ key)
 Find an item by given key. More...

virtual void insert (Key_ key, T_ *item)
 Insert an item with gven key and data. More...

virtual bool remove (Key_ key)
 Remove an item with given key. More...

virtual bool contains (Key_ key)
 Test whether hash array contains an item with given key. More...

virtual void clear (void)
 Clear the hash array. More...

virtual void setAutoDelete (bool ad)

Protected Attributes

HashTableBucket< Key_, T_,
HashTableBucketContainer_ > ** 
table_
 An array of buckets.

HashTableHash< size_ > hash_
 Hash structure.


Detailed Description

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
class HashTable< Key_, T_, HashTableBucketContainer_, size_ >

Template class representing a hash array.

Hash array is implemented as an array (with given size_) of buckets. Buckets are represented by BucketContainer_ and hold data of type T_ which are accessible by keys of type Key_. For best performance, the size_ should be a suitably large prime number.

List of some useful prime numbers:

  53,           97,           193,         389,         769,  
  1543,         3079,         6151,        12289,       24593,  
  49157,        98317,        196613,      393241,      786433,  
  1572869,      3145739,      6291469,     12582917,    25165843,  
  50331653,     100663319,    201326611,   402653189,   805306457,   
  1610612741,   3221225473,   4294967291
Parameters:
Key_  Class representing the type of a key.
T_  Class representing the type of data.
BucketContainer_  Template class representing container for buckets.
size_  Size of the hash array.

Definition at line 262 of file hashtable.h.


Constructor & Destructor Documentation

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual HashTable< Key_, T_, HashTableBucketContainer_, size_ >::~HashTable void    [inline, virtual]
 

A destructor.

Clears the contents of the hash array.

Definition at line 282 of file hashtable.h.


Member Function Documentation

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual void HashTable< Key_, T_, HashTableBucketContainer_, size_ >::clear void    [inline, virtual]
 

Clear the hash array.

Removes all items from the hash array. The data of the items aren't removed unless setAutoDelete is called.

Implements Collection.

Definition at line 393 of file hashtable.h.

Referenced by HashTable< XmlChar *, unsigned long, List, 3079 >::~HashTable.

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual bool HashTable< Key_, T_, HashTableBucketContainer_, size_ >::contains Key_    key [inline, virtual]
 

Test whether hash array contains an item with given key.

Parameters:
key  The value of the key.
Return values:
true  Hash array contains the item.
false  Hash array doesn't contain the item.

Definition at line 377 of file hashtable.h.

Referenced by HashTable< XmlChar *, unsigned long, List, 3079 >::insert.

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual T_* HashTable< Key_, T_, HashTableBucketContainer_, size_ >::find Key_    key [inline, virtual]
 

Find an item by given key.

This function finds an item by given key.

Parameters:
key  The value of the key.
Returns:
Pointer to found data, or NULL.

Definition at line 298 of file hashtable.h.

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual void HashTable< Key_, T_, HashTableBucketContainer_, size_ >::insert Key_    key,
T_ *    item
[inline, virtual]
 

Insert an item with gven key and data.

This function inserts new item into the hash array using appropriate hash function.

Parameters:
key  The value of the key.
item  Data of the item.

Definition at line 317 of file hashtable.h.

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual bool HashTable< Key_, T_, HashTableBucketContainer_, size_ >::remove Key_    key [inline, virtual]
 

Remove an item with given key.

Data of the item is not deleted unless setAutoDelete was changed.

Parameters:
key  The value of the key.
Return values:
true  Item has been removed.
false  Item hasn't been removed.

Definition at line 350 of file hashtable.h.

template<class Key_, class T_, template< class T_ > class HashTableBucketContainer_, unsigned long size_>
virtual void HashTable< Key_, T_, HashTableBucketContainer_, size_ >::setAutoDelete bool    ad [inline, virtual]
 

Turn on/off auto deletion of item data.

If auto deletion is turned off (the default), removing an item doesn't delete the data of the item. If auto deletion is turned odn, the data is deleted together with the item.

Parameters:
ad  Flag of auto deletion (true or false).

Reimplemented from Collection.

Definition at line 424 of file hashtable.h.


The documentation for this class was generated from the following file:
Generated on Wed Feb 5 10:43:05 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002