-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
76 lines (71 loc) · 2.34 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
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: stoupin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/10 14:59:34 by stoupin #+# #+# */
/* Updated: 2018/01/10 14:59:39 by stoupin ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "hashmap.h"
#define KEY_COUNT (1024 * 1024)
#define KEY_PREFIX ("test")
#define KEY_MAX_LENGTH (256)
typedef struct s_data
{
char key_string[KEY_MAX_LENGTH];
int number;
} t_data;
int main(void)
{
t_hashmap_env env;
t_hashmap *map;
int index;
char key_string[KEY_MAX_LENGTH];
t_data *value;
int error;
hashmap_init(&env);
map = hashmap_new();
if (map == NULL)
exit(1);
index = 0;
while (index < KEY_COUNT)
{
value = (t_data*)malloc(sizeof(t_data));
snprintf(value->key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
value->number = index;
error = hashmap_put(&env, map, value->key_string, value);
assert(error == MAP_OK);
index++;
}
index = 0;
while (index < KEY_COUNT)
{
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
error = hashmap_get(&env, map, key_string, (void**)&value);
assert(error == MAP_OK);
assert(value->number == index);
index++;
}
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT);
error = hashmap_get(&env, map, key_string, (void**)&value);
assert(error == MAP_MISSING);
index = 0;
while (index < KEY_COUNT)
{
snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index);
error = hashmap_get(&env, map, key_string, (void**)&value);
assert(error == MAP_OK);
error = hashmap_remove(&env, map, key_string);
assert(error == MAP_OK);
free(value);
index++;
}
hashmap_free(map);
return (0);
}