#include <hash.h>
Inheritance diagram for ABA_HASH< KeyType, ItemType >:
Public Member Functions | |
ABA_HASH (ABA_GLOBAL *glob, int size) | |
Initializes each slot with a 0-pointer to indicate that the linked list of hash items of this slot is empty. | |
~ABA_HASH () | |
The destructor deletes for each hash item by going through all non-empty lists of hash items. | |
void | insert (const KeyType &newKey, const ItemType &newItem) |
void | overWrite (const KeyType &newKey, const ItemType &newItem) |
Performs a regular insert() if there is no item with the same key in the hash table, otherwise the item is replaced by the new item. | |
ItemType * | find (const KeyType &key) |
bool | find (const KeyType &key, const ItemType &item) |
This version of the function find() checks if a prespecified item with a prespecified key is contained in the hash table. | |
int | remove (const KeyType &key) |
int | remove (const KeyType &key, const ItemType &item) |
This version of the function remove() removes the first item with a given key and a prespecified element from the hash table. | |
int | size () const |
int | nCollisions () const |
void | resize (int newSize) |
The functions initializeIteration() and next() can be used to iterate through all items stored in the hash table having the same key. | |
ItemType * | initializeIteration (const KeyType &key) |
ItemType * | next (const KeyType &key) |
The function next() can be used to go to the next item in the hash table with key key. | |
Private Member Functions | |
int | hf (int key) |
int | hf (unsigned key) |
This version of hf() implements a Fibonacci hash function for keys of type unsigned. | |
int | hf (const ABA_STRING &string) |
ABA_HASH (const ABA_HASH &rhs) | |
ABA_HASH & | operator= (const ABA_HASH &rhs) |
Private Attributes | |
ABA_GLOBAL * | glob_ |
ABA_HASHITEM< KeyType, ItemType > ** | table_ |
int | size_ |
int | nCollisions_ |
ABA_HASHITEM< KeyType, ItemType > * | iter_ |
Friends | |
ostream & | operator<< (ostream &out, const ABA_HASH< KeyType, ItemType > &hash) |
The output operator writes row by row all elements stored in the list associated with a slot on an output stream. |
Definition at line 137 of file hash.h.
ABA_HASH< KeyType, ItemType >::ABA_HASH | ( | ABA_GLOBAL * | glob, | |
int | size | |||
) |
Initializes each slot with a 0-pointer to indicate that the linked list of hash items of this slot is empty.
glob | A pointer to the corresponding global object. | |
size | The size of the hash table. |
The destructor deletes for each hash item by going through all non-empty lists of hash items.
ABA_HASH< KeyType, ItemType >::ABA_HASH | ( | const ABA_HASH< KeyType, ItemType > & | rhs | ) | [private] |
void ABA_HASH< KeyType, ItemType >::insert | ( | const KeyType & | newKey, | |
const ItemType & | newItem | |||
) |
Adds an item to the hash table.
The new item is inserted at the head of the list in the corresponding slot. It is possible to insert several items with the same key into the hash table.
key | The key of the new item. | |
item | The item being inserted. |
void ABA_HASH< KeyType, ItemType >::overWrite | ( | const KeyType & | newKey, | |
const ItemType & | newItem | |||
) |
Performs a regular insert() if there is no item with the same key in the hash table, otherwise the item is replaced by the new item.
key | The key of the new item. | |
item | The item being inserted. |
ItemType* ABA_HASH< KeyType, ItemType >::find | ( | const KeyType & | key | ) |
Looks for an item in the hash table with a given key.
key | The key of the searched item. |
bool ABA_HASH< KeyType, ItemType >::find | ( | const KeyType & | key, | |
const ItemType & | item | |||
) |
This version of the function find() checks if a prespecified item with a prespecified key is contained in the hash table.
false otherwise.
key | The key of the item. | |
item | The searched item. |
ItemType* ABA_HASH< KeyType, ItemType >::initializeIteration | ( | const KeyType & | key | ) |
The function initializeIteration() retrieves the first item.
key | The key of the items through which we want to iterate. |
ItemType* ABA_HASH< KeyType, ItemType >::next | ( | const KeyType & | key | ) |
The function next() can be used to go to the next item in the hash table with key key.
Before the first call of next() for a certain can the iteration has to be initialized by calling initializeItaration().
key | The key of the items through which we want to iterate. |
int ABA_HASH< KeyType, ItemType >::remove | ( | const KeyType & | key | ) |
Removes the first item with a given key from the hash table.
1 If there is no item with this key.
key | The key of the item that should be removed. |
int ABA_HASH< KeyType, ItemType >::remove | ( | const KeyType & | key, | |
const ItemType & | item | |||
) |
This version of the function remove() removes the first item with a given key and a prespecified element from the hash table.
1 If there is no item with this key.
key | The key of the item that should be removed. | |
item | The item which is searched. |
int ABA_HASH< KeyType, ItemType >::size | ( | ) | const |
int ABA_HASH< KeyType, ItemType >::nCollisions | ( | ) | const |
void ABA_HASH< KeyType, ItemType >::resize | ( | int | newSize | ) |
Can be used to change the size of the hash table.
newSize | The new size of the hash table (must be positive). |
int ABA_HASH< KeyType, ItemType >::hf | ( | int | key | ) | [private] |
Computes the hash value of key.
It must be overloaded for all key types, which are used together with this template.
This following version of hf() implements a Fibonacci hash function for keys of type int.
int ABA_HASH< KeyType, ItemType >::hf | ( | unsigned | key | ) | [private] |
This version of hf() implements a Fibonacci hash function for keys of type unsigned.
int ABA_HASH< KeyType, ItemType >::hf | ( | const ABA_STRING & | string | ) | [private] |
This is a hash function for character strings.
It is taken from Knu93a}, page 300.
ABA_HASH& ABA_HASH< KeyType, ItemType >::operator= | ( | const ABA_HASH< KeyType, ItemType > & | rhs | ) | [private] |
ostream& operator<< | ( | ostream & | out, | |
const ABA_HASH< KeyType, ItemType > & | hash | |||
) | [friend] |
The output operator writes row by row all elements stored in the list associated with a slot on an output stream.
The output of an empty slot is suppressed.
out | The output stream. | |
rhs | The hash table being output. |
ABA_GLOBAL* ABA_HASH< KeyType, ItemType >::glob_ [private] |
ABA_HASHITEM<KeyType, ItemType>** ABA_HASH< KeyType, ItemType >::table_ [private] |
int ABA_HASH< KeyType, ItemType >::nCollisions_ [private] |
The number of collisions on calls of insert() and overWrite().
ABA_HASHITEM<KeyType, ItemType>* ABA_HASH< KeyType, ItemType >::iter_ [private] |
An iterator for all items stored in a slot.
This variable is initialized by calling initializeIteration() and incremented by the function next().