icl_hash_test.c

Go to the documentation of this file.
00001 
00007 /* $Id: icl_hash_test.c,v 1.7 2005/09/30 18:41:15 seymour Exp $ */
00008 /* $UTK_Copyright: $ */
00009 
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 
00014 #include "icl_hash.h"
00015 
00025 int main(int argc, char** argv)
00026 {
00027   icl_hash_t* ht = icl_hash_create(64, NULL);
00028   icl_entry_t* p  = NULL;
00029   char *str, *foo;
00030 
00031   printf("Inserting Hello: A word\n");
00032   p = icl_hash_insert(ht, strdup("Hello"), strdup("A word"));
00033   printf("New node: key:%s data:%s\n", p->key, (char*)p->data);
00034   str = (char *)icl_hash_find(ht, "Hello");
00035   if(str) printf("Found %s\n", str);
00036 
00037   p = icl_hash_insert(ht, strdup("n"), strdup("a string for n"));
00038   printf("New node: key:%s data:%s\n", p->key, (char*)p->data);
00039   str = (char *)icl_hash_find(ht, "n");
00040   if(str) printf("Found %s\n", str);
00041 
00042   p = icl_hash_insert(ht, strdup("k"), strdup("a number for k"));
00043   printf("New node: key:%s data:%s\n", p->key, (char*)p->data);
00044   str = (char *)icl_hash_find(ht, "k");
00045   if(str) printf("Found %s\n", str);
00046 
00047   printf("Looking for non-existent node\n");
00048   str = (char *)icl_hash_find(ht, "foo");
00049   if(!str) printf("...cool, not found.\n");
00050 
00051   foo = strdup("foo");
00052   printf("Updating node\n");
00053   if(!icl_hash_update_insert(ht, foo, strdup("new entry for k"), (void**)&str))
00054     printf("update failed\n");
00055   else {
00056     printf("Looking for non-existent node\n");
00057     str = (char *)icl_hash_find(ht, foo);
00058     if(str) printf("Found %s\n", str);
00059   }
00060 
00061   icl_hash_dump(stderr, ht);
00062 
00063   icl_hash_destroy(ht, free, free);
00064   
00065   exit(EXIT_SUCCESS);
00066 }