#include #include #include #include #include #include #include #include #include #pragma once template static std::vector read_lookup_queries(std::string fname, double selectivity) { std::vector queries; FILE *qf = fopen(fname.c_str(), "r"); if (!qf) { fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); exit(EXIT_FAILURE); } size_t start, stop; double sel; while (fscanf(qf, "%zu%zu%lf\n", &start, &stop, &sel) != EOF) { if (start < stop && std::abs(sel - selectivity) < 0.1) { QP q; q.target_key = start; queries.push_back(q); } } fclose(qf); return queries; } template static std::vector read_range_queries(std::string &fname, double selectivity) { std::vector queries; FILE *qf = fopen(fname.c_str(), "r"); if (!qf) { fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); exit(EXIT_FAILURE); } size_t start, stop; double sel; while (fscanf(qf, "%zu%zu%lf\n", &start, &stop, &sel) != EOF) { if (start < stop && std::abs(sel - selectivity) < 0.1) { QP q; q.lower_bound = start; q.upper_bound = stop; queries.push_back(q); } } fclose(qf); return queries; } template static std::vector read_knn_queries(std::string fname, size_t k) { std::vector queries; FILE *qf = fopen(fname.c_str(), "r"); char *line = NULL; size_t len = 0; if (!qf) { fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); exit(EXIT_FAILURE); } while (getline(&line, &len, qf) > 0) { char *token; QP query; size_t idx = 0; token = strtok(line, " "); do { query.point.data[idx++] = atof(token); } while ((token = strtok(NULL, " "))); query.k = k; queries.emplace_back(query); } free(line); fclose(qf); return queries; } template static std::vector read_sosd_file(std::string &fname, size_t n) { std::fstream file; file.open(fname, std::ios::in | std::ios::binary); if (!file.is_open()) { fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); exit(EXIT_FAILURE); } std::vector records(n); for (size_t i=0; i static std::vector> read_sosd_file_pair(std::string &fname, size_t n) { std::fstream file; file.open(fname, std::ios::in | std::ios::binary); if (!file.is_open()) { fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); exit(EXIT_FAILURE); } std::vector> records(n); for (size_t i=0; i static std::vector read_vector_file(std::string &fname, size_t n) { std::fstream file; file.open(fname, std::ios::in); if (!file.is_open()) { fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); exit(EXIT_FAILURE); } std::vector records; records.reserve(n); for (size_t i=0; i