summaryrefslogtreecommitdiffstats
path: root/benchmarks/include/file_util.h
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2024-05-09 14:13:00 -0400
committerDouglas Rumbaugh <dbr4@psu.edu>2024-05-09 14:13:00 -0400
commit9dac3f67ffe442b1cfc7c86e39cf325ce8c23045 (patch)
tree1308cb37c141a0961837c18793214d004e592158 /benchmarks/include/file_util.h
parent8d8885df98c4fce50141cc2ae4eb5b4033c51ee3 (diff)
parent265610435e1164a9acc39ca02ea1139acd37c46c (diff)
downloaddynamic-extension-9dac3f67ffe442b1cfc7c86e39cf325ce8c23045.tar.gz
Merge branch 'master' of github.com:dbrumbaugh/dynamic-extension
Diffstat (limited to 'benchmarks/include/file_util.h')
-rw-r--r--benchmarks/include/file_util.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/benchmarks/include/file_util.h b/benchmarks/include/file_util.h
index 586b44f..41eb18c 100644
--- a/benchmarks/include/file_util.h
+++ b/benchmarks/include/file_util.h
@@ -80,6 +80,46 @@ static std::vector<QP> read_range_queries(std::string &fname, double selectivity
return queries;
}
+
+template <typename QP>
+static std::vector<QP> read_binary_knn_queries(std::string fname, size_t k, size_t n) {
+ std::vector<QP> queries;
+ queries.reserve(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);
+ }
+
+
+ int32_t dim;
+ int32_t cnt;
+
+ file.read((char*) &(cnt), sizeof(cnt));
+ file.read((char*) &(dim), sizeof(dim));
+
+ if (n > cnt) {
+ n = cnt;
+ }
+
+ for (size_t i=0; i<n; i++) {
+ QP query;
+ for (size_t j=0; j<dim; j++) {
+ uint64_t val;
+ file.read((char*) &(val), sizeof(uint64_t));
+ query.point.data[j] = val;
+ }
+ query.k = k;
+ queries.push_back(query);
+ }
+
+ return queries;
+}
+
+
template <typename QP>
static std::vector<QP> read_knn_queries(std::string fname, size_t k) {
std::vector<QP> queries;
@@ -192,6 +232,42 @@ static std::vector<R> read_vector_file(std::string &fname, size_t n) {
return records;
}
+template <typename R>
+static std::vector<R> read_binary_vector_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<R> records;
+ records.reserve(n);
+
+ int32_t dim;
+ int32_t cnt;
+
+ file.read((char*) &(cnt), sizeof(cnt));
+ file.read((char*) &(dim), sizeof(dim));
+
+ if (n > cnt) {
+ n = cnt;
+ }
+
+ R rec;
+ for (size_t i=0; i<n; i++) {
+ for (size_t j=0; j<dim; j++) {
+ uint64_t val;
+ file.read((char*) &(val), sizeof(uint64_t));
+ rec.data[j] = val;
+ }
+
+ records.emplace_back(rec);
+ }
+
+ return records;
+}
static std::vector<std::unique_ptr<char[]>>read_string_file(std::string fname, size_t n=10000000) {