e958e8062bfe6d73aeacc706d4cb41da61bbf8ef
[IRC.git] / Robust / src / Runtime / DSTM / interface / testclookup.c
1 #include <stdio.h>
2 #include "clookup.h"
3
4 main() 
5 {
6         int i;
7         void *val;
8         cachehashtable_t *ctable;
9
10         if (( ctable = cachehashCreate(20, 0.50)) == NULL) {
11                 printf("cachehashCreate error\n");      //creates hashtable
12         }
13
14         for (i = 1; i <= 10; i++) {     // Checks the insert() and resize() 
15                 if (cachehashInsert(ctable, 10*i, &i) == 1) 
16                         printf("cachehashInsert error\n");
17         }
18
19         i = cachehashRemove(ctable, 10);//Delete first element in the  hashtable
20         if(i == 1)
21                 printf("cachehashRemove error ");
22         
23         for (i = 1; i <= 10; i++) { // Check if it can search for all keys in hash table
24                 val = cachehashSearch(ctable, 10*i);
25                 if (val != &i) 
26                         printf("cachehashSearch error - val = %d\n", val);
27                 else
28                         printf("cachehashSearch key = %d val = %x\n",10*i, val);
29         }
30
31         i = cachehashRemove(ctable, 30);
32         if(i == 1)
33                 printf("cachehashRemove error\n ");
34         i = cachehashRemove(ctable, 40);
35         if(i == 1)
36                 printf("cachehashRemove error\n ");
37         i = cachehashRemove(ctable, 80);
38         if(i == 1)
39                 printf("cachehashRemove error\n ");
40         i = cachehashRemove(ctable, 100);
41         if(i == 1)
42                 printf("cachehashRemove error\n ");
43         i = cachehashRemove(ctable, 90);
44         if(i == 1)
45                 printf("cachehashRemove error\n ");
46         
47         for (i = 1; i <= 10; i++) {     //Prints all left over elements inside hash after deletion and prints error if element not found in hash
48                 val = cachehashSearch(ctable, 10*i);
49                 if (val != &i) 
50                         printf("cachehashSearch error - val = %d\n", val);
51                 else
52                         printf("cachehashSearch 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 }
58