Written and integrated into libwww by John Punin - thanks!
This module is implemented by HTHash.c, and is a part of the W3C Sample Code Library.
This HashTable class implements a simple hash table to keep objects associated with key words.
#ifndef HTHASH_H #define HTHASH_H #include "HTList.h" #ifdef __cplusplus extern "C" { #endif typedef struct _HTHashtable HTHashtable; struct _HTHashtable { void **table; int count; int size; }; typedef struct _keynode keynode; struct _keynode { char *key; void *object; };
These methods create and deletes a Hash Table
extern HTHashtable * HTHashtable_new (int size); extern BOOL HTHashtable_delete (HTHashtable *me);
extern BOOL HTHashtable_addObject (HTHashtable *me, const char *key, void *newObject);
extern BOOL HTHashtable_removeObject (HTHashtable *me, const char *key);
extern void * HTHashtable_object (HTHashtable * me, const char *key);
extern int HTHashtable_count (HTHashtable *me);
Walking the hashtable calls the specified function pointer with each key and object that is in the hash table. If the callback function returns 0, the walking stops. If it returns a negative number, the current element is removed from the hash table. Return a positive number to keep going.
Note that it is legal for the walkFunc to call HTHashtable_removeObject() on any element in the current hash table except the current one (if you intend to keep going, that is). The only legal way to delete the current element while continuing to walk the table is to use the negative return value.
extern BOOL HTHashtable_walk (HTHashtable *me, int (*walkFunc)(HTHashtable *, char *, void *));
extern HTArray * HTHashtable_keys (HTHashtable *me);
extern void HTHashtable_print (HTHashtable *me);
#ifdef __cplusplus } #endif #endif /* HTHASH_H */