/* this is a simple code that test hash.cc.

To compile hash.cc, use the following command
	g++ -c hash.cc
To compile test.c, use the following command
	gcc -c test.c
To link them together
	gcc -o target test.o hash.o -lstdc++

Note that -lstdc++ is required.

 */

#include <stdio.h>
#include <string.h>

/* include the hash table function header */
#include "hash.h"

int main ()
{
  char str1[] = "key 1";	/* str1 is allocated on stack */
  char str2[] = "key 2";	/* str2 is allocated on stack */
  char value1[] = "value 1";	/* value 1 is allocated on stack */
  char value2[] = "value 2";	/* value 2 is allocated on stack */

  const char** keys;
  int i;
  HashTable *hashTable;

  printf ("creating a new hash table:\n");
  hashTable = newHashTable ();

  printf ("inserting keys into the hash table:\n");



  setHashTableEntry (hashTable, str1, (void *)value1);
  setHashTableEntry (hashTable, str2, (void *)value2);

  /* I used the different string pointer types just to make sure
     that hash table working correctly for identical C strings that
     are from different pointers */

  printf ("get the entries back from the table:\n");
  printf ("The value for %s is %s\n",
	  str1, (char *)getHashTableEntry (hashTable, "key 1"));
  printf ("The value for %s is %s\n",
	  str2, (char *)getHashTableEntry (hashTable, str2));

  /* demo of key listings */
  keys = getHashTableKeys (hashTable);
  printf ("Here are the keys inside the table:\n");
  for (i = 0; keys[i] != NULL; ++i)
    printf ("key: %s\tvalue: %s\n", keys[i], (char *)getHashTableEntry (hashTable, keys[i]));
  /* important, free the memory occupied by key once done using
     it to avoid memory leaks */
  free (keys);

  printf ("deleting the hashtable:\n");
  deleteHashTable (hashTable);

  return 0;
}
