-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
54 lines (43 loc) · 1018 Bytes
/
test.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
#include <stdio.h>
typedef struct {
const char* k;
int v;
} MyEntry;
#define HASH MyHash
#define ENTRY MyEntry
#define PREFIX myhash
#define KEY(e) e->k
#define EXISTS(e) e->k
#define KEYEQ(a, b) !strcmp(a, b)
#define HASHFN(s) hashBytes((const uint8_t*)(s), strlen(s))
#include "hashtable.h"
int main(void) {
MyHash h = HASH_INIT;
MyEntry* e;
if (myhashCreate(&h, "a", &e)) {
printf("ENTRY CREATED\n");
e->k = "a";
e->v = 1;
}
myhashCreate(&h, "b", &e);
e->k = "b";
e->v = 2;
myhashCreate(&h, "c", &e);
e->k = "c";
e->v = 3;
myhashCreate(&h, "c", &e);
e->k = "c";
e->v = 4;
e = myhashFind(&h, "a");
if (e)
printf("FOUND a %d\n", e->v);
else
printf("NOT FOUND a\n");
e = myhashFind(&h, "d");
if (e)
printf("FOUND d %d\n", e->v);
else
printf("NOT FOUND d\n");
HASH_FOREACH(myhash, f, &h)
printf("%s %d\n", f->k, f->v);
}