summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2024-05-01 13:31:24 -0400
committerDouglas Rumbaugh <dbr4@psu.edu>2024-05-01 13:31:24 -0400
commit160692f4b9f80c6eba7d18d3221fc1c3e3c3139e (patch)
treed9969de74f0530eee832bf679a20b5fdab3fa120 /benchmarks
parent56e7a202b492fa26137b381eea73e4c773df069d (diff)
downloaddynamic-extension-160692f4b9f80c6eba7d18d3221fc1c3e3c3139e.tar.gz
Added error checks to file opening, and generalized key types
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/include/file_util.h40
1 files changed, 36 insertions, 4 deletions
diff --git a/benchmarks/include/file_util.h b/benchmarks/include/file_util.h
index 8dc1b5f..b5b3417 100644
--- a/benchmarks/include/file_util.h
+++ b/benchmarks/include/file_util.h
@@ -15,6 +15,12 @@ static std::vector<QP> read_lookup_queries(std::string fname, double selectivity
std::vector<QP> 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) {
@@ -34,6 +40,12 @@ static std::vector<QP> read_range_queries(std::string &fname, double selectivity
std::vector<QP> 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) {
@@ -58,6 +70,11 @@ static std::vector<QP> read_knn_queries(std::string fname, size_t k) {
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;
@@ -83,10 +100,15 @@ static std::vector<R> 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<R> records(n);
for (size_t i=0; i<n; i++) {
- uint64_t k;
- file.read((char*) &(k), sizeof(uint64_t));
+ decltype(R::key) k;
+ file.read((char*) &(k), sizeof(R::key));
records[i].key = k;
records[i].value = i;
}
@@ -99,10 +121,15 @@ static std::vector<std::pair<K, V>> read_sosd_file_pair(std::string &fname, size
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<std::pair<K,V>> records(n);
for (size_t i=0; i<n; i++) {
- uint64_t k;
- file.read((char*) &(k), sizeof(uint64_t));
+ K k;
+ file.read((char*) &(k), sizeof(K));
records[i].first = k;
records[i].second = i;
}
@@ -121,6 +148,11 @@ static std::vector<R> 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<R> records;
records.reserve(n);