-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathc_example.c
53 lines (45 loc) · 1.02 KB
/
c_example.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
#import <stdio.h>
#import "cuckoofilter_c.h"
//
// Compile using:
//
// GCC:
// $ gcc -o c_example c_example.c path/to/cuckoofilter_c.o
//
// Zig:
// $ zig build-exe --c-source c_example.c --library c --object path/to/cuckoofilter_c.o
//
// You can obtain cuckoofilter_c.o either by downloading it from the latest Release on GitHub
// or by compiling the library using the Zig compiler:
//
// $ zig build-obj --release-fast src/cuckoofilter_c.zig
//
int main(int argc, char const *argv[])
{
int err;
int found;
unsigned char memory[1024];
struct Filter8 cf;
err = cf_init8(memory, 1024, &cf);
if (err != 0) {
printf("Error!\n");
}
// Search for the item hash = 0, fp = 'a'
err = cf_maybe_contains8(&cf, 0, 'a', &found);
if (err != 0) {
printf("Error!\n");
}
printf("%d\n", found);
// Add the item
err = cf_add8(&cf, 0, 'a');
if (err != 0) {
printf("Error!\n");
}
// Search it again
err = cf_maybe_contains8(&cf, 0, 'a', &found);
if (err != 0) {
printf("Error!\n");
}
printf("%d\n", found);
return 0;
}