HASH_TABLE NEW_HASH_TABLE(size)

- create a hashtable int size;

INFO LOOKUP(h, key)

- find element with key in hashtable h HASH_TABLE h; ELEM_KEY key;

void DELETE(h, key)

- delete key from hashtable h HASH_TABLE h; ELEM_KEY key;

void INSERT(h, key, info)

- insert info with key key in hashtable h HASH_TABLE h; ELEM_KEY key; INFO info;

void HASH_GENERATOR(h, action)

- traverse the hashtable HASH_TABLE h; IntFunction action;

These general functions define a generic datatype hashtable. HASH_TABLE, INFO, ELEM_KEY and every function that is needed, must be defined as macro's for the C pre-processor when this file is included. For different hashtables the same procedures can be used. This module can handle hashtables for strings but also for integers, structures, etc.

The hashtable has size different entries. The key defines in which entry the information can be found. The key is input in the HASH_FUNCTION and the result modula the size is the information-entry.

To create a new hashtable of size NEW_HASH_TABLE() is used. DELETE() destroys an hashtable element with index key. INSERT() inserts a pair (key, information) in the hashtable, by finding the right entry (HASH_FUNCTION(key) mod size) and inserting it in the list. Information is retrieved by using LOOKUP() with key to find the entry in h. If the key is in the list the corresponding INFO is returned, otherwise zero is returned.

To traverse the entire hashtable, HASH_GENERATOR() is used. For every (key, information) pair the function action is called.

HashElem* new_element(key, info, next)

- make a new hash element ELEM_KEY key; INFO info; HashElem *next;

A new element is created with the pair (key, info). It is placed at the beginning of the list indicated by next

hash.gen hash.gh