#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_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 "piecewise_cost_merge_integer_template_test.h" typedef uint64_t leco_type; int random(int m) { return rand() % m; } 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[]) { using namespace Codecset; Leco_int codec; std::string method = "uncompressed"; std::string source_file = std::string(argv[1]); int block_size = atoi(argv[2]); bool binary = atoi(argv[3]); std::string dictionary_file = std::string(argv[4]); // 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 // load dictionary index std::vector index; if(binary){ index = load_data_binary(source_file); } else{ index = load_data(source_file); } // load dictionary std::vector dictionary; dictionary = load_data(dictionary_file); int dict_size = dictionary.size(); int N = index.size(); int blocks = dict_size / block_size; if (blocks * block_size < dict_size) { blocks++; } // handle with the last block, maybe < block_size codec.init(blocks, block_size); std::vector block_start_vec; double origin_size = (sizeof(leco_type) * dict_size * 1.0); double compressrate = 1; double start = getNow(); leco_type mark = 0; // lookup dictionary bool flag = true; int repeat = 1; for(auto tmp_index : index){ leco_type tmpvalue = dictionary[tmp_index]; mark += tmpvalue; } double end = getNow(); double randomaccesstime = (end - start); std::ofstream outfile("fix_log", std::ios::app); outfile<