-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbris8_subarray.cpp
111 lines (98 loc) · 3.11 KB
/
bris8_subarray.cpp
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
#include <sdsl/bit_vectors.hpp>
#include <sdsl/int_vector.hpp>
#include <string>
#include <vector>
#include <ctime>
#include <chrono>
#include <iterator>
#include <iostream>
#include "vbyte_helpers.hpp"
#include <valgrind/callgrind.h>
using namespace std;
using namespace sdsl;
uint32_t bit_length = 8;
unsigned int random_accesses = 1000000;
uint32_t cap = 1<<bit_length;
int main(int argc, char *argv[]) {
if(argc<=1) {
cerr << "Give uint64_t file as parameter" << endl;
return 1;
}
vector<uint64_t> original = read_data_from_file(argv[1]);
std::array<std::vector<uint32_t>, 8> data;
for(int i = 0; i < 8; i++) {
vector<uint32_t> vec;
data[i] = vec;
}
for(vector<uint64_t>::const_iterator i = original.begin(); i != original.end(); i++) {
vector<uint32_t> v = vb_encode_number(*i, cap);
v.front() += cap;
int level = 0;
for(auto j = v.rbegin(); j != v.rend(); j++) {
data[level].push_back(*j);
level++;
}
}
bit_vector b[8];
std::array<std::vector<uint8_t>, 8> iv;
size_t index = 0;
for(int i = 0; i < 8; i++) {
vector<uint8_t> vec(data[i].size(),0);
bit_vector bv(data[i].size(), 0);
index = 0;
for (vector<uint32_t>::const_iterator j = data[i].begin(); j != data[i].end(); j++, index++) {
bv[index] = (*j>>bit_length) & 1;
vec[index] = *j%(cap);
}
iv[i] = vec;
b[i] = bv;
}
rank_support_v<0> rb[8];
for(int i =0; i < 8; i++) {
rank_support_v<0> r(&b[i]);
rb[i] = r;
}
srand((unsigned) time(0));
vector<unsigned int> indices(random_accesses, 0);
for(vector<uint64_t>::size_type i = 0; i < indices.size(); i++) {
indices[i] = rand()%(original.size()-50);
}
chrono::steady_clock::time_point time_begin = chrono::steady_clock::now();
uint64_t z = 0;
uint64_t val = 0;
uint8_t subarray_len = 50;
uint32_t level_indices[8];
int max_level=-1;
for (vector<unsigned int>::const_iterator i = indices.begin(); i != indices.end(); i++) {
index = *i;
max_level = -1;
int current_level = 0;
for(int counter=0;counter<subarray_len;counter++) {
index = *i + counter;
current_level = 0;
val = 0;
while(b[current_level][index] == 0) {
uint8_t d = iv[current_level][index];
val = (val<<bit_length) + d;
if(max_level < current_level) {
level_indices[current_level] = rb[current_level](index);
max_level = current_level;
}
index = level_indices[current_level];
level_indices[current_level]++;
current_level++;
}
val = (val<<bit_length) + iv[current_level][index];
// the following is for accessing the value so it's not optimized out
z = z^val;
// sanity check for debugging the values
if(0 && val != original[*i+counter]) {
cout << "Did not match: " << val << " vs " << original[*i+counter] << endl;
}
}
}
chrono::steady_clock::time_point time_end = chrono::steady_clock::now();
cout << "checksum: " << z << endl;
cout << "Time taken: " << chrono::duration_cast<chrono::milliseconds> (time_end - time_begin).count() << "[ms]" << endl;
return 0;
}