-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_bitmaps.c
130 lines (102 loc) · 3.23 KB
/
test_bitmaps.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "test_core.h"
#include "tsdb_bitmap.h"
void print_title(char *title) {
u_int32_t i, padding = 18 - strlen(title);
printf("%s:", title);
for (i = 0; i < padding; i++) {
printf(" ");
}
}
void print_index(u_int32_t *index) {
printf(" %u", *index);
}
void print_result(u_int32_t *result, u_int32_t max_index, char *title) {
print_title(title);
scan_result(result, max_index, print_index);
printf("\n");
}
void compress_array(u_int32_t *array, u_int32_t array_len,
char *compressed, u_int32_t *compressed_len) {
u_int32_t new_len = array_len + 400;
qlz_state_compress state_compress;
memset(&state_compress, 0, sizeof(state_compress));
compressed = (char*)malloc(new_len);
*compressed_len = qlz_compress(array, compressed, array_len,
&state_compress);
}
int main(int argc, char *argv[]) {
u_int32_t i, j;
u_int8_t word_size = sizeof(u_int32_t);
u_int32_t array_len = CHUNK_GROWTH / word_size;
// three arrays, each representing a tag
u_int32_t tag1[array_len]; memset(tag1, 0, sizeof(tag1));
u_int32_t tag2[array_len]; memset(tag2, 0, sizeof(tag2));
u_int32_t tag3[array_len]; memset(tag3, 0, sizeof(tag3));
// array for operation results
u_int32_t result[array_len];
// to tag an index, we set the bit on the applicable array
set_bit(tag1, 0);
set_bit(tag3, 0);
set_bit(tag2, 1);
set_bit(tag2, 2);
set_bit(tag3, 2);
set_bit(tag1, 3);
set_bit(tag2, 3);
set_bit(tag3, 3);
set_bit(tag3, 4);
set_bit(tag1, 9999);
u_int32_t max_index = 9999;
u_int32_t array_max_used = max_index / word_size;
printf("Size of tag array uncompressed: %lu\n", sizeof(tag1));
char *compressed = 0;
u_int32_t compressed_len;
compress_array(tag1, sizeof(tag1), compressed, &compressed_len);
printf("Size of tag array compressed: %u\n", compressed_len);
free(compressed);
printf("\n");
// tag1
//
for (i = 0; i < array_max_used; i++) {
result[i] = tag1[i];
}
print_result(result, max_index, "tag1");
// tag1 and tag2
//
for (i = 0; i < array_max_used; i++) {
result[i] = tag1[i] & tag2[i];
}
print_result(result, max_index, "tag1 and tag2");
// tag2 and tag3
//
for (i = 0; i < array_max_used; i++) {
result[i] = tag2[i] & tag3[i];
}
print_result(result, max_index, "tag2 and tag3");
// tag1 or tag2
//
for (i = 0; i < array_max_used; i++) {
result[i] = tag1[i] | tag2[i];
}
print_result(result, max_index, "tag1 or tag2");
// tag2 or tag3
//
for (i = 0; i < array_max_used; i++) {
result[i] = tag2[i] | tag3[i];
}
print_result(result, max_index, "tag2 or tag3");
// tag1 and not tag2
//
for (i = 0; i < array_max_used; i++) {
result[i] = tag1[i] & ~tag2[i];
}
print_result(result, max_index, "tag1 and not tag2");
// calculate result and scan multiple times (demonstrate load)
//
for (i = 0; i < 100000; i++) {
for (j = 0; j < array_max_used; j++) {
result[j] = (tag1[j] & ~tag2[j]) | tag3[j];
}
scan_result(result, max_index, NULL);
}
return 0;
}