start of new file
[IRC.git] / Robust / src / Runtime / DSTM / interface / tests / testclookup.c
1 #include <stdio.h>
2 #include "clookup.h"
3
4 main() 
5 {
6         int i;
7         void *val;
8         chashtable_t *ctable;
9
10         if (( ctable = chashCreate(1000, 0.40)) == NULL) {
11                 printf("chashCreate error\n");  //creates hashtable
12         }
13
14         for (i = 1; i <= 2000; i++) {   // Checks the insert() and resize() 
15                 if (chashInsert(ctable, 10*i, &i) == 1) 
16                         printf("chashInsert error\n");
17         }
18
19         i = chashRemove(ctable, 10);//Delete first element in the  hashtable
20         if(i == 1)
21                 printf("chashRemove error ");
22         
23         for (i = 1; i <= 2000; i++) { // Check if it can search for all keys in hash table
24                 val = chashSearch(ctable, 10*i);
25                 if (val != &i) 
26                         printf("chashSearch error - val = %d\n", val);
27                 else
28                         printf("chashSearch key = %d val = %x\n",10*i, val);
29         }
30
31         i = chashRemove(ctable, 30);
32         if(i == 1)
33                 printf("chashRemove error\n ");
34         i = chashRemove(ctable, 40);
35         if(i == 1)
36                 printf("chashRemove error\n ");
37         i = chashRemove(ctable, 80);
38         if(i == 1)
39                 printf("chashRemove error\n ");
40         i = chashRemove(ctable, 100);
41         if(i == 1)
42                 printf("chashRemove error\n ");
43         i = chashRemove(ctable, 90);
44         if(i == 1)
45                 printf("chashRemove error\n ");
46         
47         for (i = 1; i <= 2000; i++) {   //Prints all left over elements inside hash after deletion and prints error if element not found in hash
48                 val = chashSearch(ctable, 10*i);
49                 if (val != &i) 
50                         printf("chashSearch error - val = %d\n", val);
51                 else
52                         printf("chashSearch key = %d val = %x\n",10*i, val);
53         }
54
55         printf("The total number of elements in table : %d\n", ctable->numelements);
56         
57         chashDelete(ctable);
58 }