forked from yuyuyu101/C-Buffered-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bftree_example.c
80 lines (65 loc) · 1.57 KB
/
bftree_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
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "bftree_map.h"
#include "bftree_set.h"
void bftmap_example()
{
struct bftree *tree;
int i, len;
char buf[100];
char *val;
struct bftree_iterator *iter;
int count;
tree = bftmap_create();
for (i = 0; i < 1000; i++) {
len = snprintf(buf, 100, "key%d", i);
val = malloc(100);
snprintf(val, 100, "val%d", i);
bftmap_put(tree, buf, len, val);
}
assert(bftree_count(tree) == 1000);
count = 0;
iter = bftree_get_iterator(tree);
while (bftree_next(iter) != NULL)
count++;
bftree_free_iterator(iter);
assert(count == 1000);
for (i = 0; i < 10000; i++) {
len = snprintf(buf, 100, "key%d", i);
bftmap_del(tree, buf, len);
}
for (i = 0; i < 1000; i++) {
len = snprintf(buf, 100, "key%d", i);
bftmap_get(tree, buf, len);
}
bftmap_free(tree);
}
void bftset_example()
{
struct bftree *tree;
int i, len;
char buf[100];
char *val;
tree = bftset_create();
for (i = 0; i < 10000; i++) {
len = snprintf(buf, 100, "key%d", i);
val = malloc(100);
snprintf(val, 100, "val%d", i);
bftset_put(tree, buf, len);
}
for (i = 0; i < 10000; i++) {
len = snprintf(buf, 100, "key%d", i);
bftset_del(tree, buf, len);
}
for (i = 0; i < 10000; i++) {
len = snprintf(buf, 100, "key%d", i);
bftset_get(tree, buf, len);
}
bftmap_free(tree);
}
int main()
{
bftmap_example();
bftset_example();
}