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

IntKeyHashMap Class Template Reference

#include <HashMap.h>

Inheritance diagram for IntKeyHashMap:

HashMap List of all members.

Detailed Description

template<class VALUETYPE>
class toolbox::IntKeyHashMap< VALUETYPE >

An IntKeyHashMap stores objects in the same way as the HashMap does, but uses long ints as keys.

Author:
Thomas Jacob

Definition at line 383 of file HashMap.h.

Public Member Functions

bool ContainsKey (void *key) const
 Returns, if the hash table contains a given key.

bool ContainsKey (long key) const
 Returns, if the hash table contains a given key.

void Delete (void *key)
 Removes a key/value pair from the hash table.

void Delete (long key)
 Removes a key/value pair from the hash table and frees the memory of the value.

void DeleteAll ()
 Removes all key/value pairs from the hash table.

VALUETYPE * Get (void *key) const
 Returns the value of a key/value pair by its key.

VALUETYPE * Get (long key) const
 Returns the value of a key/value pair by its key.

long GetCount () const
 Returns the number of set keys.

int GetDesiredFillRatio () const
 Returns the fill ratio after a hash table resize.

int GetFillRatio () const
 Returns the current fill ratio.

PointeredListGetKeys () const
 Returns a new PointeredList of all keys currently in the hash table.

long GetSize () const
 Returns the number of buckets currently used.

PointeredListGetValues () const
 Returns a new PointeredList of all values currently in the hash table.

 IntKeyHashMap (long initSize, int desiredFillRatio)
 Creates a new int key hash table with customized settings.

 IntKeyHashMap (long initSize)
 Creates a new int key hash table with an initial size.

 IntKeyHashMap ()
 Creates a new int key hash table.

bool IsEmpty () const
 Returns whether there are no elements in the hash table.

void Set (void *key, VALUETYPE *Value)
 Sets a key/value pair into the hash table.

void Set (long key, VALUETYPE *Value)
 Sets a key/value pair into the hash table.

VALUETYPE * Unset (void *key)
 Removes a key/value pair from the hash table.

VALUETYPE * Unset (long key)
 Removes a key/value pair from the hash table Afterwards, the method checks if the hash table has to be resized.

void UnsetAll ()
 Removes all key/value pairs from the hash table.

virtual ~IntKeyHashMap ()
 Destroys the int key hash table.


Protected Member Functions

virtual void * CreateKey (void *key) const
 Creates the key object that shall be stored in the key buckets.

virtual void DestroyKey (void *key) const
 Disposes a key created by the CreateKey method.

virtual bool Equals (void *key1, void *key2) const
 Checks, if to keys equal each other.

virtual unsigned long HashCode (void *key) const
 Returns the hash code of the key.


Protected Attributes

PointeredList ** KeyBuckets
 The array of key buckets.

long Size
 The number of buckets currently used.

PointeredList ** ValueBuckets
 The array of value buckets.


Constructor & Destructor Documentation

IntKeyHashMap  ) 
 

Creates a new int key hash table.

IntKeyHashMap long  initSize  ) 
 

Creates a new int key hash table with an initial size.

Parameters:
initSize The minimum and initial size of the hash table. This is the minimum and initial number of buckets.

IntKeyHashMap long  initSize,
int  desiredFillRatio
 

Creates a new int key hash table with customized settings.

Parameters:
initSize The minimum and initial size of the hash table. This is the minimum and initial number of buckets.
desiredFillRatio The fill ratio after a hash table resize. This happens, if the fill ratio gets higher than one and a half times the fill ratio or lower than half the fill ratio. The rest of the buckets is reserved for further setting of keys.

virtual ~IntKeyHashMap  )  [virtual]
 

Destroys the int key hash table.


Member Function Documentation

bool ContainsKey void *  key  )  const [inherited]
 

Returns, if the hash table contains a given key.

Parameters:
key The key to be looked up. Note that NULL is a valid value among all possible values for keys.
Returns:
if the hash table contains the key.

