-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
73 lines (61 loc) · 1.59 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "flmap.h"
#define MAX_ITEMS 150000000
typedef struct{
size_t key;
void* value;
}Pair;
void randTest(){
srand(93);
Pair* items = (Pair*)malloc(sizeof(Pair)*MAX_ITEMS);
int i;
FLHashMap* map = FLHashMap_new();
//FLHashMap_print(map);
printf("Inserting\n");
for (i=0; i<MAX_ITEMS; i++){
items[i].key = (size_t)(i*10 + rand()%10);
items[i].value = (void*)rand();
//printf("%zu -> %d ...\n", items[i].key, (int)(items[i].key%map->T));
FLHashMap_set(map, items[i].key, items[i].value);
//FLHashMap_print(map);
}
//FLHashMap_PrintStats(map);
/*
printf("Deleting\n");
for (i=0; i<MAX_ITEMS/2; i++){
int index = rand()%MAX_ITEMS;
while (items[index].value == NULL){
index = rand()%MAX_ITEMS;
}
if (index < 0) index*=-1;
if (index == 0) index = 1;
void* val = FLHashMap_del(map, items[index].key);
if (val != items[index].value || FLHashMap_Get(map, items[index].key) != NULL){
printf("Deletion FAILURE: <%zu, %p> -> <%zu, %p>\n",
items[index].key, items[index].value, items[index].key, val);
}
items[index].value = NULL;
}
*/
printf("Searching\n");
for (int x=0; x<10; x++){
for (i=0; i<MAX_ITEMS; i++){
if (items[i].value == NULL) continue;
void* val = FLHashMap_get(map, items[i].key);
if (val != items[i].value){
printf("Lookup FAILURE: <%zu, %p> != <%zu, %p>\n",
items[i].key, items[i].value, items[i].key, val);
}
}
}
FLHashMap_printStats(map);
FLHashMap_destroy(map);
free(items);
}
int main(int argc, char** argv){
randTest();
return 0;
}