start of new file
[IRC.git] / Robust / src / Runtime / DSTM / interface / tests / testmlookup.c
1 #include <stdio.h>
2 #include "mlookup.h"
3 extern mhashtable_t mlookup;
4
5 main() 
6 {
7         int i;
8         void *val;
9         val = NULL;
10
11         if (mhashCreate(10, 0.20) == 1) {
12                 printf("mhashCreate error\n");  //creates hashtable
13         }
14         for (i = 1; i <= 7; i++) {      // Checks the insert() and resize() 
15                 if (mhashInsert(10*i, &i) == 1) 
16                         printf("mhashInsert error\n");
17         }
18         
19         i = mhashRemove(60);//Delete first element in the  hashtable
20         if(i == 1)
21                 printf("mhashRemove error ");
22         
23         for (i = 1; i <=7; i++) { // Check if it can search for all oids in hash table
24                 val = mhashSearch(10*i);
25                 if (val != &i) 
26                         printf("mhashSearch error - val = %d\n", val);
27                 else
28                         printf("mhashSearch oid = %d val = %x\n",10*i, val);
29         }
30
31         i = mhashRemove(30);
32         if(i == 1)
33                 printf("mhashRemove error ");
34         
35         for (i = 1; i <= 7; i++) {      //Prints all left over elements inside hash after deletion and prints error if element not found in hash
36                 val = mhashSearch(10*i);
37                 if (val != &i) 
38                         printf("mhashSearch error - val = %d\n", val);
39                 else
40                         printf("mhashSearch oid = %d val = %x\n",10*i, val);
41         }
42
43         printf("The total number of elements in table : %d\n", mlookup.numelements);
44
45 }