bool ContainsKey long  key  )  const
 

Returns, if the hash table contains a given key.

Parameters:
key The key to be looked up. Note that 0 is the only not allowed key.
Returns:
if the hash table contains the key.

virtual void* CreateKey void *  key  )  const [protected, virtual, inherited]
 

Creates the key object that shall be stored in the key buckets.

The method receives a key and e.g. creates a clone, or uses the key directly, if this is possible. The Equals and HashCode method must return the same values when using the original key and the one returned by this method. The DestroyKey method disposes this key again. In the HashMap class, the key is returned directly.

Parameters:
key The original key provided by the user of this class. Note that NULL is a valid value among all possible values for keys.
Returns:
The key to be used by the key buckets.
Note:
Override this method to implement your own key memory management (for strings etc.).

Reimplemented in StringKeyHashMap, StringKeyHashMap< Void >, StringKeyHashMap< Option >, StringKeyHashMap< ConfigSection >, and StringKeyHashMap< ConfigParameter >.

void Delete void *  key  )  [inherited]
 

Removes a key/value pair from the hash table.

The memory of the key is not freed, since it was not acquired, but the memory of the value is freed.

Parameters:
key The key to be looked up for deletion. Note that NULL is a valid value among all possible values for keys.

void Delete long  key  )  [inline]
 

Removes a key/value pair from the hash table and frees the memory of the value.

Parameters:
key The key to be looked up for deletion. Note that 0 is the only not allowed key.

void DeleteAll  )  [inherited]
 

Removes all key/value pairs from the hash table.

The memory of the keys is not freed, since it was not acquired, but the memory of the values is freed.

virtual void DestroyKey void *  key  )  const [protected, virtual, inherited]
 

Disposes a key created by the CreateKey method.

This can be done by freeing the memory, if the key was cloned, or by simply doing nothing, if the user's key was directly used. This method should do the opposite of the CreateKey method. In the HashMap class, this method does nothing, since the key was directly used.

Parameters:
key The key created by the CreateKey method. Note that NULL is a valid value among all possible values for keys.
Note:
Override this method to implement your own key memory management (for strings etc.).

Reimplemented in StringKeyHashMap, StringKeyHashMap< Void >, StringKeyHashMap< Option >, StringKeyHashMap< ConfigSection >, and StringKeyHashMap< ConfigParameter >.

virtual bool Equals void *  key1,
void *  key2
const [protected, virtual, inherited]
 

Checks, if to keys equal each other.

In the HashMap class, this is true, if they point to the same memory.

Parameters:
key1 The first key.
key2 The second key.
Returns:
If both keys equal each other.
Note:
Override this method to implement your own key memory comparison method (for strings etc.).

Reimplemented in StringKeyHashMap, ICStringKeyHashMap, StringKeyHashMap< Void >, StringKeyHashMap< Option >, StringKeyHashMap< ConfigSection >, StringKeyHashMap< ConfigParameter >, and ICStringKeyHashMap< Void >.

VALUETYPE* Get void *  key  )  const [inherited]
 

Returns the value of a key/value pair by its key.

Parameters:
key The key to be looked up. Note that NULL is a valid value among all possible values for keys.
Returns:
The value to key, or NULL, if the key cannot be found or its value was NULL.

VALUETYPE* Get long  key  )  const [inline]
 

Returns the value of a key/value pair by its key.

Parameters:
key The key to be looked up. Note that 0 is the only not allowed key.
Returns:
The value to key, or NULL, if the key cannot be found or its value was NULL.

long GetCount  )  const [inline, inherited]
 

Returns the number of set keys.

Returns:
The number of set keys.

Reimplemented in HashSet.

int GetDesiredFillRatio  )  const [inline, inherited]
 

Returns the fill ratio after a hash table resize.

Returns:
The fill ratio after a hash table resize.

int GetFillRatio  )  const [inline, inherited]
 

