From aec16966a8f8a099f766ebd74223d0a3fb75a7b6 Mon Sep 17 00:00:00 2001 From: rpuwa Date: Fri, 17 May 2024 23:44:07 +0300 Subject: [PATCH] build fixes --- .../algorithms/dynamic/demo/demo_algo.cpp | 7 +-- .../algorithms/dynamic/dynamic_algorithm.cpp | 50 ++++++------------- .../algorithms/dynamic/dynamic_algorithm.h | 2 +- src/core/config/descriptions.h | 6 ++- .../crud_operations/insert/option.cpp | 4 +- .../tabular_data/crud_operations/operations.h | 9 ++-- src/core/model/table/table_row.h | 23 +++++---- src/core/util/dynamic_collection.h | 5 +- .../dynamic/bind_dynamic_algorithms.cpp | 2 +- src/python_bindings/py_util/py_to_any.cpp | 4 +- 10 files changed, 49 insertions(+), 63 deletions(-) diff --git a/src/core/algorithms/dynamic/demo/demo_algo.cpp b/src/core/algorithms/dynamic/demo/demo_algo.cpp index a629222c4..8501a3619 100644 --- a/src/core/algorithms/dynamic/demo/demo_algo.cpp +++ b/src/core/algorithms/dynamic/demo/demo_algo.cpp @@ -1,9 +1,10 @@ #include "demo_algo.h" -#include "config/names.h" + #include "config/ioption.h" +#include "config/names.h" -using config::names::kTable; using config::InputTable; +using config::names::kTable; algos::DynamicAlgorithmDemo::DynamicAlgorithmDemo(std::vector phase_names) : DynamicAlgorithm(phase_names) {} @@ -41,6 +42,6 @@ std::vector algos::DynamicAlgorithmDemo::GetResult() { } std::pair, std::vector> - algos::DynamicAlgorithmDemo::GetResultDiff() { +algos::DynamicAlgorithmDemo::GetResultDiff() { return std::make_pair(added_to_result_.AsStringVector(), erased_from_result_.AsStringVector()); } diff --git a/src/core/algorithms/dynamic/dynamic_algorithm.cpp b/src/core/algorithms/dynamic/dynamic_algorithm.cpp index 33069d691..a9a47b081 100644 --- a/src/core/algorithms/dynamic/dynamic_algorithm.cpp +++ b/src/core/algorithms/dynamic/dynamic_algorithm.cpp @@ -1,33 +1,13 @@ #include "dynamic_algorithm.h" -#include "config/tabular_data/input_table_type.h" -#include "config/names_and_descriptions.h" -#include "config/option_using.h" -#include "config/tabular_data/input_table/option.h" -#include "config/tabular_data/crud_operations/operations.h" #include +#include "config/names_and_descriptions.h" +#include "config/option_using.h" +#include "config/tabular_data/crud_operations/operations.h" +#include "config/tabular_data/input_table/option.h" +#include "config/tabular_data/input_table_type.h" -namespace { -using config::InputTable; - -std::unordered_map GetIndexes(const InputTable& table) { - std::unordered_map index; - for (int i = 0; i < table->GetNumberOfColumns(); ++i) { - index[table->GetColumnName(i)] = i; - } - return std::move(index); -} - -std::vector GetTransposition(const InputTable& table, const InputTable& stream) { - static std::unordered_map index = GetIndexes(table); - std::vector result; - for (int i = 0; i < stream->GetNumberOfColumns(); ++i) { - result.emplace_back(index[stream->GetColumnName(i)]); - } - return std::move(result); -} -} // namespace void algos::DynamicAlgorithm::RegisterOptions() { RegisterOption(config::kTableOpt(&input_table_)); @@ -73,15 +53,16 @@ void algos::DynamicAlgorithm::ValidateInsertStatements(InputTable& data) { return; } if (data->GetNumberOfColumns() != input_table_->GetNumberOfColumns()) { - throw config::ConfigurationError("Invalid data received: the number of columns in the \ + throw config::ConfigurationError( + "Invalid data received: the number of columns in the \ modification statements is different from the table."); } while (data->HasNextRow()) { TableRow row{data->GetNextRow()}; if (row.getData().size() != input_table_->GetNumberOfColumns()) { LOG(WARNING) << "Unexpected number of columns for a row, skipping (expected " - << input_table_->GetNumberOfColumns() << ", got " - << row.getData().size() << ")"; + << input_table_->GetNumberOfColumns() << ", got " << row.getData().size() + << ")"; continue; } insert_statements_.Add(row); @@ -92,8 +73,9 @@ void algos::DynamicAlgorithm::ValidateInsertStatements(InputTable& data) { void algos::DynamicAlgorithm::ValidateDeleteStatements(std::vector& data) { for (size_t rowId : data) { if (!table_rows_ids_.count(rowId)) { - throw config::ConfigurationError("Invalid data received: the row with " + - std::to_string(rowId) + " does not exist in the table."); + throw config::ConfigurationError("Invalid data received: the row with " + + std::to_string(rowId) + + " does not exist in the table."); } else { table_rows_ids_.erase(rowId); delete_statements_.emplace_back(rowId); @@ -107,10 +89,10 @@ void algos::DynamicAlgorithm::ConfigureBatch() { ValidateDeleteStatements(update_old_batch_); ValidateInsertStatements(update_new_batch_); if (insert_statements_.Size() != delete_statements_.size()) { - throw config::ConfigurationError("Invalid data received: number of rows to update: " - + std::to_string(insert_statements_.Size()) - + ", number of rows to update with: " - + std::to_string(delete_statements_.size())); + throw config::ConfigurationError( + "Invalid data received: number of rows to update: " + + std::to_string(insert_statements_.Size()) + + ", number of rows to update with: " + std::to_string(delete_statements_.size())); } // configure insert statements ValidateInsertStatements(insert_batch_); diff --git a/src/core/algorithms/dynamic/dynamic_algorithm.h b/src/core/algorithms/dynamic/dynamic_algorithm.h index e5ea05d07..58a57a003 100644 --- a/src/core/algorithms/dynamic/dynamic_algorithm.h +++ b/src/core/algorithms/dynamic/dynamic_algorithm.h @@ -42,7 +42,7 @@ class DynamicAlgorithm : public Algorithm { // update operations stream (new values) InputTable update_new_batch_; // stores current table rows ids (after last Execute() method call) - std::unordered_set table_rows_ids_ {}; + std::unordered_set table_rows_ids_{}; private: void AddSpecificNeededOptions( diff --git a/src/core/config/descriptions.h b/src/core/config/descriptions.h index 0c4873589..bd2098fb9 100644 --- a/src/core/config/descriptions.h +++ b/src/core/config/descriptions.h @@ -104,8 +104,10 @@ constexpr auto kDGfdData = "Path to file with GFD"; constexpr auto kDMemLimitMB = "memory limit im MBs"; constexpr auto kDInsertStatements = "Rows to be inserted into the table using the insert operation"; constexpr auto kDDeleteStatements = "Rows to be deleted from the table using the delete operation"; -constexpr auto kDUpdateOldStatements = "Rows that need to be replaced in the table using the update operation"; -constexpr auto kDUpdateNewStatements = "Rows that need to be used to replace old data in the table using the update operation"; +constexpr auto kDUpdateOldStatements = + "Rows that need to be replaced in the table using the update operation"; +constexpr auto kDUpdateNewStatements = + "Rows that need to be used to replace old data in the table using the update operation"; constexpr auto kDDifferenceTable = "CSV table containing difference limits for each column"; constexpr auto kDNumRows = "Use only first N rows of the table"; constexpr auto kDNUmColumns = "Use only first N columns of the table"; diff --git a/src/core/config/tabular_data/crud_operations/insert/option.cpp b/src/core/config/tabular_data/crud_operations/insert/option.cpp index c22605a3a..0b6114e15 100644 --- a/src/core/config/tabular_data/crud_operations/insert/option.cpp +++ b/src/core/config/tabular_data/crud_operations/insert/option.cpp @@ -4,6 +4,6 @@ namespace config { using names::kInsertStatements, descriptions::kDInsertStatements; -extern CommonOption const kInsertStatementsOpt = { - kInsertStatements, kDInsertStatements, std::nullopt, nullptr, nullptr}; +extern CommonOption const kInsertStatementsOpt = {kInsertStatements, kDInsertStatements, + std::nullopt, nullptr, nullptr}; } // namespace config diff --git a/src/core/config/tabular_data/crud_operations/operations.h b/src/core/config/tabular_data/crud_operations/operations.h index 075a22f4f..89156b080 100644 --- a/src/core/config/tabular_data/crud_operations/operations.h +++ b/src/core/config/tabular_data/crud_operations/operations.h @@ -1,13 +1,12 @@ #pragma once +#include "config/names.h" #include "delete/option.h" #include "insert/option.h" #include "update_new/option.h" #include "update_old/option.h" -#include "config/names.h" -const std::vector CRUD_OPTIONS{config::names::kInsertStatements, - config::names::kDeleteStatements, - config::names::kUpdateOldStatements, - config::names::kUpdateNewStatements}; +const std::vector CRUD_OPTIONS{ + config::names::kInsertStatements, config::names::kDeleteStatements, + config::names::kUpdateOldStatements, config::names::kUpdateNewStatements}; diff --git a/src/core/model/table/table_row.h b/src/core/model/table/table_row.h index 3de18f2b3..fc382c825 100644 --- a/src/core/model/table/table_row.h +++ b/src/core/model/table/table_row.h @@ -3,6 +3,7 @@ #include #include #include + #include #include "column_index.h" @@ -22,14 +23,14 @@ class TableRow { } public: - TableRow(std::vector&& data) : - data_(std::move(data)), - id_(createId()) {} + TableRow(std::vector&& data) : data_(std::move(data)), id_(createId()) {} TableRow(size_t id) : data_({}), id_(id) {} - TableRow() : data_({}), id_(0) {}; + TableRow() : data_({}), id_(0){}; TableRow(const TableRow& other) : data_(other.data_), id_(other.id_) {} + TableRow(TableRow&& other) : data_(std::move(other.data_)), id_(other.id_) {} + TableRow& operator=(const TableRow& other) { if (this != &other) { data_ = other.data_; @@ -37,6 +38,7 @@ class TableRow { } return *this; } + TableRow& operator=(TableRow&& other) { if (this != &other) { data_ = std::move(other.data_); @@ -50,7 +52,8 @@ class TableRow { } std::string toString() const { - return "(id: " + std::to_string(id_) + ", data: " + boost::algorithm::join(data_, ",") + ")"; + return "(id: " + std::to_string(id_) + ", data: " + boost::algorithm::join(data_, ",") + + ")"; } explicit operator std::string() const { @@ -61,16 +64,14 @@ class TableRow { return id_; } - bool operator==(const TableRow &rhs) const { + bool operator==(const TableRow& rhs) const { return id_ == rhs.getId(); } }; -template<> -struct std::hash -{ - std::size_t operator()(const TableRow& s) const noexcept - { +template <> +struct std::hash { + std::size_t operator()(const TableRow& s) const noexcept { return s.getId(); } }; diff --git a/src/core/util/dynamic_collection.h b/src/core/util/dynamic_collection.h index 12234a3fd..5d8221450 100644 --- a/src/core/util/dynamic_collection.h +++ b/src/core/util/dynamic_collection.h @@ -1,7 +1,8 @@ #pragma once -#include #include +#include + #include "primitive_collection.h" namespace util { @@ -55,7 +56,7 @@ class DynamicCollection { std::vector AsStringVector() const noexcept { std::vector result_; - for (const T &item : collection_) { + for (const T& item : collection_) { result_.emplace_back(std::string(item)); } return result_; diff --git a/src/python_bindings/dynamic/bind_dynamic_algorithms.cpp b/src/python_bindings/dynamic/bind_dynamic_algorithms.cpp index f3c1f9ef4..d8097fb4b 100644 --- a/src/python_bindings/dynamic/bind_dynamic_algorithms.cpp +++ b/src/python_bindings/dynamic/bind_dynamic_algorithms.cpp @@ -4,8 +4,8 @@ #include #include "algorithms/algo_factory.h" -#include "algorithms/dynamic/dynamic_algorithm.h" #include "algorithms/dynamic/demo/demo_algo.h" +#include "algorithms/dynamic/dynamic_algorithm.h" #include "config/names.h" #include "config/tabular_data/crud_operations/operations.h" #include "py_util/bind_primitive.h" diff --git a/src/python_bindings/py_util/py_to_any.cpp b/src/python_bindings/py_util/py_to_any.cpp index 8f262bc0f..338dcfb36 100644 --- a/src/python_bindings/py_util/py_to_any.cpp +++ b/src/python_bindings/py_util/py_to_any.cpp @@ -15,11 +15,11 @@ #include "config/exceptions.h" #include "config/tabular_data/input_table_type.h" #include "config/tabular_data/input_tables_type.h" +#include "model/table/table_row.h" #include "parser/csv_parser/csv_parser.h" #include "py_util/create_dataframe_reader.h" -#include "util/enum_to_available_values.h" -#include "model/table/table_row.h" #include "util/dynamic_collection.h" +#include "util/enum_to_available_values.h" namespace {