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

StringKeyHashSet Class Reference

#include <HashSet.h>

Inheritance diagram for StringKeyHashSet:

StringKeyHashMap< Void > HashMap< Void > List of all members.

Detailed Description

A StringKeyHashSet stores objects in the same way as the HashSet does, but uses char arrays (strings) as keys.

To keys equal each other, if they contain the same characters.

Author:
Thomas Jacob

Definition at line 231 of file HashSet.h.

Public Member Functions

void Add (const char *key)
 Adds a key to the hash set.

bool Contains (const char *key) const
 Returns, if the hash set contains a given key.

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

bool ContainsKey (const char *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 (const char *key)
 Removes a key/value pair from the hash table.

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

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

VoidGet (const char *key) const
 Returns the value of a key/value pair by its key.

PointeredListGetAll () const
 Returns a new PointeredList of all keys currently in the hash set.

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.

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

void Remove (const char *key)
 Removes a key from the hash set.

void RemoveAll ()
 Removes all keys from the hash set.

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

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

 StringKeyHashSet (long initSize, int desiredFillRatio)
 Creates a new string key hash set with customized settings.

 StringKeyHashSet (long initSize)
 Creates a new string key hash set with an initial size.

 StringKeyHashSet ()
 Creates a new string key hash set.

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

VoidUnset (const char *key)
 Removes a key/value pair from the hash table.

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

virtual ~StringKeyHashSet ()
 Destroys the string key hash set.


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

StringKeyHashSet  ) 
 

Creates a new string key hash set.

StringKeyHashSet long  initSize  ) 
 

Creates a new string key hash set with an initial size.

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

StringKeyHashSet long  initSize,
int  desiredFillRatio
 

Creates a new string key hash set with customized settings.

Parameters:
initSize The minimum and initial size of the hashtable. This is the minimum and initial number of buckets.
desiredFillRatio The fill ratio after a hashtable 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 ~StringKeyHashSet  )  [virtual]
 

Destroys the string key hash set.

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


Member Function Documentation

void Add const char *  key  )  [inline]
 

Adds a key to the hash set.

Afterwards, the method checks if the hash set has to be resized.

Parameters:
key The key to be set. Since the memory of the key is not freed after unsetting the key or deleting the hash set, the memory management is still yours after the call.

bool Contains const char *  key  )  const [inline]
 

Returns, if the hash set contains a given key.

Parameters:
key The key to be looked up.
Returns:
if the hash set contains the key.

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 const char *  key  )  const [inherited]
 

Returns, if the hash table contains a given key.

Parameters:
key The key to be looked up.
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 StringKeyHashMap class, this method clones the key, since it is a string (const char *).

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.

Reimplemented from HashMap< Void >.

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 const char *  key  )  [inline, inherited]
 

Removes a key/value pair from the hash table.

The original memory of the key provided when setting the key/value is not freed, since the StringKeyHashMap uses a private copy of it.

Parameters:
key The key to be looked up for deletion.

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 StringKeyHashMap class, this method frees the memory, since the CreateKey method created it.

Parameters:
key The key created by the CreateKey method. Note that NULL is a valid value among all possible values for keys.

Reimplemented from HashMap< Void >.

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

Checks, if to keys equal each other.

In the StringKeyHashMap class, this is true, if they contain the same characters.

Parameters:
key1 The first key.
key2 The second key.
Returns:
If both keys equal each other.

Reimplemented from HashMap< Void >.

Reimplemented in ICStringKeyHashMap< Void >.

Void * 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.

Void * Get const char *  key  )  const [inline, inherited]
 

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

Parameters:
key The key to be looked up.
Returns:
The value to key, or NULL, if the key cannot be found or its value was NULL.

PointeredList* GetAll  )  const [inline]
 

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

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

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, inherited]
 

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< Void >.

Reimplemented in ICStringKeyHashMap< Void >.

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 Remove const char *  key  )  [inline]
 

Removes a key from the hash set.

Afterwards, the method checks if the hash set has to be resized. The memory of the key is not freed.

Parameters:
key The key to be looked up for removal.

void RemoveAll  )  [inline]
 

Removes all keys from the hash set.

Afterwards, the method checks if the hash set has to be resized. The memory of the key is not freed.

void Set void *  key,
Void 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 const char *  key,
Void Value
[inline, 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 StringKeyHashMap uses a private copy of the key's memory, it is not freed after unsetting or deleting the key or deleting the hash table.
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 * 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.

Void * Unset const char *  key  )  [inline, 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.
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:41 2006 for ToolBox by doxygen 1.3.6