#include "common.h" #include "codecfactory.h" #include "caltime.h" #include "lr.h" #include "piecewise_fix_integer_template.h" #include "piecewise_fix_integer_template_float.h" #include "piecewise_cost_integer_template.h" #include "piecewise_cost_merge_integer_template_double.h" #include "FOR_integer_template.h" #include "delta_integer_template.h" #include "delta_cost_integer_template.h" #include "delta_cost_merge_integer_template.h" #include "delta_cost_merge_integer_template_link.h" typedef uint32_t leco_type; int random(int m) { return rand() % m; } 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; } 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; } int main(int argc, const char* argv[]) { using namespace Codecset; Delta_cost_merge_link codec; std::string method = "delta_cost"; std::string source_file = std::string(argv[1]); int blocks = atoi(argv[2]); int delta = atoi(argv[3]); int model_size = atoi(argv[4]); int binary = atoi(argv[5]); // alternatives : Delta_int, Delta_cost, Delta_cost_merge, FOR_int, Leco_int, Leco_cost, Leco_cost_merge_hc, Leco_cost_merge, Leco_cost_merge_double std::vector data; if(!binary){ data = load_data( "../data/"+source_file); } else{ data = load_data_binary("../data/"+source_file); } // std::sort(data.begin(), data.end()); 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 // if using auto segmentation codecs // int delta = 32; codec.init(blocks, block_size, delta); std::vector block_start_vec; double start_cr = getNow(); uint64_t totalsize = 0; for (int i = 0; i < blocks; i++) { // std::cout<<"block "< recover(data.size()); double totaltime = 0.0; // std::cout << "decompress all!" << std::endl; double start = getNow(); codec.decodeArray8(N, recover.data(), N); for (int j = 0; j < N; j++) { if (data[j] != recover[j]) { std::cout <<"num: " << j << " true is: " << data[j] << " predict is: " << recover[j] << std::endl; std::cout << "something wrong! decompress failed" << std::endl; flag = false; break; } } double end = getNow(); totaltime += (end - start); double da_ns = totaltime / data.size() * 1000000000; // std::cout << "random access decompress!" << std::endl; std::vector ra_pos; int repeat = 1; for(int i=0;i