-
Notifications
You must be signed in to change notification settings - Fork 1
/
c3bt-main.c
82 lines (73 loc) · 2.3 KB
/
c3bt-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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "c3bt.h"
void print_stats(c3bt_tree* tree)
{
printf("%d uobjs in %d cells, %d pushdowns %d splits %d pushups "
"%d merges.\n", c3bt_nobjects(tree), c3bt_stat_cells,
c3bt_stat_pushdowns, c3bt_stat_splits, c3bt_stat_pushups,
c3bt_stat_merges);
}
void clear_stats()
{
c3bt_stat_pushdowns = 0;
c3bt_stat_splits = 0;
c3bt_stat_pushups = 0;
c3bt_stat_merges = 0;
}
int main()
{
#define ASIZE 100000
c3bt_tree tree;
c3bt_cursor cur;
int i;
int *array = malloc(ASIZE * sizeof(int));
int *robj;
struct timespec t_start, t_end;
// srand(time(NULL) - 1354856137);
// srand(77);
for (i = 0; i < ASIZE; i++)
// array[i] = rand();
array[i] = i * 7;
c3bt_init(&tree, C3BT_KDT_U32, 0, 0);
clock_gettime(CLOCK_MONOTONIC, &t_start);
for (i = 0; i < ASIZE; i++)
c3bt_add(&tree, array + i);
clock_gettime(CLOCK_MONOTONIC, &t_end);
printf("Add %dk uobjs: %ldus\n", ASIZE / 1000,
(t_end.tv_sec - t_start.tv_sec) * 1000000
+ (t_end.tv_nsec - t_start.tv_nsec) / 1000);
print_stats(&tree);
clear_stats();
clock_gettime(CLOCK_MONOTONIC, &t_start);
for (i = 0; i < ASIZE; i += 2)
c3bt_remove(&tree, array + i);
clock_gettime(CLOCK_MONOTONIC, &t_end);
printf("Remove %dk uobjs: %ldus\n", ASIZE / 2000,
(t_end.tv_sec - t_start.tv_sec) * 1000000
+ (t_end.tv_nsec - t_start.tv_nsec) / 1000);
print_stats(&tree);
clear_stats();
clock_gettime(CLOCK_MONOTONIC, &t_start);
for (i = 0; i < ASIZE; i += 2)
c3bt_add(&tree, array + i);
clock_gettime(CLOCK_MONOTONIC, &t_end);
printf("Re-add %dk uobjs: %ldus\n", ASIZE / 2000,
(t_end.tv_sec - t_start.tv_sec) * 1000000
+ (t_end.tv_nsec - t_start.tv_nsec) / 1000);
print_stats(&tree);
robj = c3bt_first(&tree, &cur);
while (robj) {
//printf("%d\n", *robj);
robj = c3bt_next(&tree, &cur);
}
c3bt_destroy(&tree);
printf("Population distribution:\n");
for (i = 0; i < NODES_PER_CELL; i++)
printf("cells with %d nodes: %d\n", i + 1, c3bt_stat_popdist[i]);
free(array);
return 0;
}
/* vim: set syn=c.doxygen cin et sw=4 ts=4 tw=80 fo=croqmM: */