Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Hashtable< key, value > Class Template Reference

#include <Hashtable.h>

Inheritance diagram for util::Hashtable< key, value >:

util::Map< key, value > util::Iterator< Pair< key, value > > util::Object util::Object List of all members.

Detailed Description

template<class key, class value>
class util::Hashtable< key, value >

Hashtable is an implementation of an associative array.

It stores key-value pairs and allows look-ups using key values of any type.


Public Methods

 Hashtable (unsigned int size=128)
 Create a new hash table.

 Hashtable (const Hashtable &other)
 Copy a hash table.

Hashtable & operator= (const Hashtable &other)
 Copy a hash table.

virtual ~Hashtable ()
 Release the resources allocated by a Hashtable.

virtual value * get (const key &obj)
 Get a pointer to a stored object.

virtual void put (const key &obj, const value &val)
 Put a new entry into the table.

virtual void remove (const key &obj)
 Remove the data referenced by obj.

void removeValue (const value &obj)
 Remove the given value from this hash table.

bool containsKey (const key &obj)
 Check whether this hash table contains the given reference key.

bool containsValue (const value &obj)
 Check whether this hash table contains the given value.

void clear (void)
 Clear the table.

void reset (void)
 Reset the internal iterator of this Hashtable.

Pair< key, value > * next (void)
 Get the next stored item.

bool hasNext (void) const
 Check if we still have some items to fetch.

int getItems () const
 Get the current number of key-value pairs in the hash table.


Constructor & Destructor Documentation

template<class key, class value>
util::Hashtable< key, value >::Hashtable unsigned int    size = 128
 

Create a new hash table.

Parameters:
size  the initial size of the table. The table will safely hold any number of entries, but if the actual number of stored entries is much larger than the initial size, performance will be reduced.


Member Function Documentation

template<class key, class value>
void util::Hashtable< key, value >::clear void   
 

Clear the table.

All allocated resources will be released.

template<class key, class value>
bool util::Hashtable< key, value >::containsKey const key &    obj
 

Check whether this hash table contains the given reference key.

Returns:
true if obj is found in the table, false otherwise

template<class key, class value>
bool util::Hashtable< key, value >::containsValue const value &    obj
 

Check whether this hash table contains the given value.

Returns:
true if obj is found in the table, false otherwise

template<class key, class value>
value * util::Hashtable< key, value >::get const key &    obj [virtual]
 

Get a pointer to a stored object.

Parameters:
obj  the key object that references the wanted object
Returns:
a pointer to the value or NULL if it was not found

Implements util::Map< key, value >.

template<class key, class value>
Pair< key, value > * util::Hashtable< key, value >::next void    [virtual]
 

Get the next stored item.

The items are not returned in insertion order.

Implements util::Iterator< Pair< key, value > >.

template<class key, class value>
void util::Hashtable< key, value >::put const key &    obj,
const value &    val
[virtual]
 

Put a new entry into the table.

If a value is already mapped to the key, the old value is replaced.

Parameters:
obj  the reference key
val  the object to be stored

Implements util::Map< key, value >.

template<class key, class value>
void util::Hashtable< key, value >::remove const key &    obj [virtual]
 

Remove the data referenced by obj.

The memory reserved by the reference key and the actual object is released.

Parameters:
obj  the reference key

template<class key, class value>
void util::Hashtable< key, value >::removeValue const value &    obj
 

Remove the given value from this hash table.

The memory reserved by the reference key and the actual object is released. If the object is a pointer, it must be deleted by the user.

Parameters:
obj  the object to be removed


The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.