#ifndef __HASH_HENG_H__
#define __HASH_HENG_H__

/* Being lazy, I just wrote a C wrapper for C++ STL hash_map class.
   It supports multiple hash tables and can deal with hash collisions
   internally.  Treat it as a magic box of hash table */

/* everything within extern "C" are for C++ compiler to generate
   function name that is compatible with "C" naming conventions.
   Otherwise, by default C++ functions have their own conventions
   which won't be recognized by "C" compilers */

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct hashtable_tag
{
  struct hashtable_tag *parent;		/* for the purpose of making a
					   linked list of hash tables,
					   not used by any of the functions
					   below.  Defined here merely for
					   your convenience.
					*/
  void *hashTable;			/* this field is used by the
					   hash table functions defined
					   below.  Don't even try to touch
					   it
					*/
} HashTable;

/* @return a new hash table
*/
HashTable* newHashTable ();

/* destroy a hash table
   Note, it does not free the memory allocated for values.
   It is your responsibility to free them.
*/
void deleteHashTable (HashTable *table);

/* obtain an entry for the hash table.
   @return NULL if entry not found
	   otherwise the value corresponding to the key
*/
void* getHashTableEntry (HashTable *table, const char *key);

/* set an entry for the hash table
   Note: the hash table will create a copy of the key and manage
   that memory internally.  The memory for value should be managed
   by the user
*/
void setHashTableEntry (HashTable *table, const char *key, void* value);

/* remove an entry from the hash table, note, it does not free the
   memory occupied by the value.
*/
void deleteHashTableEntry (HashTable *table, const char *key);

/* this function returns the keys inside the hash table.  The last
   entry of the string array is a NULL to signal the end of the list.
   Make sure to free the structure returned to avoid memory leak.
   Do NOT free any strings inside.  The keys returned are unordered.
*/
const char** getHashTableKeys (HashTable *table);

#ifdef __cplusplus
}	/* ends extern "C" */
#endif

#endif /* __HASH_HENG_H__ */
