#include #include #include #include #include #include #include #include "util.hpp" #include "elias_fano.hpp" #include "mapper.hpp" #include "perftest_common.hpp" typedef uint64_t data_type; int random(int m) { return rand() % m; } double getNow() { struct timeval tv; gettimeofday(&tv, 0); return tv.tv_sec + tv.tv_usec / 1000000.0; } template static std::vector load_data_binary(const std::string& filename, bool print = true) { std::vector data; std::ifstream in(filename, std::ios::binary); if (!in.is_open()) { std::cerr << "unable to open " << filename << std::endl; exit(EXIT_FAILURE); } // Read size. uint64_t size; in.read(reinterpret_cast(&size), sizeof(uint64_t)); data.resize(size); // Read values. in.read(reinterpret_cast(data.data()), size * sizeof(T)); in.close(); return data; } template static std::vector load_data(const std::string& filename) { std::vector data; std::ifstream srcFile(filename, std::ios::in); if (!srcFile) { std::cout << "error opening source file." << std::endl; return data; } while (srcFile.good()) { T next; srcFile >> next; if (!srcFile.good()) { break; } data.emplace_back(next); } srcFile.close(); return data; } int main(int argc, const char* argv[]) { std::string source_file = std::string(argv[1]); int blocks = atoi(argv[2]); int binary = atoi(argv[3]); std::vector data; if(!binary){ data = load_data("/root/Learn-to-Compress/data/" + source_file); } else{ data = load_data_binary("/root/Learn-to-Compress/data/" + source_file); } int N = data.size(); int block_size = data.size() / blocks; blocks = data.size() / block_size; if (blocks * block_size < N) { blocks++; } // handle with the last block, maybe < block_size int block_length = block_size; std::vector block_start_vec; uint64_t totalsize = 0; double start_cr = getNow(); for(int i=0;idump(descriptor); uint32_t segment_size = res - descriptor; descriptor = (uint8_t*)realloc(descriptor, segment_size); block_start_vec.push_back(descriptor); totalsize += segment_size; // elias_fanos.emplace_back(ef); // totalsize +=succinct::mapper::size_tree_of(*ef)->size; } double end_cr = getNow(); double compress_time = end_cr - start_cr; double compress_throughput = N*sizeof(data_type) / (compress_time*1000000000); double compressrate = (totalsize)*100.0 / (sizeof(data_type) * N * 1.0); std::vector elias_fanos; double decode_all_time = 0; double start = getNow(); for(int i = 0; i< blocks;i++){ succinct::elias_fano* ef = new succinct::elias_fano(); ef->rebuild(block_start_vec[i]); elias_fanos.push_back(ef); } uint64_t mark_da = 0; block_length = block_size; for(int i=0;i recover(data.size()); double totaltime = 0.0; // std::cout << "random access decompress!" << std::endl; std::vector buffer(data.size()); std::vector ra_pos; for(int i=0;irebuild(block_start_vec[i]); elias_fanos.push_back(ef); } for (auto index: ra_pos) { // succinct::elias_fano ef; // ef.rebuild(block_start_vec[index/block_size]); // data_type tmpvalue = ef.select(index%block_size); data_type tmpvalue = elias_fanos[index/block_size]->select(index%block_size); mark += tmpvalue; // if (data[index] != tmpvalue) // { // std::cout << "num: " << index << "true is: " << data[index] << " predict is: " << tmpvalue << std::endl; // flag = false; // std::cout << "something wrong! decompress failed" << std::endl; // } // if (!flag) // { // break; // } } end = getNow(); randomaccesstime += (end - start); double ra_ns = randomaccesstime / N * 1000000000; outfile<