verification

This commit is contained in:
bronku 2025-11-13 19:52:34 +01:00
parent eddfd42284
commit 635ad1a225
4 changed files with 38 additions and 4 deletions

View file

@ -10,6 +10,7 @@ public:
std::string output_file = "1.in"; std::string output_file = "1.in";
std::string directory = "tmp"; std::string directory = "tmp";
bool generate_data = false; bool generate_data = false;
bool evaluate_file = false;
int N = 100000; // number of records in a file int N = 100000; // number of records in a file
int n = 101; // number of buffers int n = 101; // number of buffers
int b = 10; // blocking factor int b = 10; // blocking factor
@ -18,14 +19,14 @@ public:
{ {
if (argc <= 1) { if (argc <= 1) {
std::cerr << "Please specify input arguments\n"; std::cerr << "Please specify input arguments\n";
std::cerr << "Usage: " << argv[0] << " [-g] [-N count] [-i input] [-o output] [-d directory] [-n buffers] [-b block_size]\n"; std::cerr << "Usage: " << argv[0] << " [-g] [-e] [-N count] [-i input] [-o output] [-d directory] [-n buffers] [-b block_size]\n";
throw std::invalid_argument("No input arguments"); throw std::invalid_argument("No input arguments");
} }
Configuration config; Configuration config;
bool input_set = false; bool input_set = false;
int opt; int opt;
while ((opt = getopt(argc, argv, "i:o:d:gN:n:b:")) != -1) { while ((opt = getopt(argc, argv, "i:o:d:geN:n:b:")) != -1) {
switch (opt) { switch (opt) {
case 'i': case 'i':
config.input_file = optarg; config.input_file = optarg;
@ -40,6 +41,9 @@ public:
case 'g': case 'g':
config.generate_data = true; config.generate_data = true;
break; break;
case 'e':
config.evaluate_file = true;
break;
case 'N': case 'N':
config.N = std::stoi(optarg); config.N = std::stoi(optarg);
break; break;
@ -57,6 +61,9 @@ public:
if (config.generate_data && input_set) { if (config.generate_data && input_set) {
throw std::invalid_argument("Cannot specify both -g and -i options"); throw std::invalid_argument("Cannot specify both -g and -i options");
} }
if (config.generate_data && config.evaluate_file) {
throw std::invalid_argument("Cannot specify both -g and -e options");
}
return config; return config;
} }

View file

@ -18,6 +18,28 @@ void generate_file(int N, const std::string& filename)
} }
} }
void read_and_evaluate(std::string filename, int n)
{
Buffer main_buffer(n);
auto buff = main_buffer.divide(1)[0];
std::ifstream in_stream(filename);
Reader input_reader(in_stream);
while (true) {
size_t records_read = read_chunk(input_reader, buff);
if (records_read == 0) {
break;
}
for (size_t i = 0; i < records_read; ++i) {
const Record& rec = buff[i];
std::cout << "[Evaluate i = " << i << ": " << rec.evaluate() << "] " << rec << "\n";
}
}
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
try { try {
@ -28,6 +50,11 @@ int main(int argc, char** argv)
return 0; return 0;
} }
if (opts.evaluate_file) {
read_and_evaluate(opts.input_file, opts.N);
return 0;
}
sort_file(opts); sort_file(opts);
} catch (const std::exception& e) { } catch (const std::exception& e) {

View file

@ -1,6 +1,6 @@
CFLAGS = -g -lc++ -std=c++17 CFLAGS = -g -lc++ -std=c++17
build/main: main.cpp sort.cpp buffer.hpp reader.hpp writer.hpp build build/main: main.cpp sort.cpp config.hpp buffer.hpp reader.hpp writer.hpp build
clang $(CFLAGS) main.cpp -o build/main clang $(CFLAGS) main.cpp -o build/main
build: build:

View file

@ -31,7 +31,7 @@ void create_initial_runs(const std::string& input_filename, const std::string& d
{ {
auto buff = main_buffer.divide(1)[0]; auto buff = main_buffer.divide(1)[0];
std::ifstream in_stream(input_filename, std::ios::binary); std::ifstream in_stream(input_filename);
Reader input_reader(in_stream); Reader input_reader(in_stream);
for (size_t run_index = 0;; run_index++) { for (size_t run_index = 0;; run_index++) {
std::cout << "creating run " << run_index << '\n'; std::cout << "creating run " << run_index << '\n';