-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlru_example.c
More file actions
39 lines (32 loc) · 994 Bytes
/
lru_example.c
File metadata and controls
39 lines (32 loc) · 994 Bytes
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
#include "lrucache.h"
LRUCACHE_DEFINE(STR, const char *, int)
int main(int argc, char *argv[])
{
int i;
int status;
int v = -1;
char* test_key[] = {"persist", "joy", "allen", "ever", "a", "b", "c"};
int test_value[] = {0, 1, 2, 3, 4, 5};
printf("Init\n");
lrucache(STR) cache = lrucache_create(STR, 5);
lrucache_set_hash_func(STR, cache, str_hash);
lrucache_set_compare_func(STR, cache, strcmp);
lrucache_set_key_funcs(STR, cache, str_key_alloc, str_key_free);
printf("Cache: %p\n", cache);
printf("Put\n");
for (i = 0; i < 6; i++)
{
lrucache_put(STR, cache, test_key[i], test_value[i]);
printf("[Put] key: %s, value: %d\n", test_key[i], test_value[i]);
}
printf("Get\n");
printf("Note: if key don't exists, value will not be return.\n");
for (i = 0; i < 6; i++)
{
status = lrucache_get(STR, cache, test_key[i], &v);
printf("[Get] key: %s, value: %d, status: %d\n", test_key[i], v, status);
}
printf("Destroy\n");
lrucache_destroy(STR, cache);
return 0;
}