-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
112 lines (94 loc) · 2.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "bloom-filter.h"
static guint
djb_hash (gconstpointer data)
{
const gchar *str = data;
guint hash = 5381;
guint i;
for (i = 0; str[i]; i++) {
hash = ((hash << 5) + hash) + str[i];
}
return hash;
}
static void
test1 (void)
{
BloomFilter *filter;
guint i;
static const gchar *strings[] = {
"abcdef",
"ghijkl",
"mnopqr",
"stuvwx",
"yz",
"012345",
"6789",
};
filter = bloom_filter_new_full(2048, -1, 1, (BloomHashFunc)g_str_hash);
for (i = 0; i < G_N_ELEMENTS(strings); i++) {
g_assert(!bloom_filter_contains(filter, strings[i]));
bloom_filter_insert(filter, strings[i]);
g_assert(bloom_filter_contains(filter, strings[i]));
}
bloom_filter_remove_all(filter);
for (i = 0; i < G_N_ELEMENTS(strings); i++) {
g_assert(!bloom_filter_contains(filter, strings[i]));
}
bloom_filter_unref(filter);
}
static void
test2 (void)
{
BloomFilter *filter;
guint i;
static const gchar *strings[] = {
"abcdef",
"ghijkl",
"mnopqr",
"stuvwx",
"yz",
"012345",
"6789",
};
filter = bloom_filter_new_full(2048, -1, 2,
(BloomHashFunc)g_str_hash,
(BloomHashFunc)djb_hash);
for (i = 0; i < G_N_ELEMENTS(strings); i++) {
g_assert(!bloom_filter_contains(filter, strings[i]));
bloom_filter_insert(filter, strings[i]);
g_assert(bloom_filter_contains(filter, strings[i]));
}
bloom_filter_unref(filter);
}
static void
test3 (void)
{
BloomFilter *filter;
guint i;
static const gchar *strings[] = {
"abcdef",
"ghijkl",
"mnopqr",
"stuvwx",
"yz",
"012345",
"6789",
};
filter = bloom_filter_new_murmur(2048, -1, 4);
for (i = 0; i < G_N_ELEMENTS(strings); i++) {
g_assert(!bloom_filter_contains(filter, strings[i]));
bloom_filter_insert(filter, strings[i]);
g_assert(bloom_filter_contains(filter, strings[i]));
}
bloom_filter_unref(filter);
}
gint
main (gint argc,
gchar *argv[])
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/BloomFilter/g_str_hash", test1);
g_test_add_func("/BloomFilter/g_str_hash+djb_hash", test2);
g_test_add_func("/BloomFilter/murmurhas3", test3);
return g_test_run();
}