From ad976a5a9ed188e53490628333dbc513d6b150a0 Mon Sep 17 00:00:00 2001 From: erius Date: Mon, 28 Oct 2024 12:32:14 +0200 Subject: [PATCH] Added using directives to avoid excessive namespaecs Added explicit include directories to each file, even if an already included header defined them Removed using directives from header files --- bin/ftsort/ftsort.cpp | 34 +++++++++++++++----------- bin/ftsort/tape_config.cpp | 17 +++++++++---- bin/ftsort/tape_config.h | 2 ++ include/tapelib/filetape.h | 21 ++++++++-------- include/tapelib/tape_util.h | 6 ++--- src/filetape.cpp | 46 +++++++++++++++++++---------------- src/tape_util.cpp | 6 +++++ tests/filetape_sort_tests.cpp | 40 +++++++++++++++++------------- tests/filetape_tests.cpp | 17 +++++++------ tests/generate_input.cpp | 15 ++++++++---- 10 files changed, 121 insertions(+), 83 deletions(-) diff --git a/bin/ftsort/ftsort.cpp b/bin/ftsort/ftsort.cpp index 5143542..2f473a1 100644 --- a/bin/ftsort/ftsort.cpp +++ b/bin/ftsort/ftsort.cpp @@ -1,19 +1,27 @@ #include "tape_config.h" +#include "tapelib/filetape.h" +#include "tapelib/tape.h" #include "tapelib/tape_util.h" #include #include #include #include +#include #include +using std::string; +using std::chrono::high_resolution_clock; +using std::chrono::milliseconds; +using namespace tape; + size_t get_mem_peak() { - const static std::string mem_info_file = "/proc/self/status"; - const static std::string mem_field = "VmPeak:"; + const static string mem_info_file = "/proc/self/status"; + const static string mem_field = "VmPeak:"; std::ifstream status(mem_info_file); size_t mem = 0; - std::string line; + string line; while (std::getline(status, line)) { - if (line.find(mem_field) != std::string::npos) { + if (line.find(mem_field) != string::npos) { std::stringstream mem_line(line.substr(mem_field.size())); mem_line >> mem; return mem; @@ -36,29 +44,27 @@ int main(int argc, char *argv[]) { !read_settings_from_file(settings)) { return -1; } - tape::FileTape input(settings.input_file_name, settings.ft_settings); + FileTape input(settings.input_file_name, settings.ft_settings); if (!input.is_open()) { std::cerr << "Failed to create INPUT tape - file not found or " "insufficient permissions" << std::endl; return -1; } - tape::FileTape output(input, settings.output_file_name, - settings.ft_settings); + FileTape output(input, settings.output_file_name, settings.ft_settings); if (!output.is_open()) { std::cerr << "Failed to create OUTPUT tape - insufficient permissions" << std::endl; return -1; } // tmp tape factory that captures settings.ft_settings from local scope - tape::TempTapeFactory factory = - [&](size_t cells) -> std::unique_ptr { - return std::make_unique( - tape::FileTape(cells, settings.ft_settings)); + TempTapeFactory factory = [&](size_t cells) -> std::unique_ptr { + return std::make_unique( + FileTape(cells, settings.ft_settings)); }; - auto start = std::chrono::high_resolution_clock::now(); - tape::external_sort(input, output, factory, settings.memory_limit); - auto end = std::chrono::high_resolution_clock::now(); + auto start = high_resolution_clock::now(); + external_sort(input, output, factory, settings.memory_limit); + auto end = high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); std::cout << "Successfully sorted " << settings.input_file_name << " into " << settings.output_file_name << std::endl; diff --git a/bin/ftsort/tape_config.cpp b/bin/ftsort/tape_config.cpp index c3659fa..9e048b7 100644 --- a/bin/ftsort/tape_config.cpp +++ b/bin/ftsort/tape_config.cpp @@ -1,10 +1,17 @@ #include "tape_config.h" +#include "tapelib/filetape.h" #include +#include +#include #include #include #include #include #include +#include + +using std::string; +using std::chrono::milliseconds; const static struct std::vector