Returns the current fill ratio.

This is the ratio between the used hash table cells (Count), and the reserved cells (Size).

Returns:
The current fill ratio.

PointeredList* GetKeys  )  const [inherited]
 

Returns a new PointeredList of all keys currently in the hash table.

Returns:
The keys as a PointeredList.
Warning:
This method creates a PointeredList and expects that it is deleted by the caller.

long GetSize  )  const [inline, inherited]
 

Returns the number of buckets currently used.

Returns:
The number of buckets currently used.
See also:
GetCount()

PointeredList* GetValues  )  const [inherited]
 

Returns a new PointeredList of all values currently in the hash table.

Returns:
The values as a PointeredList.
Warning:
This method creates a PointeredList and expects that it is deleted by the caller.

virtual unsigned long HashCode void *  key  )  const [protected, virtual]
 

Returns the hash code of the key.

This is a value that has to be constant for the same key all the time, needs not to be injective, and should distribute the keys quite good.

Parameters:
key The key to determine the hash code of. Note that NULL is a valid value among all possible values for keys.
Returns:
The key's hash code.

Reimplemented from HashMap.

bool IsEmpty  )  const [inline, inherited]
 

Returns whether there are no elements in the hash table.

Returns:
Whether there are no elements in the hash table.

Reimplemented in HashSet.

void Set void *  key,
VALUETYPE *  Value
[inherited]
 

Sets a key/value pair into the hash table.

Afterwards, the method checks if the hash table has to be resized. If the key existed, the old value is replaced, and its memory is freed.

Parameters:
key The key to be set. Since the memory of the key is not freed after unsetting the key or deleting the hash table, the memory management is still yours after the call. Note that NULL is a valid value among all possible values for keys.
Value The value to be set. The memory of the value is freed when deleting the key or hash table, and is not freed when unsetting the key. A NULL value is valid. Its key is set anyway. Use Unset to remove the key, too.

void Set long  key,
VALUETYPE *  Value
[inline]
 

Sets a key/value pair into the hash table.

Afterwards, the method checks if the hash table has to be resized. If the key existed, the old value is replaced, and its memory is freed.

Parameters:
key The key to be set. Note that 0 is the only not allowed key.
Value The value to be set. The memory of the value is freed when deleting the key or hash table, and is not freed when unsetting the key. A NULL value is valid. Its key is set anyway. Use Unset to remove the key, too.

VALUETYPE* Unset void *  key  )  [inherited]
 

Removes a key/value pair from the hash table.

Afterwards, the method checks if the hash table has to be resized. Both the memory of the key and the memory of the value are not freed, but the value is returned.

Parameters:
key The key to be looked up for removal. Note that NULL is a valid value among all possible values for keys.
Returns:
The value that was stored at the key before.

VALUETYPE* Unset long  key  )  [inline]
 

Removes a key/value pair from the hash table Afterwards, the method checks if the hash table has to be resized.

The memory of the value is not freed, but returned.

Parameters:
key The key to be looked up for removal. Note that 0 is the only not allowed key.
Returns:
The value that was stored at the key before.

void UnsetAll  )  [inherited]
 

Removes all key/value pairs from the hash table.

Afterwards, the method checks if the hash table has to be resized. Both the memory of the keys and the memory of the values are not freed.

Warning:
No value is freed, so you have to have a pointer to the objects, or the memory is lost.


Member Data Documentation

PointeredList** KeyBuckets [protected, inherited]
 

The array of key buckets.

Definition at line 118 of file HashMap.h.

long Size [protected, inherited]
 

The number of buckets currently used.

See also:
Count

Definition at line 124 of file HashMap.h.

PointeredList** ValueBuckets [protected, inherited]
 

The array of value buckets.

Definition at line 129 of file HashMap.h.


The documentation for this class was generated from the following file:
Generated on Tue Oct 3 00:23:40 2006 for ToolBox by doxygen 1.3.6