diff --git a/.clang-format b/.clang-format index cf919c2481..14bf2ccd4c 100644 --- a/.clang-format +++ b/.clang-format @@ -6,7 +6,7 @@ ContinuationIndentWidth: 8 ColumnLimit: 100 AllowShortFunctionsOnASingleLine: Empty IncludeCategories: - - Regex: '<(spdlog|boost|enum|gmock|gtest|pybind11|Python|frozen).+>' + - Regex: '<(spdlog|boost|magic_enum|gmock|gtest|pybind11|Python).+>' Priority: 2 - Regex: '<.+>' Priority: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index c1aa6cde4f..50318a1b88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,28 +256,11 @@ CPMAddPackage("gh:ktprime/emhash#5f327039a2776f38910e600889acf924a2d99ea3") include_directories(SYSTEM "${emhash_SOURCE_DIR}") CPMAddPackage( - NAME frozen - GITHUB_REPOSITORY serge-sans-paille/frozen - GIT_TAG 1.2.0 - DOWNLOAD_ONLY True -) -include_directories(SYSTEM "${frozen_SOURCE_DIR}/include") - -CPMAddPackage( - NAME better-enums - GITHUB_REPOSITORY aantron/better-enums - GIT_TAG 0.11.3 - DOWNLOAD_ONLY True -) -include_directories(SYSTEM "${better-enums_SOURCE_DIR}") - -CPMAddPackage( - NAME atomicbitvector - GITHUB_REPOSITORY ekg/atomicbitvector - GIT_TAG e295358fea9532fa4c37197630d037a4a53ddede - DOWNLOAD_ONLY True + NAME magic_enum + GITHUB_REPOSITORY Neargye/magic_enum + VERSION 0.9.7 + SYSTEM YES ) -include_directories(SYSTEM "${atomicbitvector_SOURCE_DIR}/include") if(DESBORDANTE_BUILD_TESTS) CPMAddPackage( diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c730bffada..271e2a143f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -37,6 +37,7 @@ target_link_libraries( PRIVATE ${Boost_LIBRARIES} # Boost components specified in find_package Threads::Threads # System threading library PUBLIC spdlog::spdlog_header_only # Logging infrastructure exposed in headers + magic_enum::magic_enum # Enum reflection used in headers ) # Propagate the setting to all consumers of the library diff --git a/src/core/algorithms/algebraic_constraints/ac_algorithm.cpp b/src/core/algorithms/algebraic_constraints/ac_algorithm.cpp index 1dda94b968..b776868cd2 100644 --- a/src/core/algorithms/algebraic_constraints/ac_algorithm.cpp +++ b/src/core/algorithms/algebraic_constraints/ac_algorithm.cpp @@ -26,16 +26,16 @@ void ACAlgorithm::RegisterOptions() { auto check_and_set_binop = [this](Binop bin_operation) { switch (bin_operation) { - case +Binop::Addition: + case Binop::kAddition: binop_pointer_ = &model::INumericType::Add; break; - case +Binop::Subtraction: + case Binop::kSubtraction: binop_pointer_ = &model::INumericType::Sub; break; - case +Binop::Multiplication: + case Binop::kMultiplication: binop_pointer_ = &model::INumericType::Mul; break; - case +Binop::Division: + case Binop::kDivision: binop_pointer_ = &model::INumericType::Div; break; default: @@ -172,7 +172,7 @@ std::vector ACAlgorithm::SamplingIteration( } auto res = std::unique_ptr(num_type_->Allocate()); num_type_->ValueFromStr(res.get(), "0"); - if (bin_operation_ == +Binop::Division && + if (bin_operation_ == Binop::kDivision && num_type_->Compare(r, res.get()) == model::CompareResult::kEqual) { continue; } @@ -335,7 +335,7 @@ unsigned long long ACAlgorithm::ExecuteInternal() { /* Because of asymmetry and division by 0, we need to rediscover ranges. * We don't need to do that for minus: (column1 - column2) lies in *some ranges* * there we can express one column through another without possible problems */ - if (bin_operation_ == +Binop::Division) { + if (bin_operation_ == Binop::kDivision) { ranges_.emplace_back( RangesCollection{model::CreateSpecificType( data.at(col_i).GetTypeId(), true), diff --git a/src/core/algorithms/algebraic_constraints/ac_algorithm.h b/src/core/algorithms/algebraic_constraints/ac_algorithm.h index a76810ca5d..d9359a75ce 100644 --- a/src/core/algorithms/algebraic_constraints/ac_algorithm.h +++ b/src/core/algorithms/algebraic_constraints/ac_algorithm.h @@ -4,8 +4,6 @@ #include #include -#include - #include "core/algorithms/algebraic_constraints/ac.h" #include "core/algorithms/algebraic_constraints/ac_exception.h" #include "core/algorithms/algebraic_constraints/ac_exception_finder.h" @@ -39,7 +37,7 @@ class ACAlgorithm : public Algorithm { config::InputTable input_table_; - Binop bin_operation_ = Binop::_values()[0]; + Binop bin_operation_ = magic_enum::enum_values().front(); /* Desired ratio of exceptions. Value lies in (0, 1] */ double fuzziness_; /* Value lies in (0, 1]. Closer to 0 - many short intervals. diff --git a/src/core/algorithms/algebraic_constraints/ac_exception_finder.cpp b/src/core/algorithms/algebraic_constraints/ac_exception_finder.cpp index 1405b26fc1..11d9817f3d 100644 --- a/src/core/algorithms/algebraic_constraints/ac_exception_finder.cpp +++ b/src/core/algorithms/algebraic_constraints/ac_exception_finder.cpp @@ -49,7 +49,7 @@ void ACExceptionFinder::CollectColumnPairExceptions(std::vector(num_type->Allocate()); num_type->ValueFromStr(res.get(), "0"); - if (ac_alg_->GetBinOperation() == +Binop::Division && + if (ac_alg_->GetBinOperation() == Binop::kDivision && num_type->Compare(r, res.get()) == model::CompareResult::kEqual) { continue; } diff --git a/src/core/algorithms/algebraic_constraints/bin_operation_enum.h b/src/core/algorithms/algebraic_constraints/bin_operation_enum.h index c22d0d803c..3ac266011b 100644 --- a/src/core/algorithms/algebraic_constraints/bin_operation_enum.h +++ b/src/core/algorithms/algebraic_constraints/bin_operation_enum.h @@ -1,9 +1,13 @@ #pragma once -#include +#include namespace algos { -BETTER_ENUM(Binop, char, Addition = '+', Subtraction = '-', Multiplication = '*', Division = '/'); - +enum class Binop : char { + kAddition = '+', + kSubtraction = '-', + kMultiplication = '*', + kDivision = '/' +}; } // namespace algos diff --git a/src/core/algorithms/algorithm_types.h b/src/core/algorithms/algorithm_types.h index 70cbbef635..9df7a0210c 100644 --- a/src/core/algorithms/algorithm_types.h +++ b/src/core/algorithms/algorithm_types.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "core/algorithms/algorithms.h" @@ -21,87 +21,88 @@ using AlgorithmTypes = * NOTE: algorithm string name representation is taken from the value in this * enum, so name it appropriately (lowercase and without additional symbols). */ -BETTER_ENUM(AlgorithmType, char, + +enum class AlgorithmType : char { /* Functional dependency mining algorithms */ - depminer = 0, - dfd, - fastfds, - fdep, - fdmine, - pyro, - tane, - pfdtane, - fun, - hyfd, - aidfd, - eulerfd, + kDepminer = 0, + kDfd, + kFastfds, + kFdep, + kFdmine, + kPyro, + kTane, + kPfdtane, + kFun, + kHyfd, + kAidfd, + kEulerfd, /* Association rules mining algorithms */ - apriori, + kApriori, /* Numerical association rules mining algorithms*/ - des, + kDes, /* Metric verifier algorithm */ - metric, + kMetric, /* Statistic algorithms */ - stats, + kStats, /* FD verifier algorithm */ - fd_verifier, + kFdVerifier, /* Unique Column Combination mining algorithms */ - hyucc, - pyroucc, - hpivalid, + kHyucc, + kPyroucc, + kHpivalid, /* CFD mining algorithms */ - fd_first_dfs, + kFdFirstDfs, /* Algebraic constraints mining algorithm*/ - ac, + kAc, /* UCC verifier algorithm */ - ucc_verifier, + kUccVerifier, /* Inclusion dependency mining algorithms */ - faida, - spider, - mind, + kFaida, + kSpider, + kMind, /* IND verifier algorithm */ - ind_verifier, + kIndVerifier, /* Order dependency mining algorithms */ - fastod, + kFastod, /* Graph functional dependency mining algorithms */ - gfdvalid, - egfdvalid, - naivegfdvalid, + kGfdvalid, + kEgfdvalid, + kNaivegfdvalid, /* Order dependency mining algorithms */ - order, + kOrder, /* Differential dependencies mining algorithm */ - split, + kSplit, /* SFD mining algorithm */ - cords, + kCords, /* MD mining algorithms */ - hymd, + kHymd, /* PFD verifier algorithm */ - pfd_verifier, + kPfdVerifier, /* CFD verifier algorithm */ - cfd_verifier -) + kCfdVerifier +}; // clang-format on -static_assert(std::tuple_size_v == AlgorithmType::_size(), +static_assert(std::tuple_size_v == magic_enum::enum_count(), "The AlgorithmTypes tuple and the AlgorithmType enum sizes must be the same. Did you " "forget to add your new algorithm to either of those?"); diff --git a/src/core/algorithms/association_rules/ar_algorithm.cpp b/src/core/algorithms/association_rules/ar_algorithm.cpp index 0da8de06fd..32d3090f7c 100644 --- a/src/core/algorithms/association_rules/ar_algorithm.cpp +++ b/src/core/algorithms/association_rules/ar_algorithm.cpp @@ -20,8 +20,8 @@ ARAlgorithm::ARAlgorithm(std::vector phase_names) void ARAlgorithm::RegisterOptions() { DESBORDANTE_OPTION_USING; - auto sing_eq = [](InputFormat input_format) { return input_format == +InputFormat::singular; }; - auto tab_eq = [](InputFormat input_format) { return input_format == +InputFormat::tabular; }; + auto sing_eq = [](InputFormat input_format) { return input_format == InputFormat::kSingular; }; + auto tab_eq = [](InputFormat input_format) { return input_format == InputFormat::kTabular; }; RegisterOption(config::kTableOpt(&input_table_)); RegisterOption(Option{&first_column_tid_, kFirstColumnTId, kDFirstColumnTId, false}); @@ -45,11 +45,11 @@ void ARAlgorithm::MakeExecuteOptsAvailable() { void ARAlgorithm::LoadDataInternal() { switch (input_format_) { - case InputFormat::singular: + case InputFormat::kSingular: transactional_data_ = model::TransactionalData::CreateFromSingular( *input_table_, tid_column_index_, item_column_index_); break; - case InputFormat::tabular: + case InputFormat::kTabular: transactional_data_ = model::TransactionalData::CreateFromTabular(*input_table_, first_column_tid_); break; diff --git a/src/core/algorithms/association_rules/ar_algorithm.h b/src/core/algorithms/association_rules/ar_algorithm.h index b137be14c8..e07d99c06b 100644 --- a/src/core/algorithms/association_rules/ar_algorithm.h +++ b/src/core/algorithms/association_rules/ar_algorithm.h @@ -20,7 +20,7 @@ class ARAlgorithm : public Algorithm { config::InputTable input_table_; double minconf_; - InputFormat input_format_ = InputFormat::singular; + InputFormat input_format_ = InputFormat::kSingular; unsigned int tid_column_index_; unsigned int item_column_index_; bool first_column_tid_; diff --git a/src/core/algorithms/association_rules/ar_algorithm_enums.h b/src/core/algorithms/association_rules/ar_algorithm_enums.h index 760141018c..1b256d39f7 100644 --- a/src/core/algorithms/association_rules/ar_algorithm_enums.h +++ b/src/core/algorithms/association_rules/ar_algorithm_enums.h @@ -1,9 +1,8 @@ #pragma once -#include +#include namespace algos { -BETTER_ENUM(InputFormat, char, singular = 0, tabular); - +enum class InputFormat : char { kSingular = 0, kTabular }; } // namespace algos diff --git a/src/core/algorithms/cfd/enums.h b/src/core/algorithms/cfd/enums.h index 41ce42bc93..f03bdb97cc 100644 --- a/src/core/algorithms/cfd/enums.h +++ b/src/core/algorithms/cfd/enums.h @@ -1,12 +1,11 @@ #pragma once -#include +#include namespace algos::cfd { -// Defines what kind of lattice traversal will be used in pattern mining part of the algorithm. -BETTER_ENUM(Substrategy, char, - dfs = 0, // dfs lattice traversal - bfs // bfs lattice traversal -); +enum class Substrategy : char { + kDfs = 0, // dfs lattice traversal + kBfs // bfs lattice traversal +}; } // namespace algos::cfd diff --git a/src/core/algorithms/cfd/fd_first_algorithm.cpp b/src/core/algorithms/cfd/fd_first_algorithm.cpp index 64a7b31095..1d8bb35d1f 100644 --- a/src/core/algorithms/cfd/fd_first_algorithm.cpp +++ b/src/core/algorithms/cfd/fd_first_algorithm.cpp @@ -25,7 +25,7 @@ FDFirstAlgorithm::FDFirstAlgorithm() : CFDDiscovery({kDefaultPhaseName}) { void FDFirstAlgorithm::RegisterOptions() { DESBORDANTE_OPTION_USING; - Substrategy default_val = Substrategy::dfs; + Substrategy default_val = Substrategy::kDfs; RegisterOption(Option{&min_supp_, kCfdMinimumSupport, kDCfdMinimumSupport, 0u}); RegisterOption(Option{&min_conf_, kCfdMinimumConfidence, kDCfdMinimumConfidence, 0.0}); RegisterOption(Option{&max_lhs_, kCfdMaximumLhs, kDCfdMaximumLhs, 0u}); @@ -230,9 +230,9 @@ void FDFirstAlgorithm::FdsFirstDFS(Itemset const& prefix, PIdListMiners const& i Itemset const sub = ConstructSubset(iset, out); MineFD(inode, sub, out); - if (ss == +Substrategy::dfs) { + if (ss == Substrategy::kDfs) { MinePatternsDFS(sub, out, inode.tids); - } else if (ss == +Substrategy::bfs) { + } else if (ss == Substrategy::kBfs) { MinePatternsBFS(sub, out, inode.tids); } } diff --git a/src/core/algorithms/cfd/fd_first_algorithm.h b/src/core/algorithms/cfd/fd_first_algorithm.h index 5407d18a41..f24e82cbd5 100644 --- a/src/core/algorithms/cfd/fd_first_algorithm.h +++ b/src/core/algorithms/cfd/fd_first_algorithm.h @@ -19,7 +19,7 @@ class FDFirstAlgorithm : public algos::cfd::CFDDiscovery { unsigned max_cfd_size_; unsigned max_lhs_; double min_conf_; - Substrategy substrategy_ = Substrategy::dfs; + Substrategy substrategy_ = Substrategy::kDfs; std::map store_; PrefixTree cand_store_; @@ -33,7 +33,7 @@ class FDFirstAlgorithm : public algos::cfd::CFDDiscovery { void FdsFirstDFS(); void FdsFirstDFS(Itemset const &, std::vector> const &, - Substrategy = Substrategy::dfs); + Substrategy = Substrategy::kDfs); void MinePatternsBFS(Itemset const &lhs, int rhs, PartitionTIdList const &all_tids); void MinePatternsDFS(Itemset const &lhs, int rhs, PartitionTIdList const &all_tids); void MinePatternsDFS(Itemset const &, std::vector> &, Itemset const &, diff --git a/src/core/algorithms/create_algorithm.h b/src/core/algorithms/create_algorithm.h index 75208119f8..fe1b204764 100644 --- a/src/core/algorithms/create_algorithm.h +++ b/src/core/algorithms/create_algorithm.h @@ -37,7 +37,7 @@ bool IsBaseOf(AlgorithmType algorithm) { template std::vector GetAllDerived() { std::vector derived_from_base{}; - for (AlgorithmType algo : AlgorithmType::_values()) { + for (AlgorithmType algo : magic_enum::enum_values()) { if (IsBaseOf(algo)) { derived_from_base.push_back(algo); } diff --git a/src/core/algorithms/dc/FastADC/fastadc.cpp b/src/core/algorithms/dc/FastADC/fastadc.cpp index 2f42f39b91..6d9e4ab7d5 100644 --- a/src/core/algorithms/dc/FastADC/fastadc.cpp +++ b/src/core/algorithms/dc/FastADC/fastadc.cpp @@ -74,13 +74,13 @@ void FastADC::CheckTypes() { model::TypedColumnData const& column = typed_relation_->GetColumnData(column_index); model::TypeId type_id = column.GetTypeId(); - if (type_id == +model::TypeId::kMixed) { + if (type_id == model::TypeId::kMixed) { LOG_WARN( "Column with index \"{}\" contains values of different types. Those values " "will be " "treated as strings.", column_index); - } else if (!column.IsNumeric() && type_id != +model::TypeId::kString) { + } else if (!column.IsNumeric() && type_id != model::TypeId::kString) { throw std::invalid_argument( "Column with index \"" + std::to_string(column_index) + "\" is of unsupported type. Only numeric and string types are supported."); diff --git a/src/core/algorithms/dc/FastADC/model/column_operand.h b/src/core/algorithms/dc/FastADC/model/column_operand.h index 156366ae96..77b59456a1 100644 --- a/src/core/algorithms/dc/FastADC/model/column_operand.h +++ b/src/core/algorithms/dc/FastADC/model/column_operand.h @@ -1,8 +1,9 @@ #pragma once -#include +#include #include "core/model/table/column.h" +#include "core/util/enum_to_str.h" namespace algos::fastadc { @@ -25,7 +26,7 @@ namespace algos::fastadc { * indicates an operand from the first tuple (t), and `ColumnOperandTuple::S` indicates an operand * from the second tuple (s). */ -BETTER_ENUM(ColumnOperandTuple, char, t, s); +enum class ColumnOperandTuple : char { kT, kS }; // TODO: remove code duplication cause we already have "dc/model/column_operand.h" that is used for // DC verification. @@ -35,7 +36,7 @@ class ColumnOperand { ColumnOperandTuple tuple_; static ColumnOperandTuple Invert(ColumnOperandTuple tuple) { - return tuple == +ColumnOperandTuple::t ? ColumnOperandTuple::s : ColumnOperandTuple::t; + return tuple == ColumnOperandTuple::kT ? ColumnOperandTuple::kS : ColumnOperandTuple::kT; } public: @@ -60,7 +61,7 @@ class ColumnOperand { } std::string ToString() const { - return std::string(tuple_._to_string()) + "." + column_->GetName(); + return util::EnumToStr(tuple_) + "." + column_->GetName(); } }; @@ -75,7 +76,7 @@ struct std::hash { size_t operator()(algos::fastadc::ColumnOperand const& k) const noexcept { size_t seed = 0; boost::hash_combine(seed, k.GetColumn()->GetIndex()); - boost::hash_combine(seed, k.GetTuple()._value); + boost::hash_combine(seed, magic_enum::enum_integer(k.GetTuple())); return seed; } }; diff --git a/src/core/algorithms/dc/FastADC/model/operator.h b/src/core/algorithms/dc/FastADC/model/operator.h index 21a22a2c0a..9284743200 100644 --- a/src/core/algorithms/dc/FastADC/model/operator.h +++ b/src/core/algorithms/dc/FastADC/model/operator.h @@ -3,11 +3,10 @@ #include #include #include - -#include -#include +#include #include "core/model/types/type.h" +#include "core/util/static_map.h" namespace algos::fastadc { @@ -63,50 +62,52 @@ class Operator { static constexpr OperatorType kLeTransitives[] = {OperatorType::kLess, OperatorType::kLessEqual, OperatorType::kEqual}; - using OperatorMapType = frozen::unordered_map; - using OperatorMapSpan = frozen::unordered_map; - using OperatorMapString = frozen::unordered_map; + using OperatorMapType = util::StaticMap; + using OperatorMapSpan = util::StaticMap; + using OperatorMapString = util::StaticMap; - static constexpr OperatorMapType kInverseMap{ + static constexpr OperatorMapType kInverseMap{{{ {OperatorType::kEqual, OperatorType::kUnequal}, {OperatorType::kUnequal, OperatorType::kEqual}, {OperatorType::kGreater, OperatorType::kLessEqual}, {OperatorType::kLess, OperatorType::kGreaterEqual}, {OperatorType::kGreaterEqual, OperatorType::kLess}, {OperatorType::kLessEqual, OperatorType::kGreater}, - }; + }}}; - static constexpr OperatorMapType kSymmetricMap{ + static constexpr OperatorMapType kSymmetricMap{{{ {OperatorType::kEqual, OperatorType::kEqual}, {OperatorType::kUnequal, OperatorType::kUnequal}, {OperatorType::kGreater, OperatorType::kLess}, {OperatorType::kLess, OperatorType::kGreater}, {OperatorType::kGreaterEqual, OperatorType::kLessEqual}, {OperatorType::kLessEqual, OperatorType::kGreaterEqual}, - }; + }}}; - static constexpr OperatorMapSpan kImplicationsMap{ + static constexpr OperatorMapSpan kImplicationsMap{{{ {OperatorType::kEqual, OperatorSpan(kEqImplications, 3)}, {OperatorType::kUnequal, OperatorSpan(kUneqImplications, 1)}, {OperatorType::kGreater, OperatorSpan(kGtImplications, 3)}, {OperatorType::kLess, OperatorSpan(kLtImplications, 3)}, {OperatorType::kGreaterEqual, OperatorSpan(kGeImplications, 1)}, {OperatorType::kLessEqual, OperatorSpan(kLeImplications, 1)}, - }; + }}}; - static constexpr OperatorMapSpan kTransitivesMap{ + static constexpr OperatorMapSpan kTransitivesMap{{{ {OperatorType::kEqual, OperatorSpan(kEqTransitives, 1)}, {OperatorType::kUnequal, OperatorSpan(kUneqTransitives, 1)}, {OperatorType::kGreater, OperatorSpan(kGtTransitives, 3)}, {OperatorType::kLess, OperatorSpan(kLtTransitives, 3)}, {OperatorType::kGreaterEqual, OperatorSpan(kGeTransitives, 3)}, {OperatorType::kLessEqual, OperatorSpan(kLeTransitives, 3)}, - }; + }}}; - static constexpr OperatorMapString kOperatorTypeToString{ - {OperatorType::kEqual, "=="}, {OperatorType::kUnequal, "!="}, - {OperatorType::kGreater, ">"}, {OperatorType::kLess, "<"}, - {OperatorType::kGreaterEqual, ">="}, {OperatorType::kLessEqual, "<="}}; + static constexpr OperatorMapString kOperatorTypeToString{{{{OperatorType::kEqual, "=="}, + {OperatorType::kUnequal, "!="}, + {OperatorType::kGreater, ">"}, + {OperatorType::kLess, "<"}, + {OperatorType::kGreaterEqual, ">="}, + {OperatorType::kLessEqual, "<="}}}}; public: Operator(OperatorType type) : op_(type) {} @@ -118,27 +119,27 @@ class Operator { // 'a op b' <=> !'a op.inverse b' Operator GetInverse() const { - return Operator(kInverseMap.at(op_)); + return Operator(kInverseMap.At(op_)); } // 'a op b' <=> 'b op.symmetric a' Operator GetSymmetric() const { - return Operator(kSymmetricMap.at(op_)); + return Operator(kSymmetricMap.At(op_)); } // If 'a op b', then 'a op.implications[i] b' OperatorSpan GetImplications() const { - return kImplicationsMap.at(op_); + return kImplicationsMap.At(op_); } // If 'a op b' and 'b op.transitives[i] c', then 'a op c' OperatorSpan GetTransitives() const { - return kTransitivesMap.at(op_); + return kTransitivesMap.At(op_); } std::string ToString() const { - frozen::string str = kOperatorTypeToString.at(op_); - return {str.begin(), str.end()}; + std::string_view sv = kOperatorTypeToString.At(op_); + return std::string(sv); } OperatorType GetType() const { diff --git a/src/core/algorithms/dc/FastADC/model/predicate.cpp b/src/core/algorithms/dc/FastADC/model/predicate.cpp index 0148659ee2..cb94ee56e7 100644 --- a/src/core/algorithms/dc/FastADC/model/predicate.cpp +++ b/src/core/algorithms/dc/FastADC/model/predicate.cpp @@ -27,8 +27,8 @@ bool Predicate::Satisfies(std::vector& col_data, size_t model::Type const& type = lhs_type; - std::byte const* l_val = lhs.GetValue(l_.GetTuple() == +ColumnOperandTuple::t ? t : s); - std::byte const* r_val = rhs.GetValue(r_.GetTuple() == +ColumnOperandTuple::t ? t : s); + std::byte const* l_val = lhs.GetValue(l_.GetTuple() == ColumnOperandTuple::kT ? t : s); + std::byte const* r_val = rhs.GetValue(r_.GetTuple() == ColumnOperandTuple::kT ? t : s); return op_.Eval(l_val, r_val, type); } diff --git a/src/core/algorithms/dc/FastADC/util/predicate_builder.cpp b/src/core/algorithms/dc/FastADC/util/predicate_builder.cpp index c17b207ae6..05b3fd484c 100644 --- a/src/core/algorithms/dc/FastADC/util/predicate_builder.cpp +++ b/src/core/algorithms/dc/FastADC/util/predicate_builder.cpp @@ -79,8 +79,8 @@ void PredicateBuilder::ProcessColumnPair(size_t i, size_t j, bool comparable = IsComparable(input[i], input[j]); if (joinable || comparable) { - ColumnOperand t_col_op(input[i].GetColumn(), ColumnOperandTuple::t); - ColumnOperand s_col_op(input[j].GetColumn(), ColumnOperandTuple::s); + ColumnOperand t_col_op(input[i].GetColumn(), ColumnOperandTuple::kT); + ColumnOperand s_col_op(input[j].GetColumn(), ColumnOperandTuple::kS); AddAndCategorizePredicate(t_col_op, s_col_op, comparable); } } diff --git a/src/core/algorithms/dc/model/operator.h b/src/core/algorithms/dc/model/operator.h index 71cd5693f2..967ff5af53 100644 --- a/src/core/algorithms/dc/model/operator.h +++ b/src/core/algorithms/dc/model/operator.h @@ -2,9 +2,11 @@ #include #include +#include -#include -#include +#include + +#include "core/util/static_map.h" namespace algos::dc { @@ -17,16 +19,18 @@ class Operator { public: constexpr Operator(OperatorType type) noexcept : op_(type) {} - Operator(std::string str_op) { - frozen::string s = {str_op.data(), str_op.size()}; - auto it = kStringToOperatorType.find(s); - if (it == kStringToOperatorType.end()) throw std::invalid_argument("Unknown operator"); - op_ = it->second; + Operator(std::string_view str_op) { + OperatorType const* op_ptr = kStringToOperatorType.Find(str_op); + if (op_ptr == nullptr) { + throw std::invalid_argument("Unknown operator: " + std::string(str_op)); + } + + op_ = *op_ptr; } std::string ToString() const { - frozen::string str = kOperatorTypeToString.at(op_); - return str.data(); + std::string_view sv = kOperatorTypeToString.At(op_); + return std::string(sv); } bool operator==(Operator const& rhs) const noexcept { @@ -41,15 +45,21 @@ class Operator { return op_; } - static constexpr frozen::unordered_map kOperatorTypeToString{ - {OperatorType::kEqual, "=="}, {OperatorType::kUnequal, "!="}, - {OperatorType::kGreater, ">"}, {OperatorType::kLess, "<"}, - {OperatorType::kGreaterEqual, ">="}, {OperatorType::kLessEqual, "<="}}; + static constexpr util::StaticMap kOperatorTypeToString{ + {{{OperatorType::kEqual, "=="}, + {OperatorType::kUnequal, "!="}, + {OperatorType::kGreater, ">"}, + {OperatorType::kLess, "<"}, + {OperatorType::kGreaterEqual, ">="}, + {OperatorType::kLessEqual, "<="}}}}; - static constexpr frozen::unordered_map kStringToOperatorType{ - {"==", OperatorType::kEqual}, {"!=", OperatorType::kUnequal}, - {">", OperatorType::kGreater}, {"<", OperatorType::kLess}, - {">=", OperatorType::kGreaterEqual}, {"<=", OperatorType::kLessEqual}}; + static constexpr util::StaticMap kStringToOperatorType{ + {{{"==", OperatorType::kEqual}, + {"!=", OperatorType::kUnequal}, + {">", OperatorType::kGreater}, + {"<", OperatorType::kLess}, + {">=", OperatorType::kGreaterEqual}, + {"<=", OperatorType::kLessEqual}}}}; }; } // namespace algos::dc diff --git a/src/core/algorithms/dc/parser/dc_parser.cpp b/src/core/algorithms/dc/parser/dc_parser.cpp index a65d45f76a..dec85eeb56 100644 --- a/src/core/algorithms/dc/parser/dc_parser.cpp +++ b/src/core/algorithms/dc/parser/dc_parser.cpp @@ -22,10 +22,11 @@ DCParser::DCParser(std::string dc_string, ColumnLayoutRelationData const* relati dc_string_(std::move(dc_string)), has_next_predicate_(true), cur_(0) { + // TODO: Consider changing str_operations_ to std::vector + // as the source are static string literals. str_operators_.reserve(str_operators_.size()); - for (auto const& [frozen_str, _] : Operator::kStringToOperatorType) { - std::string str_op = frozen_str.data(); - str_operators_.emplace_back(std::move(str_op)); + for (auto const& pair : Operator::kStringToOperatorType) { + str_operators_.emplace_back(pair.first); } }; @@ -95,7 +96,8 @@ Predicate DCParser::ConvertToPredicate(std::string const& pred) { auto [left_operand, right_operand] = GetOperands(str_left_operand, str_right_operand); - return {std::move(str_operator), std::move(left_operand), std::move(right_operand)}; + Operator op(str_operator); + return {op, std::move(left_operand), std::move(right_operand)}; } std::pair DCParser::GetOperands(std::string str_left_op, diff --git a/src/core/algorithms/dc/verifier/dc_verifier.cpp b/src/core/algorithms/dc/verifier/dc_verifier.cpp index d32c79e8e2..ae706a2633 100644 --- a/src/core/algorithms/dc/verifier/dc_verifier.cpp +++ b/src/core/algorithms/dc/verifier/dc_verifier.cpp @@ -110,7 +110,7 @@ bool DCVerifier::Verify(dc::DC dc) { if (dc_type == dc::DCType::kOneInequality and do_collect_violations_ == true) dc_type = dc::DCType::kTwoTuples; - auto check = kDCTypeToVerificationMethod.at(dc_type); + auto check = kDCTypeToVerificationMethod.At(dc_type); // TODO: check the article for optimization 2^l -> 2^(l-1) dc's diff --git a/src/core/algorithms/dc/verifier/dc_verifier.h b/src/core/algorithms/dc/verifier/dc_verifier.h index dd70169f92..2b2216225c 100644 --- a/src/core/algorithms/dc/verifier/dc_verifier.h +++ b/src/core/algorithms/dc/verifier/dc_verifier.h @@ -6,8 +6,6 @@ #include #include -#include - #include "core/algorithms/algorithm.h" #include "core/algorithms/dc/model/dc.h" #include "core/algorithms/dc/model/point.h" @@ -16,9 +14,9 @@ #include "core/model/table/column_layout_relation_data.h" #include "core/model/table/typed_column_data.h" #include "core/util/kdtree.h" +#include "core/util/static_map.h" namespace algos { - namespace dc { struct SetComparator { bool operator()(std::pair const& lhs, @@ -92,13 +90,13 @@ class DCVerifier final : public Algorithm { dc::DC GetDC(std::vector const& no_diseq_preds, std::vector const& diseq_preds, size_t cur_signs); - static constexpr frozen::unordered_map + static constexpr util::StaticMap kDCTypeToVerificationMethod{ - {dc::DCType::kAllEquality, &DCVerifier::VerifyAllEquality}, - {dc::DCType::kOneInequality, &DCVerifier::VerifyOneInequality}, - {dc::DCType::kOneTuple, &DCVerifier::VerifyOneTuple}, - {dc::DCType::kTwoTuples, &DCVerifier::VerifyTwoTuples}, - {dc::DCType::kMixed, &DCVerifier::VerifyMixed}}; + {{{dc::DCType::kAllEquality, &DCVerifier::VerifyAllEquality}, + {dc::DCType::kOneInequality, &DCVerifier::VerifyOneInequality}, + {dc::DCType::kOneTuple, &DCVerifier::VerifyOneTuple}, + {dc::DCType::kTwoTuples, &DCVerifier::VerifyTwoTuples}, + {dc::DCType::kMixed, &DCVerifier::VerifyMixed}}}}; template void AddHighlights(InputIt first, InputIt last, size_t cur_index) { diff --git a/src/core/algorithms/dd/dd_verifier/dd_verifier.cpp b/src/core/algorithms/dd/dd_verifier/dd_verifier.cpp index bc27e6df89..2d0764f23d 100644 --- a/src/core/algorithms/dd/dd_verifier/dd_verifier.cpp +++ b/src/core/algorithms/dd/dd_verifier/dd_verifier.cpp @@ -50,11 +50,11 @@ bool DDVerifier::IsColumnMetrizable(model::ColumnIndex const column_index) const model::TypedColumnData const &column = typed_relation_->GetColumnData(column_index); model::TypeId const type_id = column.GetTypeId(); - if (type_id == +model::TypeId::kUndefined) { + if (type_id == model::TypeId::kUndefined) { throw std::invalid_argument("Column with index \"" + std::to_string(column_index) + "\" type undefined."); } - if (type_id == +model::TypeId::kMixed) { + if (type_id == model::TypeId::kMixed) { throw std::invalid_argument("Column with index \"" + std::to_string(column_index) + "\" contains values of different types."); } diff --git a/src/core/algorithms/dd/split/enums.h b/src/core/algorithms/dd/split/enums.h index 7437fac0d5..95ad7001a6 100644 --- a/src/core/algorithms/dd/split/enums.h +++ b/src/core/algorithms/dd/split/enums.h @@ -1,13 +1,14 @@ #pragma once -#include +#include namespace algos::dd { // Defines what strategy of reducing dependencies will be used in the algorithm -BETTER_ENUM(Reduce, char, - Negative = 0, // negative pruning reduce - Hybrid, // hybrid pruning reduce - IEHybrid // instance exclusion reduce (currently, the fastest) -); +enum class Reduce : char { + kNegative = 0, // negative pruning reduce + kHybrid, // hybrid pruning reduce + kIeHybrid // instance exclusion reduce (currently, the fastest) + +}; } // namespace algos::dd diff --git a/src/core/algorithms/dd/split/split.cpp b/src/core/algorithms/dd/split/split.cpp index 65174718e0..b91bdbb8e3 100644 --- a/src/core/algorithms/dd/split/split.cpp +++ b/src/core/algorithms/dd/split/split.cpp @@ -83,11 +83,11 @@ void Split::CheckTypes() { model::TypedColumnData const& column = typed_relation_->GetColumnData(column_index); model::TypeId type_id = column.GetTypeId(); - if (type_id == +model::TypeId::kUndefined) { + if (type_id == model::TypeId::kUndefined) { throw std::invalid_argument("Column with index \"" + std::to_string(column_index) + "\" type undefined."); } - if (type_id == +model::TypeId::kMixed) { + if (type_id == model::TypeId::kMixed) { throw std::invalid_argument("Column with index \"" + std::to_string(column_index) + "\" contains values of different types."); } @@ -134,7 +134,7 @@ unsigned long long Split::ExecuteInternal() { std::chrono::system_clock::now() - start_time); LOG_DEBUG("Current time: {}", elapsed_milliseconds.count()); - if (reduce_method_ == +Reduce::IEHybrid) { + if (reduce_method_ == Reduce::kIeHybrid) { CalculateTuplePairs(); } @@ -177,7 +177,7 @@ unsigned Split::ReduceDDs(auto const& start_time) { std::list
reduced; std::vector tuple_pair_indices; - if (reduce_method_ == +Reduce::IEHybrid) { + if (reduce_method_ == Reduce::kIeHybrid) { tuple_pair_indices.resize(tuple_pair_num_); std::iota(tuple_pair_indices.begin(), tuple_pair_indices.end(), 0); } @@ -203,13 +203,13 @@ unsigned Split::ReduceDDs(auto const& start_time) { unsigned cnt = 0; if (df_y != dfs_y.front()) { switch (reduce_method_) { - case +Reduce::Negative: + case Reduce::kNegative: reduced = NegativePruningReduce(df_y, search, cnt); break; - case +Reduce::Hybrid: + case Reduce::kHybrid: reduced = HybridPruningReduce(df_y, search, cnt); break; - case +Reduce::IEHybrid: + case Reduce::kIeHybrid: reduced = InstanceExclusionReduce(tuple_pair_indices, search, df_y, cnt); break; default: @@ -362,7 +362,7 @@ inline bool Split::CheckDFConstraint(DFConstraint const& dif_constraint, ClusterIndex const max_cluster = std::max(first_cluster, second_cluster); double const dif = distances_[column_index][min_cluster][max_cluster - min_cluster]; - if (type_ids_[column_index] == +model::TypeId::kDouble) { + if (type_ids_[column_index] == model::TypeId::kDouble) { return dif_constraint.Contains(dif); } @@ -454,7 +454,7 @@ std::vector Split::IndexSearchSpace(model::ColumnIndex index) { for (std::size_t row_index = 0; row_index < dif_num_rows; row_index++) { model::TypeId type_id = dif_column.GetValueTypeId(row_index); - if (type_id == +model::TypeId::kString) { + if (type_id == model::TypeId::kString) { std::string df_str = dif_column.GetDataAsString(row_index); boost::smatch matches; if (boost::regex_match(df_str, matches, df_regex)) { diff --git a/src/core/algorithms/dd/split/split.h b/src/core/algorithms/dd/split/split.h index 29401c5e20..525b62a304 100644 --- a/src/core/algorithms/dd/split/split.h +++ b/src/core/algorithms/dd/split/split.h @@ -38,7 +38,7 @@ class Split : public Algorithm { config::InputTable difference_table_; std::unique_ptr difference_typed_relation_; - Reduce const reduce_method_ = Reduce::IEHybrid; // currently, the fastest method + Reduce const reduce_method_ = Reduce::kIeHybrid; // currently, the fastest method unsigned const num_dfs_per_column_ = 5; std::vector plis_; diff --git a/src/core/algorithms/fd/fd_verifier/stats_calculator.cpp b/src/core/algorithms/fd/fd_verifier/stats_calculator.cpp index 54d4dc823e..7ef1ec369d 100644 --- a/src/core/algorithms/fd/fd_verifier/stats_calculator.cpp +++ b/src/core/algorithms/fd/fd_verifier/stats_calculator.cpp @@ -34,7 +34,7 @@ model::CompareResult CompareTypesInCol(model::TypedColumnData const& col, std::byte const* v1 = col.GetValue(i1); std::byte const* v2 = col.GetValue(i2); - if (col.GetTypeId() != +model::TypeId::kMixed) { + if (col.GetTypeId() != model::TypeId::kMixed) { return col.GetType().Compare(v1, v2); } diff --git a/src/core/algorithms/fd/pfd_verifier/pfd_stats_calculator.h b/src/core/algorithms/fd/pfd_verifier/pfd_stats_calculator.h index 08e3c1cbe5..f4dd943c30 100644 --- a/src/core/algorithms/fd/pfd_verifier/pfd_stats_calculator.h +++ b/src/core/algorithms/fd/pfd_verifier/pfd_stats_calculator.h @@ -74,7 +74,7 @@ class PFDStatsCalculator { clusters_violating_pfd_.push_back(x_cluster); } num_rows_violating_pfd_ += x_cluster_size - max; - sum += error_measure_ == +PfdErrorMeasure::per_tuple + sum += error_measure_ == PfdErrorMeasure::kPerTuple ? static_cast(max) : static_cast(max) / x_cluster_size; cluster_rows_count += x_cluster.size(); @@ -83,8 +83,8 @@ class PFDStatsCalculator { static_cast(x_pli->GetRelationSize() - cluster_rows_count); double probability = static_cast(sum + unique_rows) / - (error_measure_ == +PfdErrorMeasure::per_tuple ? x_pli->GetRelationSize() - : x_index.size() + unique_rows); + (error_measure_ == PfdErrorMeasure::kPerTuple ? x_pli->GetRelationSize() + : x_index.size() + unique_rows); error_ = 1.0 - probability; } }; diff --git a/src/core/algorithms/fd/pfd_verifier/pfd_verifier.h b/src/core/algorithms/fd/pfd_verifier/pfd_verifier.h index 8130a32fe1..e0944ed540 100644 --- a/src/core/algorithms/fd/pfd_verifier/pfd_verifier.h +++ b/src/core/algorithms/fd/pfd_verifier/pfd_verifier.h @@ -21,7 +21,7 @@ class PFDVerifier : public Algorithm { config::IndicesType lhs_indices_; config::IndicesType rhs_indices_; config::EqNullsType is_null_equal_null_; - config::PfdErrorMeasureType error_measure_ = +PfdErrorMeasure::per_tuple; + config::PfdErrorMeasureType error_measure_ = PfdErrorMeasure::kPerTuple; std::shared_ptr relation_; std::unique_ptr stats_calculator_; diff --git a/src/core/algorithms/fd/tane/enums.h b/src/core/algorithms/fd/tane/enums.h index 0783383d5f..8a17bdec6e 100644 --- a/src/core/algorithms/fd/tane/enums.h +++ b/src/core/algorithms/fd/tane/enums.h @@ -1,9 +1,9 @@ #pragma once -#include +#include namespace algos { -BETTER_ENUM(PfdErrorMeasure, char, per_tuple = 0, per_value) +enum class PfdErrorMeasure : char { kPerTuple = 0, kPerValue }; -BETTER_ENUM(AfdErrorMeasure, char, g1 = 0, pdep, tau, mu_plus, rho) +enum class AfdErrorMeasure : char { kG1 = 0, kPdep, kTau, kMuPlus, kRho }; } // namespace algos diff --git a/src/core/algorithms/fd/tane/pfdtane.cpp b/src/core/algorithms/fd/tane/pfdtane.cpp index b29988c731..28fa96d2db 100644 --- a/src/core/algorithms/fd/tane/pfdtane.cpp +++ b/src/core/algorithms/fd/tane/pfdtane.cpp @@ -69,15 +69,15 @@ config::ErrorType PFDTane::CalculatePFDError(model::PositionListIndex const* x_p xa_cluster_it++; } } - sum += measure == +PfdErrorMeasure::per_tuple ? static_cast(max) - : static_cast(max) / x_cluster.size(); + sum += measure == PfdErrorMeasure::kPerTuple ? static_cast(max) + : static_cast(max) / x_cluster.size(); cluster_rows_count += x_cluster.size(); } unsigned int unique_rows = static_cast(x_pli->GetRelationSize() - cluster_rows_count); double probability = static_cast(sum + unique_rows) / - (measure == +PfdErrorMeasure::per_tuple ? x_pli->GetRelationSize() - : x_index.size() + unique_rows); + (measure == PfdErrorMeasure::kPerTuple ? x_pli->GetRelationSize() + : x_index.size() + unique_rows); return 1.0 - probability; } diff --git a/src/core/algorithms/fd/tane/pfdtane.h b/src/core/algorithms/fd/tane/pfdtane.h index dbffc877fb..1c2b339b3f 100644 --- a/src/core/algorithms/fd/tane/pfdtane.h +++ b/src/core/algorithms/fd/tane/pfdtane.h @@ -11,7 +11,7 @@ namespace algos { /** Class for pFD mining with TANE algorithm */ class PFDTane : public tane::TaneCommon { private: - PfdErrorMeasure pfd_error_measure_ = +PfdErrorMeasure::per_tuple; + PfdErrorMeasure pfd_error_measure_ = PfdErrorMeasure::kPerTuple; void RegisterOptions(); void MakeExecuteOptsAvailableFDInternal() final; config::ErrorType CalculateZeroAryFdError(ColumnData const* rhs) override; diff --git a/src/core/algorithms/fd/tane/tane.cpp b/src/core/algorithms/fd/tane/tane.cpp index ec2fd5bd92..6c2152bbf8 100644 --- a/src/core/algorithms/fd/tane/tane.cpp +++ b/src/core/algorithms/fd/tane/tane.cpp @@ -18,7 +18,7 @@ void Tane::MakeExecuteOptsAvailableFDInternal() { } config::ErrorType Tane::CalculateZeroAryFdError(ColumnData const* rhs) { - if (afd_error_measure_ == +AfdErrorMeasure::g1) + if (afd_error_measure_ == AfdErrorMeasure::kG1) return CalculateZeroAryG1(rhs, relation_.get()->GetNumTuplePairs()); return 1; } @@ -27,13 +27,13 @@ config::ErrorType Tane::CalculateFdError(model::PositionListIndex const* lhs_pli model::PositionListIndex const* rhs_pli, model::PositionListIndex const* joint_pli) { switch (afd_error_measure_) { - case +AfdErrorMeasure::pdep: + case AfdErrorMeasure::kPdep: return 1 - CalculatePdepMeasure(lhs_pli, joint_pli); - case +AfdErrorMeasure::tau: + case AfdErrorMeasure::kTau: return 1 - CalculateTauMeasure(lhs_pli, rhs_pli, joint_pli); - case +AfdErrorMeasure::mu_plus: + case AfdErrorMeasure::kMuPlus: return 1 - CalculateMuPlusMeasure(lhs_pli, rhs_pli, joint_pli); - case +AfdErrorMeasure::rho: + case AfdErrorMeasure::kRho: return 1 - CalculateRhoMeasure(lhs_pli, joint_pli); default: return CalculateG1Error(lhs_pli, joint_pli, relation_.get()->GetNumTuplePairs()); diff --git a/src/core/algorithms/fd/tane/tane.h b/src/core/algorithms/fd/tane/tane.h index 8a46ef0438..77768725db 100644 --- a/src/core/algorithms/fd/tane/tane.h +++ b/src/core/algorithms/fd/tane/tane.h @@ -10,7 +10,7 @@ namespace algos { class Tane : public tane::TaneCommon { private: - AfdErrorMeasure afd_error_measure_ = +AfdErrorMeasure::g1; + AfdErrorMeasure afd_error_measure_ = AfdErrorMeasure::kG1; void MakeExecuteOptsAvailableFDInternal() override final; config::ErrorType CalculateZeroAryFdError(ColumnData const* rhs) override; config::ErrorType CalculateFdError(model::PositionListIndex const* lhs_pli, diff --git a/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.cpp b/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.cpp index 65f6cfdfe4..7eec1eccf9 100644 --- a/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.cpp +++ b/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.cpp @@ -12,7 +12,7 @@ void SampledInvertedIndex::Init(std::vector const& sampled_hashes, int m max_id_ = max_id; seen_cc_indices_ = boost::dynamic_bitset<>(max_id); - non_covered_cc_indices_ = atomicbitvector::atomic_bv_t(max_id); + non_covered_cc_indices_ = util::AtomicBitVector(max_id); discovered_inds_.clear(); } diff --git a/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.h b/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.h index 921e7a1f46..95d6111c15 100644 --- a/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.h +++ b/src/core/algorithms/ind/faida/inclusion_testing/sampled_inverted_index.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -10,6 +9,7 @@ #include "core/algorithms/ind/faida/inclusion_testing/hll_data.h" #include "core/algorithms/ind/faida/util/simple_ind.h" +#include "core/util/atomic_bit_vector.h" namespace algos::faida { @@ -24,7 +24,7 @@ class SampledInvertedIndex { emhash2::HashSet discovered_inds_; boost::dynamic_bitset<> seen_cc_indices_; - atomicbitvector::atomic_bv_t non_covered_cc_indices_; + util::AtomicBitVector non_covered_cc_indices_; int max_id_; @@ -37,8 +37,8 @@ class SampledInvertedIndex { auto set_iter = inverted_index_.find(hash); if (set_iter == inverted_index_.end()) { - if (!non_covered_cc_indices_.test(combination.GetIndex())) { - non_covered_cc_indices_.set(combination.GetIndex()); + if (!non_covered_cc_indices_.Test(combination.GetIndex())) { + non_covered_cc_indices_.Set(combination.GetIndex()); } return false; } @@ -50,7 +50,7 @@ class SampledInvertedIndex { } bool IsCovered(std::shared_ptr const& combination) { - return !non_covered_cc_indices_.test(combination->GetIndex()); + return !non_covered_cc_indices_.Test(combination->GetIndex()); } bool IsIncludedIn(std::shared_ptr const& a, std::shared_ptr const& b) { diff --git a/src/core/algorithms/ind/mind/mind.cpp b/src/core/algorithms/ind/mind/mind.cpp index 481fb22e73..85d37ce312 100644 --- a/src/core/algorithms/ind/mind/mind.cpp +++ b/src/core/algorithms/ind/mind/mind.cpp @@ -34,7 +34,7 @@ void Mind::MakeLoadOptsAvailable() { * At the moment we only have one algorithm for mining unary approximate inds. * In the future we should give the user the ability to choose the algorithm. */ - auind_algo_ = CreateAlgorithmInstance(AlgorithmType::spider); + auind_algo_ = CreateAlgorithmInstance(AlgorithmType::kSpider); } void Mind::MakeExecuteOptsAvailable() { diff --git a/src/core/algorithms/md/hymd/enums.h b/src/core/algorithms/md/hymd/enums.h index cf8c0007cf..8bdbe9313b 100644 --- a/src/core/algorithms/md/hymd/enums.h +++ b/src/core/algorithms/md/hymd/enums.h @@ -1,12 +1,12 @@ #pragma once -#include +#include namespace algos::hymd { -BETTER_ENUM(LevelDefinition, char, - cardinality = 0, /*define level as the set of mds with the same cardinality*/ - lattice /*define level as the whole lattice*/ -) +enum class LevelDefinition : char { + kCardinality = 0, /*define level as the set of mds with the same cardinality*/ + kLattice /*define level as the whole lattice*/ +}; } diff --git a/src/core/algorithms/md/hymd/hymd.cpp b/src/core/algorithms/md/hymd/hymd.cpp index 170a0d1560..23ec90a28a 100644 --- a/src/core/algorithms/md/hymd/hymd.cpp +++ b/src/core/algorithms/md/hymd/hymd.cpp @@ -50,9 +50,9 @@ lattice::SingleLevelFunc GetLevelDefinitionFunc(LevelDefinition definition_enum) // TODO: make infrastructure for depth level. // TODO: use depth level and validate several levels depending on thread number. switch (definition_enum) { - case +LevelDefinition::cardinality: + case LevelDefinition::kCardinality: return [](...) { return 1; }; - case +LevelDefinition::lattice: + case LevelDefinition::kLattice: return {nullptr}; default: DESBORDANTE_ASSUME(false); @@ -148,7 +148,7 @@ void HyMD::RegisterOptions() { std::numeric_limits::max()}); RegisterOption(config::kThreadNumberOpt(&threads_)); RegisterOption(Option{&level_definition_, kLevelDefinition, kDLevelDefinition, - +LevelDefinition::cardinality}); + LevelDefinition::kCardinality}); } void HyMD::ResetStateMd() {} diff --git a/src/core/algorithms/md/hymd/hymd.h b/src/core/algorithms/md/hymd/hymd.h index 700b7c9765..0abdb6814e 100644 --- a/src/core/algorithms/md/hymd/hymd.h +++ b/src/core/algorithms/md/hymd/hymd.h @@ -63,7 +63,7 @@ class HyMD final : public MdAlgorithm { bool prune_nondisjoint_ = true; std::size_t max_cardinality_ = -1; config::ThreadNumType threads_; - LevelDefinition level_definition_ = +LevelDefinition::cardinality; + LevelDefinition level_definition_ = LevelDefinition::kCardinality; // TODO: different level definitions (cardinality currently used) // TODO: comparing only some values during similarity calculation // TODO: automatically calculating minimal support diff --git a/src/core/algorithms/metric/enums.h b/src/core/algorithms/metric/enums.h index 5d6dccc8b8..2c6e767810 100644 --- a/src/core/algorithms/metric/enums.h +++ b/src/core/algorithms/metric/enums.h @@ -1,25 +1,27 @@ #pragma once -#include +#include namespace algos::metric { -BETTER_ENUM(Metric, char, euclidean = 0, /* Standard metric for calculating the distance between - * numeric values */ - levenshtein, /* Levenshtein distance between strings */ - cosine /* Represent strings as q-gram vectors and calculate cosine distance - * between these vectors */ -) +enum class Metric : char { + kEuclidean = 0, /* Standard metric for calculating the distance between + * numeric values */ + kLevenshtein, /* Levenshtein distance between strings */ + kCosine /* Represent strings as q-gram vectors and calculate cosine distance + * between these vectors */ -BETTER_ENUM(MetricAlgo, char, - brute = 0, /* Brute force algorithm. Calculates distance between all possible pairs - * of values and compares them with parameter */ - approx, /* 2-approximation linear time algorithm, which makes a prediction - * based on the max distance of one point in cluster */ - calipers /* Rotating calipers algorithm for 2d euclidean metric. Computes a - * convex hull of the points and calculates distances between - * antipodal pairs of convex hull, resulting in a significant - * reduction in the number of comparisons */ -) +}; +enum class MetricAlgo : char { + kBrute = 0, /* Brute force algorithm. Calculates distance between all possible pairs + * of values and compares them with parameter */ + kApprox, /* 2-approximation linear time algorithm, which makes a prediction + * based on the max distance of one point in cluster */ + kCalipers /* Rotating calipers algorithm for 2d euclidean metric. Computes a + * convex hull of the points and calculates distances between + * antipodal pairs of convex hull, resulting in a significant + * reduction in the number of comparisons */ + +}; } // namespace algos::metric diff --git a/src/core/algorithms/metric/metric_verifier.cpp b/src/core/algorithms/metric/metric_verifier.cpp index 383a158180..4c2f0e00dd 100644 --- a/src/core/algorithms/metric/metric_verifier.cpp +++ b/src/core/algorithms/metric/metric_verifier.cpp @@ -29,16 +29,16 @@ void MetricVerifier::ValidateRhs(config::IndicesType const& rhs_indices) { config::IndexType column_index = rhs_indices[0]; model::TypedColumnData const& column = typed_relation_->GetColumnData(column_index); model::TypeId type_id = column.GetTypeId(); - if (type_id == +model::TypeId::kUndefined) { + if (type_id == model::TypeId::kUndefined) { throw config::ConfigurationError("Column with index \"" + std::to_string(column_index) + "\" type undefined."); } - if (type_id == +model::TypeId::kMixed) { + if (type_id == model::TypeId::kMixed) { throw config::ConfigurationError("Column with index \"" + std::to_string(column_index) + "\" contains values of different types."); } - if (metric_ == +Metric::euclidean) { + if (metric_ == Metric::kEuclidean) { if (!column.IsNumeric()) { throw config::ConfigurationError( "\"Euclidean\" metric is only available for numeric " @@ -46,19 +46,19 @@ void MetricVerifier::ValidateRhs(config::IndicesType const& rhs_indices) { } return; } - if (type_id == +model::TypeId::kString) return; + if (type_id == model::TypeId::kString) return; throw config::ConfigurationError("The chosen metric is available only for string columns."); } - if (metric_ == +Metric::euclidean) { + if (metric_ == Metric::kEuclidean) { for (config::IndexType column_index : rhs_indices) { model::TypedColumnData const& column = typed_relation_->GetColumnData(column_index); model::TypeId type_id = column.GetTypeId(); - if (type_id == +model::TypeId::kUndefined) { + if (type_id == model::TypeId::kUndefined) { throw config::ConfigurationError("Column with index \"" + std::to_string(column_index) + "\" type undefined."); } - if (type_id == +model::TypeId::kMixed) { + if (type_id == model::TypeId::kMixed) { throw config::ConfigurationError("Column with index \"" + std::to_string(column_index) + "\" contains values of different types."); @@ -85,16 +85,16 @@ void MetricVerifier::RegisterOptions() { auto get_schema_columns = [this]() { return relation_->GetSchema()->GetNumColumns(); }; auto check_rhs = [this](config::IndicesType const& rhs_indices) { ValidateRhs(rhs_indices); }; auto need_algo_and_q = [this]([[maybe_unused]] config::IndicesType const& _) { - return metric_ == +Metric::cosine; + return metric_ == Metric::kCosine; }; auto need_algo_only = [this](config::IndicesType const& rhs_indices) { - assert(metric_ == +Metric::levenshtein || metric_ == +Metric::euclidean); - return metric_ == +Metric::levenshtein || rhs_indices.size() != 1; + assert(metric_ == Metric::kLevenshtein || metric_ == Metric::kEuclidean); + return metric_ == Metric::kLevenshtein || rhs_indices.size() != 1; }; auto algo_check = [this](MetricAlgo metric_algo) { - assert(!(metric_ == +Metric::euclidean && rhs_indices_.size() == 1)); - if (metric_algo == +MetricAlgo::calipers) { - if (!(metric_ == +Metric::euclidean && rhs_indices_.size() == 2)) + assert(!(metric_ == Metric::kEuclidean && rhs_indices_.size() == 1)); + if (metric_algo == MetricAlgo::kCalipers) { + if (!(metric_ == Metric::kEuclidean && rhs_indices_.size() == 2)) throw config::ConfigurationError( "\"calipers\" algorithm is only available for " "2-dimensional RHS and \"euclidean\" metric."); @@ -233,7 +233,7 @@ void MetricVerifier::VerifyMetricFD() { for (auto const& cluster : pli->GetIndex()) { if (!cluster_func(cluster)) { metric_fd_holds_ = false; - if (algo_ == +MetricAlgo::approx) { + if (algo_ == MetricAlgo::kApprox) { break; } } @@ -243,7 +243,7 @@ void MetricVerifier::VerifyMetricFD() { ClusterFunction MetricVerifier::GetClusterFunctionForOneDimension() { model::TypedColumnData const& col = typed_relation_->GetColumnData(rhs_indices_[0]); - if (metric_ == +Metric::euclidean) { + if (metric_ == Metric::kEuclidean) { assert(col.IsNumeric()); return CalculateClusterFunction( [this](auto const& cluster) { @@ -256,11 +256,11 @@ ClusterFunction MetricVerifier::GetClusterFunctionForOneDimension() { }); } - assert(col.GetTypeId() == +model::TypeId::kString); + assert(col.GetTypeId() == model::TypeId::kString); auto const& type = static_cast(col.GetType()); std::function)> verify_func; - if (algo_ == +MetricAlgo::brute) { + if (algo_ == MetricAlgo::kBrute) { verify_func = [this](auto dist_func) { return CalculateClusterFunction( [this](auto const& cluster) { @@ -285,7 +285,7 @@ ClusterFunction MetricVerifier::GetClusterFunctionForOneDimension() { }; } - if (metric_ == +Metric::levenshtein) { + if (metric_ == Metric::kLevenshtein) { return verify_func( [&type](std::byte const* l, std::byte const* r) { return type.Dist(l, r); }); } @@ -297,7 +297,7 @@ ClusterFunction MetricVerifier::GetClusterFunctionForOneDimension() { } ClusterFunction MetricVerifier::GetClusterFunctionForSeveralDimensions() { - if (algo_ == +MetricAlgo::calipers) { + if (algo_ == MetricAlgo::kCalipers) { return [this](model::PLI::Cluster const& cluster) { auto result = points_calculator_->CalculateMultidimensionalPointsForCalipers(cluster); if (!CheckMFDFailIfHasNulls(result.has_nulls) && @@ -312,7 +312,7 @@ ClusterFunction MetricVerifier::GetClusterFunctionForSeveralDimensions() { return false; }; } - if (algo_ == +MetricAlgo::brute) { + if (algo_ == MetricAlgo::kBrute) { return CalculateClusterFunction( [this](auto const& cluster) { return points_calculator_->CalculateMultidimensionalIndexedPoints(cluster); diff --git a/src/core/algorithms/metric/metric_verifier.h b/src/core/algorithms/metric/metric_verifier.h index e2da55de1d..72fbfc47d2 100644 --- a/src/core/algorithms/metric/metric_verifier.h +++ b/src/core/algorithms/metric/metric_verifier.h @@ -29,8 +29,8 @@ class MetricVerifier : public Algorithm { private: config::InputTable input_table_; - Metric metric_ = Metric::_values()[0]; - MetricAlgo algo_ = MetricAlgo::_values()[0]; + Metric metric_ = magic_enum::enum_values().front(); + MetricAlgo algo_ = magic_enum::enum_values().front(); config::IndicesType lhs_indices_; config::IndicesType rhs_indices_; long double parameter_; diff --git a/src/core/algorithms/metric/points_calculator.cpp b/src/core/algorithms/metric/points_calculator.cpp index 1fe2f11900..382dcc8655 100644 --- a/src/core/algorithms/metric/points_calculator.cpp +++ b/src/core/algorithms/metric/points_calculator.cpp @@ -47,7 +47,7 @@ long double PointsCalculator::GetCoordinate(bool& has_values, ClusterIndex row_i } has_values = true; - return col.GetType().GetTypeId() == +model::TypeId::kInt + return col.GetType().GetTypeId() == model::TypeId::kInt ? (long double)model::Type::GetValue(col.GetData()[row_index]) : model::Type::GetValue(col.GetData()[row_index]); } diff --git a/src/core/algorithms/nar/des/des.cpp b/src/core/algorithms/nar/des/des.cpp index 62365116eb..aef76ee393 100644 --- a/src/core/algorithms/nar/des/des.cpp +++ b/src/core/algorithms/nar/des/des.cpp @@ -22,7 +22,7 @@ DES::DES() : NARAlgorithm({}) { void DES::RegisterOptions() { DESBORDANTE_OPTION_USING; - DifferentialStrategy default_strategy = DifferentialStrategy::rand1Bin; + DifferentialStrategy default_strategy = DifferentialStrategy::kRand1Bin; RegisterOption(Option{&seed_, kSeed, kDSeed, 2ul}); RegisterOption(Option{&population_size_, kPopulationSize, kDPopulationSize, 100u}); RegisterOption( diff --git a/src/core/algorithms/nar/des/differential_functions.cpp b/src/core/algorithms/nar/des/differential_functions.cpp index 3acd10bdea..d0dc222043 100644 --- a/src/core/algorithms/nar/des/differential_functions.cpp +++ b/src/core/algorithms/nar/des/differential_functions.cpp @@ -40,7 +40,7 @@ EncodedNAR Rand1Bin(std::vector const& population, size_t candidate_ // TODO: name is probably inconsistent with how it's called in the field. MutationFunction EnumToMutationStrategy(DifferentialStrategy strategy) { switch (strategy) { - case DifferentialStrategy::rand1Bin: + case DifferentialStrategy::kRand1Bin: return Rand1Bin; default: throw std::logic_error("No mutation function corresponding to DifferentialStategy."); diff --git a/src/core/algorithms/nar/des/differential_functions.h b/src/core/algorithms/nar/des/differential_functions.h index ec3d77fb95..396bd98aab 100644 --- a/src/core/algorithms/nar/des/differential_functions.h +++ b/src/core/algorithms/nar/des/differential_functions.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "core/algorithms/nar/des/encoded_nar.h" #include "core/algorithms/nar/des/enums.h" #include "core/algorithms/nar/des/rng.h" @@ -11,7 +9,7 @@ namespace algos::des { struct DifferentialOptions { double differential_scale; double crossover_probability; - DifferentialStrategy differential_strategy = DifferentialStrategy::best1Exp; + DifferentialStrategy differential_strategy = DifferentialStrategy::kBest1Exp; }; EncodedNAR Rand1Bin(std::vector const& population, size_t candidate_index, diff --git a/src/core/algorithms/nar/des/encoded_value_range.cpp b/src/core/algorithms/nar/des/encoded_value_range.cpp index da012269c9..a19ce8c474 100644 --- a/src/core/algorithms/nar/des/encoded_value_range.cpp +++ b/src/core/algorithms/nar/des/encoded_value_range.cpp @@ -75,7 +75,7 @@ std::shared_ptr EncodedValueRange::Decode( return DecodeTypedValueRange>(domain); default: throw std::invalid_argument(std::string("ValueRange has invalid type_id: ") + - domain_type_id._to_string() + + std::string(magic_enum::enum_name(domain_type_id)) + std::string(" in function: ") + __func__); } } diff --git a/src/core/algorithms/nar/des/enums.h b/src/core/algorithms/nar/des/enums.h index 2e22905d79..a70576b444 100644 --- a/src/core/algorithms/nar/des/enums.h +++ b/src/core/algorithms/nar/des/enums.h @@ -1,9 +1,18 @@ #pragma once -#include +#include namespace algos::des { -BETTER_ENUM(DifferentialStrategy, char, rand1Bin = 0, rand1Exp, randToBest1Exp, best2Exp, rand2Exp, - best1Bin, best1Exp, randToBest1Bin, best2Bin, - rand2Bin); // TODO: add descriptions of each strategy +enum class DifferentialStrategy : char { + kRand1Bin = 0, + kRand1Exp, + kRandToBest1Exp, + kBest2Exp, + kRand2Exp, + kBest1Bin, + kBest1Exp, + kRandToBest1Bin, + kBest2Bin, + kRand2Bin +}; // TODO: add descriptions of each strategy } // namespace algos::des diff --git a/src/core/algorithms/nar/value_range.h b/src/core/algorithms/nar/value_range.h index 9bebc41baa..cd58e0c160 100644 --- a/src/core/algorithms/nar/value_range.h +++ b/src/core/algorithms/nar/value_range.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "core/model/table/column_layout_typed_relation_data.h" #include "core/model/types/type.h" diff --git a/src/core/algorithms/nd/nd_verifier/util/value_combination.cpp b/src/core/algorithms/nd/nd_verifier/util/value_combination.cpp index 48040f3c0a..741b42daaf 100644 --- a/src/core/algorithms/nd/nd_verifier/util/value_combination.cpp +++ b/src/core/algorithms/nd/nd_verifier/util/value_combination.cpp @@ -22,7 +22,7 @@ bool ValueCombination::CompareValues(ValueCombination::TypedValue a, return false; } auto type = CreateType(a.first, false); - if (a.first == +(TypeId::kMixed)) { + if (a.first == (TypeId::kMixed)) { if (MixedType::RetrieveTypeId(a.second) != MixedType::RetrieveTypeId(b.second)) { return false; } diff --git a/src/core/algorithms/od/fastod/fastod.cpp b/src/core/algorithms/od/fastod/fastod.cpp index 3da5f63263..fdfc7e1831 100644 --- a/src/core/algorithms/od/fastod/fastod.cpp +++ b/src/core/algorithms/od/fastod/fastod.cpp @@ -148,8 +148,8 @@ void Fastod::ComputeODs() { CCPut(context, context_cc); - AddCandidates(context, del_attrs); - AddCandidates(context, del_attrs); + AddCandidates(context, del_attrs); + AddCandidates(context, del_attrs); } size_t delete_index = 0; @@ -181,8 +181,8 @@ void Fastod::ComputeODs() { } }); - CalculateODs(context, del_attrs); - CalculateODs(context, del_attrs); + CalculateODs(context, del_attrs); + CalculateODs(context, del_attrs); } } @@ -194,8 +194,8 @@ void Fastod::PruneLevels() { for (auto attribute_set_it = context_in_current_level_.begin(); attribute_set_it != context_in_current_level_.end();) { if (IsEmptySet(CCGet(*attribute_set_it)) && - CSGet(*attribute_set_it).empty() && - CSGet(*attribute_set_it).empty()) { + CSGet(*attribute_set_it).empty() && + CSGet(*attribute_set_it).empty()) { context_in_current_level_.erase(attribute_set_it++); } else { ++attribute_set_it; @@ -227,7 +227,7 @@ void Fastod::CalculateNextLevel() { for (size_t j = i + 1; j < single_attributes.size(); ++j) { bool create_context = true; - const AttributeSet candidate = fastod::AddAttribute( + AttributeSet const candidate = fastod::AddAttribute( fastod::AddAttribute(prefix, single_attributes[i]), single_attributes[j]); candidate.Iterate([this, &candidate, &create_context](model::ColumnIndex attr) { diff --git a/src/core/algorithms/od/fastod/fastod.h b/src/core/algorithms/od/fastod/fastod.h index fa12a6aa0b..f0453136de 100644 --- a/src/core/algorithms/od/fastod/fastod.h +++ b/src/core/algorithms/od/fastod/fastod.h @@ -73,7 +73,7 @@ class Fastod : public Algorithm { template [[nodiscard]] static consteval bool IsAscending() { - return Ordering == +od::Ordering::ascending; + return Ordering == od::Ordering::kAscending; } template diff --git a/src/core/algorithms/od/fastod/model/canonical_od.cpp b/src/core/algorithms/od/fastod/model/canonical_od.cpp index e8c2452ee4..d2ac9b30c1 100644 --- a/src/core/algorithms/od/fastod/model/canonical_od.cpp +++ b/src/core/algorithms/od/fastod/model/canonical_od.cpp @@ -35,7 +35,7 @@ std::string CanonicalOD::ToString() const { std::stringstream result; result << context_.ToString() << " : " << ap_.left + 1 - << ((Ordering == +od::Ordering::ascending) ? "<=" : ">=") << " ~ " << ap_.right + 1 + << ((Ordering == od::Ordering::kAscending) ? "<=" : ">=") << " ~ " << ap_.right + 1 << "<="; return result.str(); @@ -68,18 +68,18 @@ std::string SimpleCanonicalOD::ToString() const { return result.str(); } -bool operator==(CanonicalOD const& x, - CanonicalOD const& y) { +bool operator==(CanonicalOD const& x, + CanonicalOD const& y) { return x.context_ == y.context_ && x.ap_ == y.ap_; } -bool operator!=(CanonicalOD const& x, - CanonicalOD const& y) { +bool operator!=(CanonicalOD const& x, + CanonicalOD const& y) { return !(x == y); } -bool operator<(CanonicalOD const& x, - CanonicalOD const& y) { +bool operator<(CanonicalOD const& x, + CanonicalOD const& y) { if (x.ap_ != y.ap_) { return x.ap_ < y.ap_; } @@ -87,18 +87,18 @@ bool operator<(CanonicalOD const& x, return x.context_ < y.context_; } -bool operator==(CanonicalOD const& x, - CanonicalOD const& y) { +bool operator==(CanonicalOD const& x, + CanonicalOD const& y) { return x.context_ == y.context_ && x.ap_ == y.ap_; } -bool operator!=(CanonicalOD const& x, - CanonicalOD const& y) { +bool operator!=(CanonicalOD const& x, + CanonicalOD const& y) { return !(x == y); } -bool operator<(CanonicalOD const& x, - CanonicalOD const& y) { +bool operator<(CanonicalOD const& x, + CanonicalOD const& y) { if (x.ap_ != y.ap_) { return x.ap_ < y.ap_; } @@ -122,7 +122,7 @@ bool operator<(SimpleCanonicalOD const& x, SimpleCanonicalOD const& y) { return x.context_ < y.context_; } -template class CanonicalOD; -template class CanonicalOD; +template class CanonicalOD; +template class CanonicalOD; } // namespace algos::fastod diff --git a/src/core/algorithms/od/fastod/model/canonical_od.h b/src/core/algorithms/od/fastod/model/canonical_od.h index ae52305134..a52c2c891f 100644 --- a/src/core/algorithms/od/fastod/model/canonical_od.h +++ b/src/core/algorithms/od/fastod/model/canonical_od.h @@ -42,24 +42,24 @@ class CanonicalOD { constexpr static auto kName = "OC"; - friend bool operator==(CanonicalOD const& x, - CanonicalOD const& y); - friend bool operator!=(CanonicalOD const& x, - CanonicalOD const& y); - friend bool operator<(CanonicalOD const& x, - CanonicalOD const& y); - friend bool operator==(CanonicalOD const& x, - CanonicalOD const& y); - friend bool operator!=(CanonicalOD const& x, - CanonicalOD const& y); - friend bool operator<(CanonicalOD const& x, - CanonicalOD const& y); + friend bool operator==(CanonicalOD const& De, + CanonicalOD const& y); + friend bool operator!=(CanonicalOD const& x, + CanonicalOD const& y); + friend bool operator<(CanonicalOD const& x, + CanonicalOD const& y); + friend bool operator==(CanonicalOD const& x, + CanonicalOD const& y); + friend bool operator!=(CanonicalOD const& x, + CanonicalOD const& y); + friend bool operator<(CanonicalOD const& x, + CanonicalOD const& y); friend struct std::hash>; }; -using AscCanonicalOD = CanonicalOD; -using DescCanonicalOD = CanonicalOD; +using AscCanonicalOD = CanonicalOD; +using DescCanonicalOD = CanonicalOD; class SimpleCanonicalOD { private: diff --git a/src/core/algorithms/od/fastod/od_ordering.h b/src/core/algorithms/od/fastod/od_ordering.h index a4a38d0fd4..f66407c735 100644 --- a/src/core/algorithms/od/fastod/od_ordering.h +++ b/src/core/algorithms/od/fastod/od_ordering.h @@ -1,7 +1,7 @@ #pragma once -#include +#include namespace algos::od { -BETTER_ENUM(Ordering, char, ascending = 0, descending); +enum class Ordering : char { kAscending = 0, kDescending }; } // namespace algos::od diff --git a/src/core/algorithms/od/fastod/partitions/complex_stripped_partition.cpp b/src/core/algorithms/od/fastod/partitions/complex_stripped_partition.cpp index 0d6b720926..590b3c7423 100644 --- a/src/core/algorithms/od/fastod/partitions/complex_stripped_partition.cpp +++ b/src/core/algorithms/od/fastod/partitions/complex_stripped_partition.cpp @@ -8,7 +8,7 @@ namespace { template using Comp = - std::conditional_t, std::greater>; + std::conditional_t, std::greater>; } // namespace @@ -148,9 +148,9 @@ bool ComplexStrippedPartition::Swap(model::ColumnIndex left, model::ColumnIndex return false; } -template bool ComplexStrippedPartition::Swap( +template bool ComplexStrippedPartition::Swap( model::ColumnIndex left, model::ColumnIndex right) const; -template bool ComplexStrippedPartition::Swap( +template bool ComplexStrippedPartition::Swap( model::ColumnIndex left, model::ColumnIndex right) const; namespace { @@ -242,9 +242,9 @@ od::RemovalSetAsVec ComplexStrippedPartition::CalculateSwapRemovalSet( } template od::RemovalSetAsVec ComplexStrippedPartition::CalculateSwapRemovalSet< - od::Ordering::ascending>(model::ColumnIndex left, model::ColumnIndex right) const; + od::Ordering::kAscending>(model::ColumnIndex left, model::ColumnIndex right) const; template od::RemovalSetAsVec ComplexStrippedPartition::CalculateSwapRemovalSet< - od::Ordering::descending>(model::ColumnIndex left, model::ColumnIndex right) const; + od::Ordering::kDescending>(model::ColumnIndex left, model::ColumnIndex right) const; od::RemovalSetAsVec ComplexStrippedPartition::CommonSplitRemovalSet( model::ColumnIndex right) const { diff --git a/src/core/algorithms/od/fastod/util/type_util.cpp b/src/core/algorithms/od/fastod/util/type_util.cpp index 3e0db5d0f5..e231403055 100644 --- a/src/core/algorithms/od/fastod/util/type_util.cpp +++ b/src/core/algorithms/od/fastod/util/type_util.cpp @@ -5,8 +5,8 @@ namespace algos::fastod { bool IsUnorderedType(model::TypeId type_id) { - return type_id == +model::TypeId::kEmpty || type_id == +model::TypeId::kNull || - type_id == +model::TypeId::kUndefined; + return type_id == model::TypeId::kEmpty || type_id == model::TypeId::kNull || + type_id == model::TypeId::kUndefined; } model::CompareResult CompareDataAsStrings(std::byte const* left, std::byte const* right, diff --git a/src/core/algorithms/od/order/dependency_checker.cpp b/src/core/algorithms/od/order/dependency_checker.cpp index 0514551fb6..a7b4da3e6b 100644 --- a/src/core/algorithms/od/order/dependency_checker.cpp +++ b/src/core/algorithms/od/order/dependency_checker.cpp @@ -23,7 +23,7 @@ bool SubsetSetDifference(SortedPartition::EquivalenceClass const& a, } // namespace ValidityType CheckForSwap(SortedPartition const& l, SortedPartition const& r) { - ValidityType res = ValidityType::valid; + ValidityType res = ValidityType::kValid; size_t l_i = 0, r_i = 0; bool next_l = true, next_r = true; SortedPartition::EquivalenceClass l_eq_class; @@ -39,16 +39,16 @@ ValidityType CheckForSwap(SortedPartition const& l, SortedPartition const& r) { } if (l_eq_class.size() < r_eq_class.size()) { if (!SubsetSetDifference(l_eq_class, r_eq_class)) { - return ValidityType::swap; + return ValidityType::kSwap; } else { - res = ValidityType::merge; + res = ValidityType::kMerge; ++l_i; next_l = true; next_r = false; } } else { if (!SubsetSetDifference(r_eq_class, l_eq_class)) { - return ValidityType::swap; + return ValidityType::kSwap; } else { ++r_i; next_r = true; diff --git a/src/core/algorithms/od/order/dependency_checker.h b/src/core/algorithms/od/order/dependency_checker.h index 9d38567d21..5d99795e2b 100644 --- a/src/core/algorithms/od/order/dependency_checker.h +++ b/src/core/algorithms/od/order/dependency_checker.h @@ -1,12 +1,12 @@ #pragma once -#include +#include #include "core/algorithms/od/order/sorted_partitions.h" namespace algos::order { -BETTER_ENUM(ValidityType, char, valid = 0, merge, swap); +enum class ValidityType : char { kValid = 0, kMerge, kSwap }; ValidityType CheckForSwap(SortedPartition const& l, SortedPartition const& r); diff --git a/src/core/algorithms/od/order/order.cpp b/src/core/algorithms/od/order/order.cpp index 646a4c5092..6e002ad0b8 100644 --- a/src/core/algorithms/od/order/order.cpp +++ b/src/core/algorithms/od/order/order.cpp @@ -62,13 +62,13 @@ void Order::CreateSingleColumnSortedPartitions() { std::unique_ptr mixed_type = model::CreateSpecificType(model::TypeId::kMixed, true); auto less = [&type, &mixed_type](IndexedByteData const& l, IndexedByteData const& r) { - if (type->GetTypeId() == +(model::TypeId::kMixed)) { + if (type->GetTypeId() == (model::TypeId::kMixed)) { return mixed_type->CompareAsStrings(l.data, r.data) == model::CompareResult::kLess; } return type->Compare(l.data, r.data) == model::CompareResult::kLess; }; auto equal = [&type, &mixed_type](IndexedByteData const& l, IndexedByteData const& r) { - if (type->GetTypeId() == +(model::TypeId::kMixed)) { + if (type->GetTypeId() == (model::TypeId::kMixed)) { return mixed_type->CompareAsStrings(l.data, r.data) == model::CompareResult::kEqual; } return type->Compare(l.data, r.data) == model::CompareResult::kEqual; @@ -122,11 +122,11 @@ ValidityType Order::CheckCandidateValidity(AttributeList const& lhs, AttributeLi break; } } - ValidityType candidate_validity = +ValidityType::merge; + ValidityType candidate_validity = ValidityType::kMerge; if (!is_merge_immediately) { CreateSortedPartitionsFromSingletons(lhs); if (sorted_partitions_[lhs].Size() == 1) { - candidate_validity = +ValidityType::valid; + candidate_validity = ValidityType::kValid; candidate_sets_[lhs].erase(rhs); } else { CreateSortedPartitionsFromSingletons(rhs); @@ -151,7 +151,7 @@ void Order::ComputeDependencies(ListLattice::LatticeLevel const& lattice_level) continue; } ValidityType candidate_validity = CheckCandidateValidity(lhs, rhs); - if (candidate_validity == +ValidityType::valid) { + if (candidate_validity == ValidityType::kValid) { bool non_minimal_by_merge = false; for (AttributeList const& merge_lhs : GetPrefixes(lhs)) { if (InUnorderedMap(merge_invalidated_, merge_lhs, rhs)) { @@ -170,9 +170,9 @@ void Order::ComputeDependencies(ListLattice::LatticeLevel const& lattice_level) if (lhs_unique) { candidate_sets_[lhs].erase(rhs); } - } else if (candidate_validity == +ValidityType::swap) { + } else if (candidate_validity == ValidityType::kSwap) { candidate_sets_[lhs].erase(rhs); - } else if (candidate_validity == +ValidityType::merge) { + } else if (candidate_validity == ValidityType::kMerge) { if (merge_invalidated_.find(lhs) == merge_invalidated_.end()) { merge_invalidated_[lhs] = {}; } diff --git a/src/core/algorithms/od/set_based_verifier/verifier.cpp b/src/core/algorithms/od/set_based_verifier/verifier.cpp index d1d18df356..6ef7782185 100644 --- a/src/core/algorithms/od/set_based_verifier/verifier.cpp +++ b/src/core/algorithms/od/set_based_verifier/verifier.cpp @@ -2,6 +2,8 @@ #include +#include + #include "core/algorithms/od/fastod/model/canonical_od.h" #include "core/config/column_index/option.h" #include "core/config/indices/option.h" @@ -35,7 +37,7 @@ void SetBasedAodVerifier::RegisterOptions() { RegisterOption(config::ColumnIndexOption{kOcLeftIndex, kDOcLeftIndex}(&oc_.left, get_cols_num)); RegisterOption(ColumnIndexOption{kOcRightIndex, kDOcRightIndex}(&oc_.right, get_cols_num)); RegisterOption(Option{&oc_.left_ordering, kOcLeftOrdering, kDODLeftOrdering, - Ordering::ascending}); + Ordering::kAscending}); RegisterOption(IndicesOption{kOFDContext, kDOFDContext, true}(&ofd_.context, get_cols_num) .SetConditionalOpts({{nullptr, {kOFDRightIndex}}}) .SetIsRequiredFunc([this]() { return !OptionIsSet(kOcContext); })); @@ -98,15 +100,15 @@ void SetBasedAodVerifier::Verify() { if (OptionIsSet(config::names::kOcContext)) { switch (oc_.left_ordering) { - case od::Ordering::ascending: - CalculateRemovalSetForOC(); + case od::Ordering::kAscending: + CalculateRemovalSetForOC(); break; - case od::Ordering::descending: - CalculateRemovalSetForOC(); + case od::Ordering::kDescending: + CalculateRemovalSetForOC(); break; default: throw std::invalid_argument(std::string{"Unknown ordering: "} + - oc_.left_ordering._to_string()); + std::string(magic_enum::enum_name(oc_.left_ordering))); } } diff --git a/src/core/algorithms/od/set_based_verifier/verifier.h b/src/core/algorithms/od/set_based_verifier/verifier.h index 3eb2055195..4325b55d6a 100644 --- a/src/core/algorithms/od/set_based_verifier/verifier.h +++ b/src/core/algorithms/od/set_based_verifier/verifier.h @@ -2,6 +2,8 @@ #include +#include + #include "core/algorithms/algorithm.h" #include "core/algorithms/od/fastod/model/removal_set.h" #include "core/algorithms/od/fastod/od_ordering.h" @@ -21,7 +23,7 @@ class SetBasedAodVerifier final : public Algorithm { config::IndicesType context; config::IndexType left; config::IndexType right; - Ordering left_ordering = Ordering::_values()[0]; + Ordering left_ordering = magic_enum::enum_values().front(); }; struct OFD { diff --git a/src/core/algorithms/statistics/data_stats.cpp b/src/core/algorithms/statistics/data_stats.cpp index cfd66d8348..751ea00c12 100644 --- a/src/core/algorithms/statistics/data_stats.cpp +++ b/src/core/algorithms/statistics/data_stats.cpp @@ -184,11 +184,13 @@ size_t DataStats::MixedDistinct(size_t index) const { std::vector const& data = col.GetData(); mo::MixedType mixed_type(is_null_equal_null_); - std::vector> values_by_type_id(mo::TypeId::_size()); + std::vector> values_by_type_id( + magic_enum::enum_count()); for (size_t i = 0; i < data.size(); ++i) { if (col.IsNullOrEmpty(i)) continue; - values_by_type_id[mixed_type.RetrieveTypeId(data[i])._to_index()].push_back(data[i]); + auto type_id = mixed_type.RetrieveTypeId(data[i]); + values_by_type_id[magic_enum::enum_index(type_id).value()].push_back(data[i]); } size_t result = 0; @@ -202,7 +204,7 @@ size_t DataStats::MixedDistinct(size_t index) const { size_t DataStats::Distinct(size_t index) { if (all_stats_[index].distinct != 0) return all_stats_[index].distinct; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() == +mo::TypeId::kMixed) { + if (col.GetTypeId() == mo::TypeId::kMixed) { all_stats_[index].distinct = MixedDistinct(index); return all_stats_[index].distinct; } @@ -234,8 +236,8 @@ bool DataStats::IsCategorical(size_t index, size_t quantity) { std::vector DataStats::DeleteNullAndEmpties(size_t index) const { mo::TypedColumnData const& col = col_data_[index]; mo::TypeId type_id = col.GetTypeId(); - if (type_id == +mo::TypeId::kNull || type_id == +mo::TypeId::kEmpty || - type_id == +mo::TypeId::kUndefined) + if (type_id == mo::TypeId::kNull || type_id == mo::TypeId::kEmpty || + type_id == mo::TypeId::kUndefined) return {}; std::vector const& data = col.GetData(); std::vector res; @@ -492,7 +494,7 @@ Statistic DataStats::GetMedianAD(size_t index) const { Statistic DataStats::GetVocab(size_t index) const { if (all_stats_[index].vocab.HasValue()) return all_stats_[index].vocab; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; mo::StringType string_type; std::string string_data; @@ -548,7 +550,7 @@ Statistic DataStats::GetNumberOfUppercaseChars(size_t index) const { template Statistic DataStats::CountIfInColumn(Pred pred, size_t index) const { mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; size_t count = 0; mo::IntType int_type; @@ -567,7 +569,7 @@ Statistic DataStats::CountIfInColumn(Pred pred, size_t index) const { Statistic DataStats::GetNumberOfChars(size_t index) const { mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; return GetStringSumOf(index, [](std::string const& line) { return line.size(); }); } @@ -576,7 +578,7 @@ Statistic DataStats::GetAvgNumberOfChars(size_t index) const { if (all_stats_[index].num_avg_chars.HasValue()) return all_stats_[index].num_avg_chars; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; mo::DoubleType double_type; mo::IntType int_type; @@ -656,7 +658,7 @@ Statistic DataStats::GetStringSumOf(size_t index, Pred pred) const { Statistic DataStats::GetMinNumberOfChars(size_t index) const { if (all_stats_[index].min_num_chars.HasValue()) return all_stats_[index].min_num_chars; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; return GetStringMinOf(index, [](std::string const& line) { return line.size(); }); } @@ -664,7 +666,7 @@ Statistic DataStats::GetMinNumberOfChars(size_t index) const { Statistic DataStats::GetMaxNumberOfChars(size_t index) const { if (all_stats_[index].max_num_chars.HasValue()) return all_stats_[index].max_num_chars; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; return GetStringMaxOf(index, [](std::string const& line) { return line.size(); }); } @@ -678,7 +680,7 @@ std::vector DataStats::GetWordsInString(std::string line) { std::set DataStats::GetWords(size_t index) const { mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; mo::StringType string_type; std::set words; @@ -707,7 +709,7 @@ Statistic DataStats::GetMinNumberOfWords(size_t index) const { if (all_stats_[index].min_num_words.HasValue()) return all_stats_[index].min_num_words; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; return GetStringMinOf(index, [](std::string const& line) { return GetNumberOfWordsInString(line); }); @@ -716,7 +718,7 @@ Statistic DataStats::GetMinNumberOfWords(size_t index) const { Statistic DataStats::GetMaxNumberOfWords(size_t index) const { if (all_stats_[index].max_num_words.HasValue()) return all_stats_[index].max_num_words; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; return GetStringMaxOf(index, [](std::string const& line) { return GetNumberOfWordsInString(line); }); @@ -725,7 +727,7 @@ Statistic DataStats::GetMaxNumberOfWords(size_t index) const { Statistic DataStats::GetNumberOfWords(size_t index) const { if (all_stats_[index].num_words.HasValue()) return all_stats_[index].num_words; mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; return GetStringSumOf(index, [](std::string const& line) { return GetNumberOfWordsInString(line); }); @@ -733,7 +735,7 @@ Statistic DataStats::GetNumberOfWords(size_t index) const { std::vector DataStats::GetTopKChars(size_t index, size_t k) const { mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; mo::StringType string_type; std::unordered_map count_chars; @@ -768,7 +770,7 @@ std::vector DataStats::GetTopKChars(size_t index, size_t k) const { std::vector DataStats::GetTopKWords(size_t index, size_t k) const { mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; mo::StringType string_type; std::unordered_map count_words; @@ -844,7 +846,7 @@ bool DataStats::IsEntirelyLowercase(std::string word) { template Statistic DataStats::CountIfInColumnForWords(Pred pred, size_t index) const { mo::TypedColumnData const& col = col_data_[index]; - if (col.GetTypeId() != +mo::TypeId::kString) return {}; + if (col.GetTypeId() != mo::TypeId::kString) return {}; std::size_t count = 0; std::string string_data; @@ -873,7 +875,7 @@ unsigned long long DataStats::ExecuteInternal() { double percent_per_col = kTotalProgressPercent / all_stats_.size(); auto task = [percent_per_col, this](size_t index) { all_stats_[index].count = NumberOfValues(index); - if (this->col_data_[index].GetTypeId() != +mo::TypeId::kMixed) { + if (this->col_data_[index].GetTypeId() != mo::TypeId::kMixed) { all_stats_[index].min = GetMin(index); all_stats_[index].max = GetMax(index); all_stats_[index].sum = GetSum(index); diff --git a/src/core/algorithms/ucc/hpivalid/enums.h b/src/core/algorithms/ucc/hpivalid/enums.h index c9102670de..2ec33d569f 100644 --- a/src/core/algorithms/ucc/hpivalid/enums.h +++ b/src/core/algorithms/ucc/hpivalid/enums.h @@ -1,10 +1,15 @@ #pragma once -#include +#include namespace algos::hpiv::timer { -BETTER_ENUM(TimerName, char, total = 0, construct_clusters, total_enum_algo, sample_diff_sets, - cluster_intersect, num_of_timers); - +enum class TimerName : size_t { + kTotal = 0, + kConstructClusters, + kTotalEnumAlgo, + kSampleDiffSets, + kClusterIntersect, + kNumOfTimers +}; } // namespace algos::hpiv::timer diff --git a/src/core/algorithms/ucc/hpivalid/hpivalid.cpp b/src/core/algorithms/ucc/hpivalid/hpivalid.cpp index 48c1631ce6..7b758816fd 100644 --- a/src/core/algorithms/ucc/hpivalid/hpivalid.cpp +++ b/src/core/algorithms/ucc/hpivalid/hpivalid.cpp @@ -24,7 +24,7 @@ void HPIValid::LoadDataInternal() { } hpiv::PLITable HPIValid::Preprocess(hpiv::ResultCollector& rc) { - rc.StartTimer(hpiv::timer::TimerName::construct_clusters); + rc.StartTimer(hpiv::timer::TimerName::kConstructClusters); hpiv::PLITable tab; @@ -39,7 +39,7 @@ hpiv::PLITable HPIValid::Preprocess(hpiv::ResultCollector& rc) { } tab.inverse_mapping = hy::util::BuildInvertedPlis(plis); - rc.StopTimer(hpiv::timer::TimerName::construct_clusters); + rc.StopTimer(hpiv::timer::TimerName::kConstructClusters); return tab; } @@ -47,24 +47,24 @@ unsigned long long HPIValid::ExecuteInternal() { hpiv::Config cfg; hpiv::ResultCollector rc(3600); - rc.StartTimer(hpiv::timer::TimerName::total); + rc.StartTimer(hpiv::timer::TimerName::kTotal); hpiv::PLITable tab = Preprocess(rc); - rc.StartTimer(hpiv::timer::TimerName::total_enum_algo); + rc.StartTimer(hpiv::timer::TimerName::kTotalEnumAlgo); hpiv::TreeSearch tree_search(tab, cfg, rc); tree_search.Run(); - rc.StopTimer(hpiv::timer::TimerName::total_enum_algo); + rc.StopTimer(hpiv::timer::TimerName::kTotalEnumAlgo); RegisterUCCs(rc); PrintInfo(rc); - rc.StopTimer(hpiv::timer::TimerName::total); - LOG_INFO("Elapsed time: {}", rc.Time(hpiv::timer::TimerName::total)); + rc.StopTimer(hpiv::timer::TimerName::kTotal); + LOG_INFO("Elapsed time: {}", rc.Time(hpiv::timer::TimerName::kTotal)); - return rc.Time(hpiv::timer::TimerName::total); + return rc.Time(hpiv::timer::TimerName::kTotal); } void HPIValid::RegisterUCCs(hpiv::ResultCollector const& rc) { diff --git a/src/core/algorithms/ucc/hpivalid/result_collector.cpp b/src/core/algorithms/ucc/hpivalid/result_collector.cpp index ad7b1b9f8b..071ce3be1f 100644 --- a/src/core/algorithms/ucc/hpivalid/result_collector.cpp +++ b/src/core/algorithms/ucc/hpivalid/result_collector.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "core/util/logger.h" // see algorithms/ucc/hpivalid/LICENSE @@ -22,7 +24,7 @@ ResultCollector::ResultCollector(double timeout) : timeout_(timeout), ucc_count_(0), diff_sets_final_(0), - timers_(timer::TimerName::num_of_timers), + timers_(magic_enum::enum_integer(timer::TimerName::kNumOfTimers)), diff_sets_(0), diff_sets_initial_(0), tree_complexity_(0), @@ -34,7 +36,7 @@ bool ResultCollector::UCCFound(Edge const& ucc) { ucc_count_++; ucc_vector_.push_back(ucc); return std::chrono::duration_cast>( - clock::now() - timers_[timer::TimerName::total].begin) + clock::now() - timers_[magic_enum::enum_integer(timer::TimerName::kTotal)].begin) .count() <= timeout_; } @@ -55,18 +57,20 @@ void ResultCollector::FinalHypergraph(Hypergraph const& hg) { } void ResultCollector::StartTimer(timer::TimerName timer) { - timers_[timer].begin = clock::now(); + timers_[magic_enum::enum_integer(timer)].begin = clock::now(); } void ResultCollector::StopTimer(timer::TimerName timer) { - timers_[timer].end = clock::now(); - timers_[timer].elapsed += std::chrono::duration_cast( - timers_[timer].end - timers_[timer].begin) - .count(); + timers_[magic_enum::enum_integer(timer)].end = clock::now(); + timers_[magic_enum::enum_integer(timer)].elapsed += + std::chrono::duration_cast( + timers_[magic_enum::enum_integer(timer)].end - + timers_[magic_enum::enum_integer(timer)].begin) + .count(); } unsigned long long ResultCollector::Time(timer::TimerName timer) const { - return timers_[timer].elapsed; + return timers_[magic_enum::enum_integer(timer)].elapsed; } void ResultCollector::CountDiffSets(unsigned number) { diff --git a/src/core/algorithms/ucc/hpivalid/tree_search.cpp b/src/core/algorithms/ucc/hpivalid/tree_search.cpp index 9524abb689..fe8e538855 100644 --- a/src/core/algorithms/ucc/hpivalid/tree_search.cpp +++ b/src/core/algorithms/ucc/hpivalid/tree_search.cpp @@ -35,7 +35,7 @@ TreeSearch::TreeSearch(PLITable const& tab, Config const& cfg, ResultCollector& } void TreeSearch::Run() { - rc_.StartTimer(timer::TimerName::sample_diff_sets); + rc_.StartTimer(timer::TimerName::kSampleDiffSets); for (auto const& pli : tab_.plis) { Hypergraph gen = Sample(pli); for (Edge const& e : gen) { @@ -43,7 +43,7 @@ void TreeSearch::Run() { } } rc_.StopInitialSampling(); - rc_.StopTimer(timer::TimerName::sample_diff_sets); + rc_.StopTimer(timer::TimerName::kSampleDiffSets); // S, CAND Edge s(partial_hg_.NumVertices()); @@ -321,14 +321,14 @@ inline bool TreeSearch::ExtendOrConfirmS( inline void TreeSearch::PullUpIntersections( std::stack>& intersection_stack, std::deque& tointersect_queue) { - rc_.StartTimer(timer::TimerName::cluster_intersect); + rc_.StartTimer(timer::TimerName::kClusterIntersect); while (!tointersect_queue.empty()) { intersection_stack.push(IntersectClusterListAndClusterMapping( intersection_stack.top(), tab_.inverse_mapping[tointersect_queue.front()])); tointersect_queue.pop_front(); } - rc_.StopTimer(timer::TimerName::cluster_intersect); + rc_.StopTimer(timer::TimerName::kClusterIntersect); } std::deque TreeSearch::IntersectClusterListAndClusterMapping( @@ -366,9 +366,9 @@ inline void TreeSearch::UpdateEdges(std::vector& crit, Edgemark& uncov std::vector>& removed_criticals_stack, std::deque const& pli) { // sample new edges - rc_.StartTimer(timer::TimerName::sample_diff_sets); + rc_.StartTimer(timer::TimerName::kSampleDiffSets); Hypergraph new_edges = Sample(pli); - rc_.StopTimer(timer::TimerName::sample_diff_sets); + rc_.StopTimer(timer::TimerName::kSampleDiffSets); // find out which edges are supersets and therefore can be removed and save // indices in descending order diff --git a/src/core/config/error_measure/option.cpp b/src/core/config/error_measure/option.cpp index bcbd042eb8..f877b0a632 100644 --- a/src/core/config/error_measure/option.cpp +++ b/src/core/config/error_measure/option.cpp @@ -1,5 +1,7 @@ #include "core/config/error_measure/option.h" +#include + #include "core/algorithms/fd/tane/enums.h" #include "core/config/names_and_descriptions.h" @@ -7,8 +9,10 @@ namespace config { using names::kPfdErrorMeasure, names::kAfdErrorMeasure, descriptions::kDPfdErrorMeasure, descriptions::kDAfdErrorMeasure; extern CommonOption const kPfdErrorMeasureOpt{ - kPfdErrorMeasure, kDPfdErrorMeasure, algos::PfdErrorMeasure::_values()[0]}; + kPfdErrorMeasure, kDPfdErrorMeasure, + magic_enum::enum_values().front()}; extern CommonOption const kAfdErrorMeasureOpt{ - kAfdErrorMeasure, kDAfdErrorMeasure, algos::AfdErrorMeasure::_values()[0]}; + kAfdErrorMeasure, kDAfdErrorMeasure, + magic_enum::enum_values().front()}; } // namespace config diff --git a/src/core/model/table/typed_column_data.cpp b/src/core/model/table/typed_column_data.cpp index 915a1599d7..e03ad56972 100644 --- a/src/core/model/table/typed_column_data.cpp +++ b/src/core/model/table/typed_column_data.cpp @@ -24,15 +24,15 @@ namespace model { TypeId TypedColumnDataFactory::DeduceColumnType() const { bool is_undefined = true; std::bitset<5> candidate_types_bitset("11111"); - TypeId first_type_id = +TypeId::kUndefined; + TypeId first_type_id = TypeId::kUndefined; for (std::size_t i = 0; i != unparsed_.size(); ++i) { if (!kNullCheck(unparsed_[i]) && !kEmptyCheck(unparsed_[i])) { is_undefined = false; - if (first_type_id != +TypeId::kUndefined) { + if (first_type_id != TypeId::kUndefined) { auto& type_check = kTypeIdToChecker.at(first_type_id); if (type_check(unparsed_[i])) { // undelimited and delimited dates have different bitsets - if (first_type_id == +TypeId::kDate && kDelimitedDateCheck(unparsed_[i])) { + if (first_type_id == TypeId::kDate && kDelimitedDateCheck(unparsed_[i])) { candidate_types_bitset &= kTypeIdToBitset.at(first_type_id); } continue; @@ -43,36 +43,36 @@ TypeId TypedColumnDataFactory::DeduceColumnType() const { bool matched = false; for (auto const& [type_id, type_check] : kTypeIdToChecker) { if (type_id != first_type_id && type_check(unparsed_[i])) { - if (first_type_id == +TypeId::kUndefined && !matched) { + if (first_type_id == TypeId::kUndefined && !matched) { first_type_id = type_id; } matched = true; new_candidate_types_bitset |= kTypeIdToBitset.at(type_id); // possible value types are known at the first match except for dates // (undelimited dates could be ints or doubles and delimited couldn't) - if (type_id == +TypeId::kDate && kUndelimitedDateCheck(unparsed_[i])) { - new_candidate_types_bitset |= kTypeIdToBitset.at(+TypeId::kInt); + if (type_id == TypeId::kDate && kUndelimitedDateCheck(unparsed_[i])) { + new_candidate_types_bitset |= kTypeIdToBitset.at(TypeId::kInt); } break; } } if (!matched) { - new_candidate_types_bitset = kTypeIdToBitset.at(+TypeId::kString); + new_candidate_types_bitset = kTypeIdToBitset.at(TypeId::kString); } candidate_types_bitset &= new_candidate_types_bitset; if (candidate_types_bitset.none()) { if (treat_mixed_as_string_) { - candidate_types_bitset = kTypeIdToBitset.at(+TypeId::kString); + candidate_types_bitset = kTypeIdToBitset.at(TypeId::kString); } else { - return +TypeId::kMixed; + return TypeId::kMixed; } } } } if (is_undefined) { - return +TypeId::kUndefined; + return TypeId::kUndefined; } for (std::size_t i = 0; i < 5; i++) { @@ -81,17 +81,17 @@ TypeId TypedColumnDataFactory::DeduceColumnType() const { } } - return +TypeId::kMixed; + return TypeId::kMixed; } TypedColumnDataFactory::TypeMap TypedColumnDataFactory::CreateTypeMap(TypeId const type_id) const { TypeMap type_map; auto const match = [&type_map, type_id](std::string const& val, size_t const row) { if (kNullCheck(val)) { - type_map[+TypeId::kNull].insert(row); + type_map[TypeId::kNull].insert(row); } else if (kEmptyCheck(val)) { - type_map[+TypeId::kEmpty].insert(row); - } else if (type_id != +TypeId::kMixed) { + type_map[TypeId::kEmpty].insert(row); + } else if (type_id != TypeId::kMixed) { type_map[type_id].insert(row); } else { bool matched = false; @@ -156,7 +156,7 @@ size_t TypedColumnDataFactory::CalculateMixedBufSize( TypedColumnData TypedColumnDataFactory::CreateMixedFromTypeMap(std::unique_ptr type, TypeMap type_map) { - assert(type->GetTypeId() == +TypeId::kMixed); + assert(type->GetTypeId() == TypeId::kMixed); MixedType const* mixed_type = static_cast(type.get()); std::vector data; data.reserve(unparsed_.size()); @@ -201,7 +201,7 @@ TypedColumnData TypedColumnDataFactory::CreateConcreteFromTypeMap(std::unique_pt TypeMap type_map) { TypeId const type_id = type->GetTypeId(); - if (type_id == +TypeId::kMixed) { + if (type_id == TypeId::kMixed) { /* For mixed type use CreateMixedFromTypeMap. */ assert(0); } @@ -215,7 +215,7 @@ TypedColumnData TypedColumnDataFactory::CreateConcreteFromTypeMap(std::unique_pt std::vector data(unparsed_.size()); - if (type_id == +TypeId::kUndefined) { + if (type_id == TypeId::kUndefined) { return TypedColumnData(column_, std::move(type), rows_num, nulls_num, empties_num, nullptr, std::move(data), std::move(nulls), std::move(empties)); } @@ -238,7 +238,7 @@ TypedColumnData TypedColumnDataFactory::CreateConcreteFromTypeMap(std::unique_pt TypedColumnData TypedColumnDataFactory::CreateFromTypeMap(std::unique_ptr type, TypeMap type_map) { - if (type->GetTypeId() == +TypeId::kMixed) { + if (type->GetTypeId() == TypeId::kMixed) { return CreateMixedFromTypeMap(std::move(type), std::move(type_map)); } else { return CreateConcreteFromTypeMap(std::move(type), std::move(type_map)); diff --git a/src/core/model/table/typed_column_data.h b/src/core/model/table/typed_column_data.h index ecc48f7998..a7b9742dac 100644 --- a/src/core/model/table/typed_column_data.h +++ b/src/core/model/table/typed_column_data.h @@ -5,6 +5,7 @@ #include #include +#include #include "core/model/table/abstract_column_data.h" #include "core/model/table/idataset_stream.h" @@ -54,10 +55,10 @@ class TypedColumnData : public model::AbstractColumnData { MixedType const* mixed = GetIfMixed(); for (size_t i = 0; i != data_.size(); ++i) { - if (GetValueTypeId(i) == +TypeId::kString || GetValueTypeId(i) == +TypeId::kBigInt || - GetValueTypeId(i) == +TypeId::kDate) { + if (GetValueTypeId(i) == TypeId::kString || GetValueTypeId(i) == TypeId::kBigInt || + GetValueTypeId(i) == TypeId::kDate) { std::byte const* value = (mixed) ? mixed->RetrieveValue(data_[i]) : data_[i]; - if (GetValueTypeId(i) == +TypeId::kDate) { + if (GetValueTypeId(i) == TypeId::kDate) { DateType::Destruct(value); } else { StringType::Destruct(value); @@ -109,7 +110,7 @@ class TypedColumnData : public model::AbstractColumnData { bool IsNull(size_t index) const noexcept { MixedType const* mixed = GetIfMixed(); if (mixed != nullptr) { - return mixed->RetrieveTypeId(data_[index]) == +TypeId::kNull; + return mixed->RetrieveTypeId(data_[index]) == TypeId::kNull; } else { return nulls_.find(index) != nulls_.end(); } @@ -118,7 +119,7 @@ class TypedColumnData : public model::AbstractColumnData { bool IsEmpty(size_t index) const noexcept { MixedType const* mixed = GetIfMixed(); if (mixed != nullptr) { - return mixed->RetrieveTypeId(data_[index]) == +TypeId::kEmpty; + return mixed->RetrieveTypeId(data_[index]) == TypeId::kEmpty; } else { return empties_.find(index) != empties_.end(); } @@ -130,7 +131,7 @@ class TypedColumnData : public model::AbstractColumnData { TypeId GetValueTypeId(size_t index) const noexcept { TypeId const type_id = type_->GetTypeId(); - if (type_id == +TypeId::kMixed) { + if (type_id == TypeId::kMixed) { return static_cast(type_.get())->RetrieveTypeId(data_[index]); } @@ -146,12 +147,12 @@ class TypedColumnData : public model::AbstractColumnData { bool IsNumeric() const noexcept { TypeId type_id = GetTypeId(); - return type_id == +TypeId::kInt || /* type_id == +ColumnTypeId::kBigInt || */ - type_id == +TypeId::kDouble; + return type_id == TypeId::kInt || /* type_id == ColumnTypeId::kBigInt || */ + type_id == TypeId::kDouble; } bool IsMixed() const noexcept { - return GetTypeId() == +TypeId::kMixed; + return GetTypeId() == TypeId::kMixed; } MixedType const* GetIfMixed() const noexcept { @@ -159,7 +160,8 @@ class TypedColumnData : public model::AbstractColumnData { } std::string ToString() const final { - return "Data for column " + column_->ToString() + " of type " + GetTypeId()._to_string(); + return "Data for column " + column_->ToString() + " of type " + + std::string(magic_enum::enum_name(GetTypeId())); } }; @@ -174,7 +176,7 @@ class TypedColumnDataFactory { bool treat_mixed_as_string_; inline static std::vector const kAllCandidateTypes = { - +TypeId::kDate, +TypeId::kInt, +TypeId::kBigInt, +TypeId::kDouble, +TypeId::kString}; + TypeId::kDate, TypeId::kInt, TypeId::kBigInt, TypeId::kDouble, TypeId::kString}; inline static std::unordered_map const kTypeIdToRegex = { {TypeId::kDate, boost::regex( @@ -184,15 +186,15 @@ class TypedColumnDataFactory { R"(^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$|)" R"(^[+-]?(?i)(inf|nan)(?-i)$|)" R"(^[+-]?0[xX](((\d|[a-f]|[A-F]))+(\.(\d|[a-f]|[A-F])*)?|\.(\d|[a-f]|[A-F])+)([pP][+-]?\d+)?$)")}, - {+TypeId::kBigInt, boost::regex(R"(^(\+|-)?\d{20,}$)")}, - {+TypeId::kInt, boost::regex(R"(^(\+|-)?\d{1,19}$)")}, - {+TypeId::kNull, boost::regex(Null::kValue.data())}, - {+TypeId::kEmpty, boost::regex(R"(^$)")}}; + {TypeId::kBigInt, boost::regex(R"(^(\+|-)?\d{20,}$)")}, + {TypeId::kInt, boost::regex(R"(^(\+|-)?\d{1,19}$)")}, + {TypeId::kNull, boost::regex(Null::kValue.data())}, + {TypeId::kEmpty, boost::regex(R"(^$)")}}; inline static auto const kNullCheck = [](std::string const& val) { - return boost::regex_match(val, kTypeIdToRegex.at(+TypeId::kNull)); + return boost::regex_match(val, kTypeIdToRegex.at(TypeId::kNull)); }; inline static auto const kEmptyCheck = [](std::string const& val) { - return boost::regex_match(val, kTypeIdToRegex.at(+TypeId::kEmpty)); + return boost::regex_match(val, kTypeIdToRegex.at(TypeId::kEmpty)); }; inline static std::function const kUndelimitedDateCheck = [](std::string const& val) { @@ -218,27 +220,27 @@ class TypedColumnDataFactory { kTypeIdToChecker = { {TypeId::kDouble, [](std::string const& val) { - return boost::regex_match(val, kTypeIdToRegex.at(+TypeId::kDouble)); + return boost::regex_match(val, kTypeIdToRegex.at(TypeId::kDouble)); }}, {TypeId::kBigInt, [](std::string const& val) { - return boost::regex_match(val, kTypeIdToRegex.at(+TypeId::kBigInt)); + return boost::regex_match(val, kTypeIdToRegex.at(TypeId::kBigInt)); }}, {TypeId::kInt, [](std::string const& val) { - return boost::regex_match(val, kTypeIdToRegex.at(+TypeId::kInt)); + return boost::regex_match(val, kTypeIdToRegex.at(TypeId::kInt)); }}, {TypeId::kDate, [](std::string const& val) { - return boost::regex_match(val, kTypeIdToRegex.at(+TypeId::kDate)) && + return boost::regex_match(val, kTypeIdToRegex.at(TypeId::kDate)) && (kDelimitedDateCheck(val) || kUndelimitedDateCheck(val)); }}}; // each 1 represents a possible type from kAllCandidateTypes inline static std::unordered_map> const kTypeIdToBitset = { - {+TypeId::kDate, std::bitset<5>("00001")}, // bitset for delimited dates - {+TypeId::kInt, std::bitset<5>("01110")}, - {+TypeId::kBigInt, std::bitset<5>("01100")}, - {+TypeId::kDouble, std::bitset<5>("01000")}, - {+TypeId::kString, std::bitset<5>("10000")}}; + {TypeId::kDate, std::bitset<5>("00001")}, // bitset for delimited dates + {TypeId::kInt, std::bitset<5>("01110")}, + {TypeId::kBigInt, std::bitset<5>("01100")}, + {TypeId::kDouble, std::bitset<5>("01000")}, + {TypeId::kString, std::bitset<5>("10000")}}; size_t CalculateMixedBufSize(std::vector const& types_layout, TypeIdToType const& type_id_to_type) const noexcept; diff --git a/src/core/model/types/builtin.h b/src/core/model/types/builtin.h index 515591ef8f..4d0e2cf969 100644 --- a/src/core/model/types/builtin.h +++ b/src/core/model/types/builtin.h @@ -4,8 +4,9 @@ #include #include -#include +#include +#define MAGIC_ENUM_ENABLE_HASH namespace model { /* Aliases below are used to describe types containing in ColumnData and a ColumnData type itself. @@ -47,7 +48,7 @@ using AllValueTypes = std::tuple; * avoid confusion. */ // clang-format off -BETTER_ENUM(TypeId, char, +enum class TypeId : char { kInt = 0, /* Except for nulls and empties column contains only ints * (fixed-precision integer value) */ kDouble, /* Except for nulls and empties column contains only doubles @@ -62,7 +63,7 @@ BETTER_ENUM(TypeId, char, kEmpty, /* Column contains only empties ("" value) */ kUndefined, /* Column contains only nulls and empties */ kMixed /* Except for nulls and empties column contains more than one type */ -); +}; // clang-format on @@ -139,6 +140,3 @@ struct TupleMaxAlign> { inline constexpr size_t kTypesMaxAlignment = detail::TupleMaxAlign::kValue; } // namespace model - -/* Should be outside the namespace */ -BETTER_ENUMS_DECLARE_STD_HASH(model::TypeId) diff --git a/src/core/model/types/mixed_type.h b/src/core/model/types/mixed_type.h index 9df3d08ed1..d13d138662 100644 --- a/src/core/model/types/mixed_type.h +++ b/src/core/model/types/mixed_type.h @@ -32,7 +32,7 @@ class MixedType final : public Type { return alignment; } - static constexpr size_t kTypeIdSize = sizeof(TypeId::_integral); + static constexpr size_t kTypeIdSize = sizeof(std::underlying_type_t); public: explicit MixedType(bool is_null_eq_null) noexcept @@ -68,10 +68,10 @@ class MixedType final : public Type { void Free(std::byte const* value) const noexcept override { TypeId const type_id = RetrieveTypeId(value); - if (type_id == +TypeId::kString || type_id == +TypeId::kBigInt) { + if (type_id == TypeId::kString || type_id == TypeId::kBigInt) { StringType::Destruct(RetrieveValue(value)); } - if (type_id == +TypeId::kDate) { + if (type_id == TypeId::kDate) { DateType::Destruct(RetrieveValue(value)); } Type::Free(value); diff --git a/src/core/model/types/type.h b/src/core/model/types/type.h index 47a250627e..f2a7ec99a5 100644 --- a/src/core/model/types/type.h +++ b/src/core/model/types/type.h @@ -4,6 +4,8 @@ #include #include +#include + #include "core/model/types/builtin.h" namespace model { @@ -34,20 +36,20 @@ class Type { } [[nodiscard]] bool IsNumeric() const noexcept { - return type_id_ == +TypeId::kInt /* || type_id_ == +TypeId::kBigInt */ || - type_id_ == +TypeId::kDouble; + return type_id_ == TypeId::kInt /* || type_id_ == TypeId::kBigInt */ || + type_id_ == TypeId::kDouble; } [[nodiscard]] bool IsDate() const noexcept { - return type_id_ == +TypeId::kDate; + return type_id_ == TypeId::kDate; } [[nodiscard]] bool IsMetrizable() const noexcept { - return IsNumeric() || type_id_ == +TypeId::kString || IsDate(); + return IsNumeric() || type_id_ == TypeId::kString || IsDate(); } [[nodiscard]] std::string ToString() const { - return type_id_._to_string(); + return std::string(magic_enum::enum_name(type_id_)); } /* Operations on values of current type */ @@ -126,8 +128,8 @@ class Type { } static bool IsOrdered(TypeId const& type_id) { - return !(type_id == +TypeId::kEmpty || type_id == +TypeId::kNull || - type_id == +TypeId::kUndefined || type_id == +TypeId::kMixed); + return !(type_id == TypeId::kEmpty || type_id == TypeId::kNull || + type_id == TypeId::kUndefined || type_id == TypeId::kMixed); } virtual Destructor GetDestructor() const { diff --git a/src/core/util/atomic_bit_vector.h b/src/core/util/atomic_bit_vector.h new file mode 100644 index 0000000000..257f1530ce --- /dev/null +++ b/src/core/util/atomic_bit_vector.h @@ -0,0 +1,84 @@ +/* + * Based on atomic_bitvector by Erik Garrison (Apache 2.0) + * https://github.com/ekg/atomicbitvector + * + * Simplified version without iterator support. + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace util { + +class AtomicBitVector { +public: + AtomicBitVector(size_t size) + : size_(size), + num_blocks_((size + kBitsPerBlock - 1) / kBitsPerBlock), + data_(std::make_unique[]>(num_blocks_)) {} + + // Set bit to true. Returns previous value. + bool Set(size_t idx, std::memory_order order = std::memory_order_seq_cst) { + assert(idx < size_); + BlockType mask = kOne << BitOffset(idx); + return data_[BlockIndex(idx)].fetch_or(mask, order) & mask; + } + + // Set bit to false. Returns previous value. + bool Reset(size_t idx, std::memory_order order = std::memory_order_seq_cst) { + assert(idx < size_); + BlockType mask = kOne << BitOffset(idx); + return data_[BlockIndex(idx)].fetch_and(~mask, order) & mask; + } + + // Set bit to given value. Returns previous value. + bool Set(size_t idx, bool value, std::memory_order order = std::memory_order_seq_cst) { + return value ? Set(idx, order) : Reset(idx, order); + } + + // Read bit value. + bool Test(size_t idx, std::memory_order order = std::memory_order_seq_cst) const { + assert(idx < size_); + BlockType mask = kOne << BitOffset(idx); + return data_[BlockIndex(idx)].load(order) & mask; + } + + bool operator[](size_t idx) const { + return Test(idx); + } + + constexpr size_t Size() const noexcept { + return size_; + } + +private: +#if (ATOMIC_LLONG_LOCK_FREE == 2) + using BlockType = unsigned long long; +#elif (ATOMIC_LONG_LOCK_FREE == 2) + using BlockType = unsigned long; +#else + using BlockType = unsigned int; +#endif + + static constexpr size_t kBitsPerBlock = std::numeric_limits::digits; + static constexpr BlockType kOne = 1; + + static constexpr size_t BlockIndex(size_t bit) { + return bit / kBitsPerBlock; + } + + static constexpr size_t BitOffset(size_t bit) { + return bit % kBitsPerBlock; + } + + size_t size_; + size_t num_blocks_; + std::unique_ptr[]> data_; +}; + +} // namespace util diff --git a/src/core/util/enum_to_available_values.h b/src/core/util/enum_to_available_values.h index 52e3f9e64d..fe2b905e3d 100644 --- a/src/core/util/enum_to_available_values.h +++ b/src/core/util/enum_to_available_values.h @@ -2,20 +2,26 @@ #include #include +#include + +#include namespace util { -template +template + requires std::is_enum_v static std::string EnumToAvailableValues() { std::stringstream avail_values; - avail_values << '['; + constexpr auto& enum_names = magic_enum::enum_names(); - for (auto const& name : BetterEnumType::_names()) { - avail_values << name << '|'; + avail_values << '['; + for (size_t i = 0; i < enum_names.size(); ++i) { + avail_values << enum_names[i]; + if (i < enum_names.size() - 1) { + avail_values << '|'; + } } - - avail_values.seekp(-1, std::stringstream::cur); avail_values << ']'; return avail_values.str(); diff --git a/src/core/util/enum_to_str.h b/src/core/util/enum_to_str.h new file mode 100644 index 0000000000..df02fb34b0 --- /dev/null +++ b/src/core/util/enum_to_str.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include + +#include + +namespace util { + +inline std::string KCamelToSnake(std::string_view input) { + std::string out; + out.reserve(input.size()); + size_t start = (input.size() > 1 && input[0] == 'k' && std::isupper(input[1])) ? 1 : 0; + + for (size_t i = start; i < input.size(); ++i) { + char c = input[i]; + if (std::isupper(c)) { + if (i > start) out.push_back('_'); + out.push_back(std::tolower(static_cast(c))); + } else { + out.push_back(c); + } + } + return out; +} + +inline std::string SnakeToKCamel(std::string_view input) { + std::string out; + out.reserve(input.size() + 1); + out.push_back('k'); + + bool cap_next = true; + for (char c : input) { + if (c == '_') { + cap_next = true; + } else if (cap_next) { + out.push_back(std::toupper(static_cast(c))); + cap_next = false; + } else { + out.push_back(std::tolower(static_cast(c))); + } + } + return out; +} + +template + requires std::is_enum_v +std::string EnumToStr(E value) { + return KCamelToSnake(magic_enum::enum_name(value)); +} + +template + requires std::is_enum_v +std::optional EnumFromStr(std::string_view str) { + return magic_enum::enum_cast(SnakeToKCamel(str)); +} + +} // namespace util diff --git a/src/core/util/static_map.h b/src/core/util/static_map.h new file mode 100644 index 0000000000..ea4179b7a2 --- /dev/null +++ b/src/core/util/static_map.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include + +namespace util { +/** + * @brief Provides a constexpr immutable map-like lookup structure based on std::array. + + * @tparam Key The key type. Must be comparable with `operator==`. + * @tparam Value The value type. + * @tparam N The number of key-value pairs in the map. + */ +template +struct StaticMap { + std::array, N> data; + + [[nodiscard]] constexpr Value const& At(Key const& key) const { + for (auto const& pair : data) { + if (pair.first == key) { + return pair.second; + } + } + throw std::out_of_range("StaticMap::at: key not found"); + } + + [[nodiscard]] constexpr Value const* Find(Key const& key) const { + for (auto const& pair : data) { + if (pair.first == key) { + return &pair.second; + } + } + return nullptr; + } + + [[nodiscard]] constexpr auto begin() const { + return data.begin(); + } + + [[nodiscard]] constexpr auto end() const { + return data.end(); + } + + [[nodiscard]] constexpr auto Size() const { + return N; + } + + [[nodiscard]] constexpr bool Empty() const { + return N == 0; + } +}; +} // namespace util diff --git a/src/python_bindings/ac/bind_ac.cpp b/src/python_bindings/ac/bind_ac.cpp index 5c95e3c73e..fbd6d0da5b 100644 --- a/src/python_bindings/ac/bind_ac.cpp +++ b/src/python_bindings/ac/bind_ac.cpp @@ -1,5 +1,6 @@ #include "python_bindings/ac/bind_ac.h" +#include #include #include @@ -83,7 +84,8 @@ void BindAc(py::module_& main_module) { auto col_indices = t[0].cast>(); int type_id_int = t[1].cast(); auto s_ranges = t[2].cast>(); - model::TypeId type_id = model::TypeId::_from_integral(type_id_int); + auto type_id = magic_enum::enum_cast(type_id_int) + .value_or(model::TypeId::kUndefined); std::unique_ptr num_type = CreateNumericTypeFromTypeId(type_id); std::vector ranges; diff --git a/src/python_bindings/dc/bind_fastadc.cpp b/src/python_bindings/dc/bind_fastadc.cpp index 059a57d565..deec8af30a 100644 --- a/src/python_bindings/dc/bind_fastadc.cpp +++ b/src/python_bindings/dc/bind_fastadc.cpp @@ -4,6 +4,7 @@ #include #include "core/algorithms/dc/FastADC/fastadc.h" +#include "core/util/enum_to_str.h" #include "python_bindings/py_util/bind_primitive.h" #include "python_bindings/py_util/table_serialization.h" @@ -13,7 +14,7 @@ using namespace algos::fastadc; namespace fastadc_serialization { py::tuple SerializeColumnOperand(ColumnOperand const& operand) { - return py::make_tuple(operand.GetColumn()->GetIndex(), operand.GetTuple()._to_string()); + return py::make_tuple(operand.GetColumn()->GetIndex(), util::EnumToStr(operand.GetTuple())); } ColumnOperand DeserializeColumnOperand(py::tuple t, @@ -21,8 +22,9 @@ ColumnOperand DeserializeColumnOperand(py::tuple t, if (t.size() != 2) throw std::runtime_error("Invalid state for ColumnOperand pickle!"); auto col_index = t[0].cast(); auto tuple_str = t[1].cast(); - auto tuple_type = ColumnOperandTuple::_from_string(tuple_str.c_str()); - return ColumnOperand(schema->GetColumn(col_index), tuple_type); + auto tuple_type = util::EnumFromStr(tuple_str); + if (!tuple_type) throw std::runtime_error("Invalid tuple type: " + tuple_str); + return ColumnOperand(schema->GetColumn(col_index), *tuple_type); } py::tuple SerializePredicate(PredicatePtr predicate) { diff --git a/src/python_bindings/nar/bind_nar.cpp b/src/python_bindings/nar/bind_nar.cpp index 2b4d80fd0d..13499182f4 100644 --- a/src/python_bindings/nar/bind_nar.cpp +++ b/src/python_bindings/nar/bind_nar.cpp @@ -11,23 +11,28 @@ namespace py = pybind11; namespace nar_serialization { py::object SerializeValueRange(std::shared_ptr const& vr) { - switch (int type_code = vr->GetTypeId()) { + switch (auto const type_id = vr->GetTypeId()) { case model::TypeId::kString: { auto svr = std::dynamic_pointer_cast(vr); - return py::make_tuple(type_code, svr->domain); + return py::make_tuple(magic_enum::enum_integer(type_id), svr->domain); } case model::TypeId::kDouble: { auto nvr = std::dynamic_pointer_cast>(vr); - return py::make_tuple(type_code, py::make_tuple(nvr->lower_bound, nvr->upper_bound)); + return py::make_tuple(magic_enum::enum_integer(type_id), + py::make_tuple(nvr->lower_bound, nvr->upper_bound)); } case model::TypeId::kInt: { auto nvr = std::dynamic_pointer_cast>(vr); - return py::make_tuple(type_code, py::make_tuple(nvr->lower_bound, nvr->upper_bound)); - } - default: { - throw std::runtime_error("Unsupported ValueRange type in serialization."); + return py::make_tuple(magic_enum::enum_integer(type_id), + py::make_tuple(nvr->lower_bound, nvr->upper_bound)); } + + default: + throw std::runtime_error(std::string("Unsupported type: ") + + std::string(magic_enum::enum_name(type_id))); } + + throw std::runtime_error("Unsupported ValueRange type in serialization."); } std::shared_ptr DeserializeValueRange(py::object const& obj) { @@ -36,7 +41,8 @@ std::shared_ptr DeserializeValueRange(py::object const& obj) throw std::runtime_error("Invalid ValueRange tuple size!"); } int type_code = tup[0].cast(); - model::TypeId type_id = model::TypeId::_from_integral(type_code); + model::TypeId type_id = + magic_enum::enum_cast(type_code).value_or(model::TypeId::kUndefined); switch (type_id) { case model::TypeId::kString: { auto domain = tup[1].cast>(); diff --git a/src/python_bindings/py_util/opt_to_py.cpp b/src/python_bindings/py_util/opt_to_py.cpp index 5873b31d18..9f52fd3375 100644 --- a/src/python_bindings/py_util/opt_to_py.cpp +++ b/src/python_bindings/py_util/opt_to_py.cpp @@ -17,6 +17,7 @@ #include "core/config/indices/type.h" #include "core/config/max_lhs/type.h" #include "core/config/thread_number/type.h" +#include "core/util/enum_to_str.h" namespace { namespace py = pybind11; @@ -30,7 +31,7 @@ std::pair normal_conv_pair{ template std::pair enum_conv_pair{ std::type_index(typeid(T)), - [](boost::any value) { return py::cast(boost::any_cast(value)._to_string()); }}; + [](boost::any value) { return py::cast(util::EnumToStr(boost::any_cast(value))); }}; std::unordered_map const kConverters{ normal_conv_pair, normal_conv_pair, diff --git a/src/python_bindings/py_util/py_to_any.cpp b/src/python_bindings/py_util/py_to_any.cpp index aec6eb1339..d9dadded3d 100644 --- a/src/python_bindings/py_util/py_to_any.cpp +++ b/src/python_bindings/py_util/py_to_any.cpp @@ -22,6 +22,7 @@ #include "core/config/tabular_data/input_tables_type.h" #include "core/parser/csv_parser/csv_parser.h" #include "core/util/enum_to_available_values.h" +#include "core/util/enum_to_str.h" #include "python_bindings/py_util/create_dataframe_reader.h" namespace { @@ -65,39 +66,59 @@ std::pair const kNormalConvPair{ }}; template + requires magic_enum::is_scoped_enum_v || magic_enum::is_unscoped_enum_v std::pair const kEnumConvPair{ - std::type_index(typeid(EnumType)), [](std::string_view option_name, py::handle value) { - auto string = CastAndReplaceCastError(option_name, value); - better_enums::optional enum_holder = - EnumType::_from_string_nocase_nothrow(string.data()); - if (enum_holder) return *enum_holder; + std::type_index(typeid(EnumType)), + [](std::string_view option_name, py::handle value) -> boost::any { + auto user_str = CastAndReplaceCastError(option_name, value); + auto enum_optional = util::EnumFromStr(user_str); + + if (enum_optional) return *enum_optional; std::stringstream error_message; - error_message << "Incorrect value for option \"" << option_name - << "\". Possible values: " << util::EnumToAvailableValues(); + std::stringstream possible_values; + + possible_values << "["; + constexpr auto& values = magic_enum::enum_values(); + for (size_t i = 0; i < values.size(); ++i) { + possible_values << util::EnumToStr(values[i]); + if (i < values.size() - 1) { + possible_values << "|"; + } + } + possible_values << "]"; + + error_message << "Incorrect value '" << user_str << "' for option \"" << option_name + << "\". Possible values: " << possible_values.str(); + throw config::ConfigurationError(error_message.str()); }}; template + requires magic_enum::is_scoped_enum_v || magic_enum::is_unscoped_enum_v std::pair const kCharEnumConvPair{ - std::type_index(typeid(EnumType)), [](std::string_view option_name, py::handle value) { - using EnumValueType = typename EnumType::_integral; - // May be applicable to other types. - static_assert(std::is_same_v); - auto char_value = CastAndReplaceCastError(option_name, value); - better_enums::optional enum_holder = - EnumType::_from_integral_nothrow(char_value); - if (enum_holder) return *enum_holder; + std::type_index(typeid(EnumType)), + [](std::string_view option_name, py::handle value) -> boost::any { + using UnderlyingType = magic_enum::underlying_type_t; + static_assert(std::is_same_v, + "This converter is for char-based enums only."); - std::stringstream error_message; - error_message << "Incorrect value for option \"" << option_name - << "\". Possible values: "; + auto char_value = CastAndReplaceCastError(option_name, value); + auto enum_optional = magic_enum::enum_cast(char_value); + + if (enum_optional) return *enum_optional; - error_message << '['; - for (auto const& val : EnumType::_values()) { - error_message << val._to_integral() << '|'; + std::stringstream error_message; + error_message << "Incorrect integral value '" << static_cast(char_value) + << "' for option \"" << option_name << "\". Possible values are: ["; + + constexpr auto& enum_values = magic_enum::enum_values(); + for (size_t i = 0; i < enum_values.size(); ++i) { + error_message << static_cast(magic_enum::enum_integer(enum_values[i])); + if (i < enum_values.size() - 1) { + error_message << '|'; + } } - error_message.seekp(-1, std::stringstream::cur); error_message << ']'; throw config::ConfigurationError(error_message.str()); diff --git a/src/tests/benchmark/fd_benchmark.h b/src/tests/benchmark/fd_benchmark.h index cafe56f0a8..54a196aec4 100644 --- a/src/tests/benchmark/fd_benchmark.h +++ b/src/tests/benchmark/fd_benchmark.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "core/algorithms/fd/aidfd/aid.h" #include "core/algorithms/fd/eulerfd/eulerfd.h" #include "core/algorithms/fd/hyfd/hyfd.h" @@ -34,14 +36,14 @@ inline void FDBenchmark(BenchmarkRunner& runner, BenchmarkComparer& comparer) { ""); comparer.SetThreshold(pyro_name, 22); - for (auto measure : algos::AfdErrorMeasure::_values()) { + for (auto measure : magic_enum::enum_values()) { // mu_plus is much slower than other measures - auto dataset = measure == +algos::AfdErrorMeasure::mu_plus ? tests::kMushroomPlus2attr1500 - : tests::kMushroomPlus3attr1300; + auto dataset = measure == algos::AfdErrorMeasure::kMuPlus ? tests::kMushroomPlus2attr1500 + : tests::kMushroomPlus3attr1300; auto tane_name = runner.RegisterSimpleBenchmark( dataset, {{kError, static_cast(0.95)}, {kAfdErrorMeasure, measure}}, - measure._to_string()); + std::string(magic_enum::enum_name(measure))); comparer.SetThreshold(tane_name, 20); } diff --git a/src/tests/benchmark/nar_benchmark.h b/src/tests/benchmark/nar_benchmark.h index 153ff8f911..c5cde664cc 100644 --- a/src/tests/benchmark/nar_benchmark.h +++ b/src/tests/benchmark/nar_benchmark.h @@ -20,7 +20,7 @@ inline void NARBenchmark(BenchmarkRunner& runner, BenchmarkComparer& comparer) { {kMaxFitnessEvaluations, static_cast(std::pow(10, 5))}, {kCrossoverProbability, 0.9}, {kDifferentialScale, 0.5}, - {kDifferentialStrategy, +algos::des::DifferentialStrategy::rand1Bin}}); + {kDifferentialStrategy, algos::des::DifferentialStrategy::kRand1Bin}}); comparer.SetThreshold(des_name, 20); } diff --git a/src/tests/unit/test_ac_algorithm.cpp b/src/tests/unit/test_ac_algorithm.cpp index ddf66b420b..62992d9ffd 100644 --- a/src/tests/unit/test_ac_algorithm.cpp +++ b/src/tests/unit/test_ac_algorithm.cpp @@ -61,7 +61,7 @@ class ACAlgorithmTest : public ::testing::Test { } static std::unique_ptr CreateACAlgorithmInstance( - CSVConfig const& csv_config, algos::Binop bin_operation = algos::Binop::Addition, + CSVConfig const& csv_config, algos::Binop bin_operation = algos::Binop::kAddition, double fuzziness = 0.1, double p_fuzz = 0.9, double weight = 0.1, size_t bumps_limit = 0, size_t iterations_limit = 10, double seed = 0) { return algos::CreateAndLoadAlgorithm( @@ -71,7 +71,7 @@ class ACAlgorithmTest : public ::testing::Test { }; TEST_F(ACAlgorithmTest, NonFuzzyBumpsDetection1) { - auto a = CreateACAlgorithmInstance(kIris, algos::Binop::Addition, 0.0, 0.9, 0.05); + auto a = CreateACAlgorithmInstance(kIris, algos::Binop::kAddition, 0.0, 0.9, 0.05); a->Execute(); auto& ranges_collection = a->GetRangesByColumns(0, 2); @@ -81,7 +81,7 @@ TEST_F(ACAlgorithmTest, NonFuzzyBumpsDetection1) { } TEST_F(ACAlgorithmTest, NonFuzzyBumpsDetection2) { - auto a = CreateACAlgorithmInstance(kIris, algos::Binop::Addition, 0.0, 0.9, 0.05); + auto a = CreateACAlgorithmInstance(kIris, algos::Binop::kAddition, 0.0, 0.9, 0.05); a->Execute(); auto& ranges_collection = a->GetRangesByColumns(2, 3); @@ -91,7 +91,7 @@ TEST_F(ACAlgorithmTest, NonFuzzyBumpsDetection2) { } TEST_F(ACAlgorithmTest, SampleSizeCalculation) { - auto a = CreateACAlgorithmInstance(kIris, algos::Binop::Addition, 0.1, 0.8, 0.05); + auto a = CreateACAlgorithmInstance(kIris, algos::Binop::kAddition, 0.1, 0.8, 0.05); ASSERT_EQ(28, a->CalculateSampleSize(1)); /* Sample size can't be greather than number of rows in the table */ ASSERT_EQ(150, a->CalculateSampleSize(13)); @@ -99,7 +99,7 @@ TEST_F(ACAlgorithmTest, SampleSizeCalculation) { } TEST_F(ACAlgorithmTest, SubNonFuzzy) { - auto a = CreateACAlgorithmInstance(kIris, algos::Binop::Subtraction, 0.0); + auto a = CreateACAlgorithmInstance(kIris, algos::Binop::kSubtraction, 0.0); a->Execute(); auto& ranges_collection = a->GetRangesByColumns(1, 3); @@ -109,7 +109,7 @@ TEST_F(ACAlgorithmTest, SubNonFuzzy) { } TEST_F(ACAlgorithmTest, MulNonFuzzy) { - auto a = CreateACAlgorithmInstance(kIris, algos::Binop::Multiplication, 0.0); + auto a = CreateACAlgorithmInstance(kIris, algos::Binop::kMultiplication, 0.0); a->Execute(); auto& ranges_collection = a->GetRangesByColumns(2, 3); @@ -119,7 +119,7 @@ TEST_F(ACAlgorithmTest, MulNonFuzzy) { } TEST_F(ACAlgorithmTest, DivNonFuzzy) { - auto a = CreateACAlgorithmInstance(kTestZeros, algos::Binop::Division, 0.0); + auto a = CreateACAlgorithmInstance(kTestZeros, algos::Binop::kDivision, 0.0); a->Execute(); auto& ranges_collection01 = a->GetRangesByColumns(0, 1); auto& ranges_collection10 = a->GetRangesByColumns(1, 0); @@ -141,7 +141,7 @@ TEST_F(ACAlgorithmTest, DivNonFuzzy) { } TEST_F(ACAlgorithmTest, FuzzyBumpsDetection) { - auto a = CreateACAlgorithmInstance(kTestLong, algos::Binop::Addition, 0.55, 0.41, 0.1); + auto a = CreateACAlgorithmInstance(kTestLong, algos::Binop::kAddition, 0.55, 0.41, 0.1); a->Execute(); auto& ranges_collection01 = a->GetRangesByColumns(0, 1); auto& ranges_collection02 = a->GetRangesByColumns(0, 2); @@ -157,7 +157,7 @@ TEST_F(ACAlgorithmTest, FuzzyBumpsDetection) { } TEST_F(ACAlgorithmTest, NullAndEmptyIgnoring) { - auto a = CreateACAlgorithmInstance(kNullEmpty, algos::Binop::Addition, 0.0); + auto a = CreateACAlgorithmInstance(kNullEmpty, algos::Binop::kAddition, 0.0); a->Execute(); auto& ranges = a->GetRangesCollections(); EXPECT_EQ(ranges.size(), 6); @@ -175,14 +175,14 @@ TEST_F(ACAlgorithmTest, NullAndEmptyIgnoring) { } TEST_F(ACAlgorithmTest, ColumnTypesPairing) { - auto a = CreateACAlgorithmInstance(kSimpleTypes, algos::Binop::Addition, 0.0); + auto a = CreateACAlgorithmInstance(kSimpleTypes, algos::Binop::kAddition, 0.0); a->Execute(); auto& ranges = a->GetRangesCollections(); EXPECT_EQ(ranges.size(), 2); } TEST_F(ACAlgorithmTest, CollectingACExceptions) { - auto a = CreateACAlgorithmInstance(kTestLong, algos::Binop::Addition, 0.55, 0.41, 0.1); + auto a = CreateACAlgorithmInstance(kTestLong, algos::Binop::kAddition, 0.55, 0.41, 0.1); a->Execute(); a->CollectACExceptions(); @@ -196,7 +196,7 @@ TEST_F(ACAlgorithmTest, CollectingACExceptions) { } TEST_F(ACAlgorithmTest, RangesReconstruction) { - auto a = CreateACAlgorithmInstance(kIris, algos::Binop::Subtraction, 0.0); + auto a = CreateACAlgorithmInstance(kIris, algos::Binop::kSubtraction, 0.0); a->Execute(); auto ranges_collection = a->ReconstructRangesByColumns(1, 3, 1); std::vector expected_ranges = {0.3, 4.0}; diff --git a/src/tests/unit/test_apriori.cpp b/src/tests/unit/test_apriori.cpp index a64a0f0c4c..9219cb3503 100644 --- a/src/tests/unit/test_apriori.cpp +++ b/src/tests/unit/test_apriori.cpp @@ -75,7 +75,7 @@ class ARAlgorithmTest : public ::testing::Test { double minconf, unsigned int tidColumnIndex, unsigned int itemColumnIndex) { using namespace config::names; - return {{kCsvConfig, csv_config}, {kInputFormat, +algos::InputFormat::singular}, + return {{kCsvConfig, csv_config}, {kInputFormat, algos::InputFormat::kSingular}, {kMinimumSupport, minsup}, {kMinimumConfidence, minconf}, {kTIdColumnIndex, tidColumnIndex}, {kItemColumnIndex, itemColumnIndex}}; } @@ -84,7 +84,7 @@ class ARAlgorithmTest : public ::testing::Test { double minconf, bool firstColumnTid) { using namespace config::names; return {{kCsvConfig, csv_config}, - {kInputFormat, +algos::InputFormat::tabular}, + {kInputFormat, algos::InputFormat::kTabular}, {kMinimumSupport, minsup}, {kMinimumConfidence, minconf}, {kFirstColumnTId, firstColumnTid}}; diff --git a/src/tests/unit/test_cfd_algos.cpp b/src/tests/unit/test_cfd_algos.cpp index 7e9c2e9380..dc3545406d 100644 --- a/src/tests/unit/test_cfd_algos.cpp +++ b/src/tests/unit/test_cfd_algos.cpp @@ -2,6 +2,7 @@ // see input_data/cfd_data/LICENSE #include +#include #include "core/algorithms/algo_factory.h" #include "core/algorithms/cfd/enums.h" @@ -36,7 +37,8 @@ class CFDAlgorithmTest : public ::testing::Test { {kCfdMinimumSupport, minsup}, {kCfdMinimumConfidence, minconf}, {kCfdMaximumLhs, max_lhs}, - {kCfdSubstrategy, algos::cfd::Substrategy::_from_string(substrategy)}, + {kCfdSubstrategy, + magic_enum::enum_cast(substrategy).value()}, {kCfdTuplesNumber, tuples_number}, {kCfdColumnsNumber, columns_number}}; return algos::CreateAndLoadAlgorithm(params); @@ -44,7 +46,7 @@ class CFDAlgorithmTest : public ::testing::Test { }; TEST_F(CFDAlgorithmTest, CfdRelationDataStringFormatTest) { - auto algorithm = CreateAlgorithmInstance(kTennis, 2, 0.85, "dfs", 3, 4, 5); + auto algorithm = CreateAlgorithmInstance(kTennis, 2, 0.85, "kDfs", 3, 4, 5); algorithm->Execute(); std::string expected_data = "outlook temp humidity windy\nsunny hot high false\nsunny hot high true\n"; @@ -53,7 +55,7 @@ TEST_F(CFDAlgorithmTest, CfdRelationDataStringFormatTest) { } TEST_F(CFDAlgorithmTest, CfdRelationDataPartialStringFormatTest) { - auto algorithm = CreateAlgorithmInstance(kTennis, 8, 0.85, "dfs", 3); + auto algorithm = CreateAlgorithmInstance(kTennis, 8, 0.85, "kDfs", 3); algorithm->Execute(); std::vector tids = {0, 2, 4, 6}; std::string expected_data = @@ -64,7 +66,7 @@ TEST_F(CFDAlgorithmTest, CfdRelationDataPartialStringFormatTest) { } TEST_F(CFDAlgorithmTest, FullTennisDataset) { - auto algorithm = CreateAlgorithmInstance(kTennis, 8, 0.85, "dfs", 3); + auto algorithm = CreateAlgorithmInstance(kTennis, 8, 0.85, "kDfs", 3); algorithm->Execute(); std::set actual_cfds; for (auto const& cfd : algorithm->GetItemsetCfds()) { @@ -85,13 +87,13 @@ TEST_F(CFDAlgorithmTest, FullTennisDataset) { "(windy, humidity, outlook) => play"}; CheckCfdSetsEquality(actual_cfds, expected_cfds); - algorithm = CreateAlgorithmInstance(kTennis, 8, 0.85, "bfs", 3); + algorithm = CreateAlgorithmInstance(kTennis, 8, 0.85, "kBfs", 3); algorithm->Execute(); CheckCfdSetsEquality(actual_cfds, expected_cfds); } TEST_F(CFDAlgorithmTest, PartialMushroomDataset) { - auto algorithm = CreateAlgorithmInstance(kMushroom, 4, 0.9, "dfs", 4, 4, 50); + auto algorithm = CreateAlgorithmInstance(kMushroom, 4, 0.9, "kDfs", 4, 4, 50); algorithm->Execute(); std::set actual_cfds; for (auto const& cfd : algorithm->GetItemsetCfds()) { diff --git a/src/tests/unit/test_dc_structures.cpp b/src/tests/unit/test_dc_structures.cpp index 823f1a0ccf..057c3ead2c 100644 --- a/src/tests/unit/test_dc_structures.cpp +++ b/src/tests/unit/test_dc_structures.cpp @@ -229,9 +229,9 @@ TEST(Predicate, PredicateCreatesCorrectly) { PredicateProvider pred_provider; Column const *first = col_data[0].GetColumn(), *second = col_data[1].GetColumn(); - ColumnOperand t_a(first, ColumnOperandTuple::t); - ColumnOperand s_a(first, ColumnOperandTuple::s); - ColumnOperand s_b(second, ColumnOperandTuple::s); + ColumnOperand t_a(first, ColumnOperandTuple::kT); + ColumnOperand s_a(first, ColumnOperandTuple::kS); + ColumnOperand s_b(second, ColumnOperandTuple::kS); PredicatePtr t_a_less_s_b = pred_provider.GetPredicate(Operator(OperatorType::kLess), t_a, s_b); diff --git a/src/tests/unit/test_dc_structures_correct_results.h b/src/tests/unit/test_dc_structures_correct_results.h index 5ba6d83ba3..547a325566 100644 --- a/src/tests/unit/test_dc_structures_correct_results.h +++ b/src/tests/unit/test_dc_structures_correct_results.h @@ -285,11 +285,14 @@ std::vector expected_denial_constraints = { "¬{ t.A < s.D ∧ t.C >= s.C }", "¬{ t.A < s.D ∧ t.D >= s.D }", "¬{ t.A < s.D ∧ t.E <= s.E ∧ t.F == s.F }", - "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.A != s.D ∧ t.C >= s.C ∧ t.D != s.D ∧ t.G != s.G }", + "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.A != s.D ∧ t.C >= s.C ∧ t.D != s.D ∧ t.G != " + "s.G }", "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.A > s.D ∧ t.D != s.D ∧ t.G != s.G }", - "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.A >= s.D ∧ t.B >= s.B ∧ t.D != s.D ∧ t.G != s.G }", + "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.A >= s.D ∧ t.B >= s.B ∧ t.D != s.D ∧ t.G != " + "s.G }", "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.A >= s.D ∧ t.D != s.D ∧ t.F != s.F }", - "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.B >= s.B ∧ t.C >= s.C ∧ t.D != s.D ∧ t.G != s.G }", + "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.B >= s.B ∧ t.C >= s.C ∧ t.D != s.D ∧ t.G != " + "s.G }", "¬{ t.A <= s.A ∧ t.A != s.C ∧ t.C >= s.C ∧ t.D != s.D ∧ t.F != s.F }", "¬{ t.A <= s.A ∧ t.A != s.D ∧ t.B <= s.B ∧ t.C != s.D ∧ t.G != s.G }", "¬{ t.A <= s.A ∧ t.A != s.D ∧ t.B <= s.B ∧ t.C >= s.C }", diff --git a/src/tests/unit/test_des.cpp b/src/tests/unit/test_des.cpp index 91c910790d..75bf1303d1 100644 --- a/src/tests/unit/test_des.cpp +++ b/src/tests/unit/test_des.cpp @@ -39,7 +39,7 @@ class DESTest : public ::testing::Test { TEST_F(DESTest, LaunchTest1) { auto algorithm = CreateAlgorithmInstance(kAbalone, 0.0, 0.0, 100u, 100u, 0.9, 0.5, - algos::des::DifferentialStrategy::rand1Bin); + algos::des::DifferentialStrategy::kRand1Bin); algorithm->Execute(); auto result = ExtractFitnessValues(algorithm->GetNARVector()); std::vector expected = {"0.609963", "0.518598", "0.514174", "0.497616", "0.483237", @@ -52,7 +52,7 @@ TEST_F(DESTest, LaunchTest1) { TEST_F(DESTest, LaunchTest2) { auto algorithm = CreateAlgorithmInstance(kAbalone, 0.2, 0.6, 200u, 300u, 0.9, 0.5, - algos::des::DifferentialStrategy::rand1Bin); + algos::des::DifferentialStrategy::kRand1Bin); algorithm->Execute(); auto result = ExtractFitnessValues(algorithm->GetNARVector()); std::vector expected = {"0.598929", "0.587854", "0.566134", "0.524618", diff --git a/src/tests/unit/test_metric_verifier.cpp b/src/tests/unit/test_metric_verifier.cpp index 16d8e569a5..baf61f5421 100644 --- a/src/tests/unit/test_metric_verifier.cpp +++ b/src/tests/unit/test_metric_verifier.cpp @@ -23,7 +23,7 @@ struct MetricVerifyingParams { MetricVerifyingParams(CSVConfig const& csv_config, Metric metric, long double const min_parameter, std::vector lhs_indices, std::vector rhs_indices, - MetricAlgo algo = MetricAlgo::brute, + MetricAlgo algo = MetricAlgo::kBrute, bool const dist_from_null_is_infinity = false, bool const expected = true, unsigned const q = 2) : params({{onam::kCsvConfig, csv_config}, @@ -45,7 +45,7 @@ struct HighlightTestParams { HighlightTestParams(CSVConfig const& csv_config, std::vector>&& highlight_distances, Metric metric, std::vector lhs_indices, - std::vector rhs_indices, MetricAlgo algo = MetricAlgo::brute, + std::vector rhs_indices, MetricAlgo algo = MetricAlgo::kBrute, bool const dist_from_null_is_infinity = false, unsigned const q = 2) : params({{onam::kCsvConfig, csv_config}, {onam::kParameter, (long double)0}, @@ -127,43 +127,44 @@ TEST_P(TestHighlights, DefaultTest) { // Assumes that highlights are sorted by INSTANTIATE_TEST_SUITE_P( MetricVerifierTestSuite, TestMetricVerifying, ::testing::Values( - MetricVerifyingParams(kTestLong, Metric::euclidean, 2, {0, 1}, {2}), - MetricVerifyingParams(kTestLong, Metric::euclidean, 1, {0}, {1}), - MetricVerifyingParams(kTestLong, Metric::euclidean, 4, {1}, {0}), - MetricVerifyingParams(kTestLong, Metric::euclidean, 5, {0}, {2}), - MetricVerifyingParams(kTestLong, Metric::euclidean, 0, {2}, {1}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 20500, {0}, {4}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 1059, {1}, {4}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 1, {1, 0}, {4}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 4.5724231, {0}, {2}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 7.53, {0}, {3}), - MetricVerifyingParams(kTestMetric, Metric::levenshtein, 2, {0}, {5}), - MetricVerifyingParams(kTestMetric, Metric::levenshtein, 3, {1}, {5}), - MetricVerifyingParams(kTestMetric, Metric::levenshtein, 4, {0}, {6}), - MetricVerifyingParams(kTestMetric, Metric::levenshtein, 10, {0}, {6}, - MetricAlgo::brute, true, false), - MetricVerifyingParams(kTestMetric, Metric::cosine, 0.661938299, {0}, {7}, - MetricAlgo::brute, false, true, 2), - MetricVerifyingParams(kTestMetric, Metric::cosine, 0.5, {1}, {7}, MetricAlgo::brute, - false, true, 2), - MetricVerifyingParams(kTestMetric, Metric::cosine, 0.75, {1}, {6}, - MetricAlgo::brute, false, true, 2), - MetricVerifyingParams(kTestMetric, Metric::cosine, 0.0298575, {1}, {5}, - MetricAlgo::brute, false, true, 1), - MetricVerifyingParams(kTestMetric, Metric::cosine, 0.661938299, {0}, {8}, - MetricAlgo::brute, false, true, 3), - MetricVerifyingParams(kTestMetric, Metric::cosine, 0.525658351, {1}, {8}, - MetricAlgo::brute, false, true, 3), - MetricVerifyingParams(kTestLong, Metric::euclidean, 5.0990195135928, {0}, {1, 2}), - MetricVerifyingParams(kTestLong, Metric::euclidean, 5.0990195135928, {0}, {1, 2}, - MetricAlgo::calipers), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 3.081374600094, {0}, {9, 10}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 3.081374600094, {0}, {9, 10}, - MetricAlgo::calipers), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 4.5, {0}, {11, 12}), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 4.5, {0}, {12, 11}, - MetricAlgo::calipers), - MetricVerifyingParams(kTestMetric, Metric::euclidean, 6.0091679956547, {0}, + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 2, {0, 1}, {2}), + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 1, {0}, {1}), + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 4, {1}, {0}), + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 5, {0}, {2}), + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 0, {2}, {1}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 20500, {0}, {4}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 1059, {1}, {4}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 1, {1, 0}, {4}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 4.5724231, {0}, {2}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 7.53, {0}, {3}), + MetricVerifyingParams(kTestMetric, Metric::kLevenshtein, 2, {0}, {5}), + MetricVerifyingParams(kTestMetric, Metric::kLevenshtein, 3, {1}, {5}), + MetricVerifyingParams(kTestMetric, Metric::kLevenshtein, 4, {0}, {6}), + MetricVerifyingParams(kTestMetric, Metric::kLevenshtein, 10, {0}, {6}, + MetricAlgo::kBrute, true, false), + MetricVerifyingParams(kTestMetric, Metric::kCosine, 0.661938299, {0}, {7}, + MetricAlgo::kBrute, false, true, 2), + MetricVerifyingParams(kTestMetric, Metric::kCosine, 0.5, {1}, {7}, + MetricAlgo::kBrute, false, true, 2), + MetricVerifyingParams(kTestMetric, Metric::kCosine, 0.75, {1}, {6}, + MetricAlgo::kBrute, false, true, 2), + MetricVerifyingParams(kTestMetric, Metric::kCosine, 0.0298575, {1}, {5}, + MetricAlgo::kBrute, false, true, 1), + MetricVerifyingParams(kTestMetric, Metric::kCosine, 0.661938299, {0}, {8}, + MetricAlgo::kBrute, false, true, 3), + MetricVerifyingParams(kTestMetric, Metric::kCosine, 0.525658351, {1}, {8}, + MetricAlgo::kBrute, false, true, 3), + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 5.0990195135928, {0}, {1, 2}), + MetricVerifyingParams(kTestLong, Metric::kEuclidean, 5.0990195135928, {0}, {1, 2}, + MetricAlgo::kCalipers), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 3.081374600094, {0}, + {9, 10}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 3.081374600094, {0}, {9, 10}, + MetricAlgo::kCalipers), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 4.5, {0}, {11, 12}), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 4.5, {0}, {12, 11}, + MetricAlgo::kCalipers), + MetricVerifyingParams(kTestMetric, Metric::kEuclidean, 6.0091679956547, {0}, {13, 14, 15}))); constexpr long double kInf = std::numeric_limits::infinity(); @@ -174,46 +175,48 @@ INSTANTIATE_TEST_SUITE_P( HighlightTestParams(kTestMetric, {{125, 125, 110, 79, 78, 68}, {20500, 20500, 20000, 19997, 19991, 18900}}, - Metric::euclidean, {0}, {4}), + Metric::kEuclidean, {0}, {4}), HighlightTestParams(kTestMetric, {{4.572423, 4.572423, 4.217, 3.663899, 3.217, 3.21}, {4.0331, 4.0331, 3.1101, 3.03, 2.3311, 2.3101}}, - Metric::euclidean, {0}, {2}), - HighlightTestParams(kTestMetric, {{3.9, 3.9, 2.07, 0, 0}}, Metric::euclidean, {16}, + Metric::kEuclidean, {0}, {2}), + HighlightTestParams(kTestMetric, {{3.9, 3.9, 2.07, 0, 0}}, Metric::kEuclidean, {16}, {13}), - HighlightTestParams(kTestMetric, {{kInf, 3.9, 3.9, 2.07, 0}}, Metric::euclidean, - {16}, {13}, MetricAlgo::brute, true), + HighlightTestParams(kTestMetric, {{kInf, 3.9, 3.9, 2.07, 0}}, Metric::kEuclidean, + {16}, {13}, MetricAlgo::kBrute, true), HighlightTestParams(kTestMetric, {{2, 2, 2, 2, 2, 1}, {2, 2, 2, 2, 2, 2}}, - Metric::levenshtein, {0}, {5}), - HighlightTestParams(kTestMetric, {{4, 4, 4, 3, 3, 3}}, Metric::levenshtein, {0}, + Metric::kLevenshtein, {0}, {5}), + HighlightTestParams(kTestMetric, {{4, 4, 4, 3, 3, 3}}, Metric::kLevenshtein, {0}, {6}), HighlightTestParams(kTestMetric, {{0.661938, 0.661938, 0.661938, 0.6, 0.552786, 0.525658}}, - Metric::cosine, {0}, {7}), - HighlightTestParams(kTestMetric, {{0.5, 0.5, 0.410744}}, Metric::cosine, {1}, {7}), + Metric::kCosine, {0}, {7}), + HighlightTestParams(kTestMetric, {{0.5, 0.5, 0.410744}}, Metric::kCosine, {1}, {7}), HighlightTestParams(kTestMetric, {{0.661938, 0.661938, 0.53709, 0.525658, 0.428571, 0.316237}, {kInf, kInf, kInf, 0, 0, 0}}, - Metric::cosine, {0}, {8}, MetricAlgo::brute, true, 3), - HighlightTestParams(kTestMetric, {{0.525658, 0.525658, 0.483602}}, Metric::cosine, - {1}, {8}, MetricAlgo::brute, true, 3), + Metric::kCosine, {0}, {8}, MetricAlgo::kBrute, true, 3), + HighlightTestParams(kTestMetric, {{0.525658, 0.525658, 0.483602}}, Metric::kCosine, + {1}, {8}, MetricAlgo::kBrute, true, 3), HighlightTestParams(kTestMetric, {{4.574986, 4.574986, 2.540827, 0, 0}}, - Metric::euclidean, {16}, {13, 14, 15}), + Metric::kEuclidean, {16}, {13, 14, 15}), HighlightTestParams(kTestMetric, {{kInf, 4.574986, 4.574986, 2.540827, 0}}, - Metric::euclidean, {16}, {13, 14, 15}, MetricAlgo::brute, true), + Metric::kEuclidean, {16}, {13, 14, 15}, MetricAlgo::kBrute, + true), HighlightTestParams(kTestMetric, {{4.543006, 4.54301, 2.41814, 0, 0}}, - Metric::euclidean, {16}, {13, 14}), + Metric::kEuclidean, {16}, {13, 14}), HighlightTestParams(kTestMetric, {{kInf, 4.543006, 4.54301, 2.41814, 0}}, - Metric::euclidean, {16}, {13, 14}, MetricAlgo::brute, true), + Metric::kEuclidean, {16}, {13, 14}, MetricAlgo::kBrute, true), HighlightTestParams(kTestMetric, {{4.543006, 4.54301, 2.41814, 0, 0}}, - Metric::euclidean, {16}, {13, 14}, MetricAlgo::calipers), + Metric::kEuclidean, {16}, {13, 14}, MetricAlgo::kCalipers), HighlightTestParams(kTestMetric, {{kInf, 4.543006, 4.54301, 2.41814, 0}}, - Metric::euclidean, {16}, {13, 14}, MetricAlgo::calipers, true), + Metric::kEuclidean, {16}, {13, 14}, MetricAlgo::kCalipers, + true), HighlightTestParams(kTestMetric, {{3.08137, 3.08137, 2.43892, 2.15623, 2.15421, 1.86557}}, - Metric::euclidean, {0}, {9, 10}), + Metric::kEuclidean, {0}, {9, 10}), HighlightTestParams(kTestMetric, {{3.08137, 3.08137, 2.43892, 2.15623, 2.15421, 1.86557}}, - Metric::euclidean, {0}, {9, 10}, MetricAlgo::calipers))); + Metric::kEuclidean, {0}, {9, 10}, MetricAlgo::kCalipers))); } // namespace tests diff --git a/src/tests/unit/test_pfd_verifier.cpp b/src/tests/unit/test_pfd_verifier.cpp index e0033c5143..5160ddde20 100644 --- a/src/tests/unit/test_pfd_verifier.cpp +++ b/src/tests/unit/test_pfd_verifier.cpp @@ -53,23 +53,21 @@ TEST_P(TestPFDVerifying, DefaultTest) { INSTANTIATE_TEST_SUITE_P( PFDVerifierTestSuite, TestPFDVerifying, - ::testing::Values(PFDVerifyingParams({2}, {3}, +algos::PfdErrorMeasure::per_value, 0.0625, - 1, 1, {{0, 1}}, kTestFD), - PFDVerifyingParams({0, 1}, {4}, +algos::PfdErrorMeasure::per_value, + ::testing::Values(PFDVerifyingParams({2}, {3}, algos::PfdErrorMeasure::kPerValue, 0.0625, 1, + 1, {{0, 1}}, kTestFD), + PFDVerifyingParams({0, 1}, {4}, algos::PfdErrorMeasure::kPerValue, 0.166667, 2, 2, {{0, 1, 2}, {6, 7, 8}}, kTestFD), - PFDVerifyingParams({4}, {5}, +algos::PfdErrorMeasure::per_value, 0.3334, - 4, 4, {{0, 8}, {1, 2}, {3, 4, 5}, {9, 10, 11}}, - kTestFD), - PFDVerifyingParams({5}, {1}, +algos::PfdErrorMeasure::per_value, 0.0, 0, - 0, {}, kTestFD), - PFDVerifyingParams({2}, {3}, +algos::PfdErrorMeasure::per_tuple, 0.0834, - 1, 1, {{0, 1}}, kTestFD), - PFDVerifyingParams({0, 1}, {4}, +algos::PfdErrorMeasure::per_tuple, - 0.1667, 2, 2, {{0, 1, 2}, {6, 7, 8}}, kTestFD), - PFDVerifyingParams({4}, {5}, +algos::PfdErrorMeasure::per_tuple, 0.3334, - 4, 4, {{0, 8}, {1, 2}, {3, 4, 5}, {9, 10, 11}}, - kTestFD), - PFDVerifyingParams({5}, {1}, +algos::PfdErrorMeasure::per_tuple, 0.0, 0, - 0, {}, kTestFD))); + PFDVerifyingParams({4}, {5}, algos::PfdErrorMeasure::kPerValue, 0.3334, 4, + 4, {{0, 8}, {1, 2}, {3, 4, 5}, {9, 10, 11}}, kTestFD), + PFDVerifyingParams({5}, {1}, algos::PfdErrorMeasure::kPerValue, 0.0, 0, 0, + {}, kTestFD), + PFDVerifyingParams({2}, {3}, algos::PfdErrorMeasure::kPerTuple, 0.0834, 1, + 1, {{0, 1}}, kTestFD), + PFDVerifyingParams({0, 1}, {4}, algos::PfdErrorMeasure::kPerTuple, 0.1667, + 2, 2, {{0, 1, 2}, {6, 7, 8}}, kTestFD), + PFDVerifyingParams({4}, {5}, algos::PfdErrorMeasure::kPerTuple, 0.3334, 4, + 4, {{0, 8}, {1, 2}, {3, 4, 5}, {9, 10, 11}}, kTestFD), + PFDVerifyingParams({5}, {1}, algos::PfdErrorMeasure::kPerTuple, 0.0, 0, 0, + {}, kTestFD))); } // namespace tests diff --git a/src/tests/unit/test_pfdtane.cpp b/src/tests/unit/test_pfdtane.cpp index ac6a69e611..3114ae5621 100644 --- a/src/tests/unit/test_pfdtane.cpp +++ b/src/tests/unit/test_pfdtane.cpp @@ -64,20 +64,20 @@ TEST_P(TestPFDTaneValidation, ErrorCalculationTest) { INSTANTIATE_TEST_SUITE_P( PFDTaneTestMiningSuite, TestPFDTaneMining, ::testing::Values( - PFDTaneMiningParams(44381, 0.3, +algos::PfdErrorMeasure::per_value, kTestFD), - PFDTaneMiningParams(19266, 0.1, +algos::PfdErrorMeasure::per_value, kIris), - PFDTaneMiningParams(10695, 0.01, +algos::PfdErrorMeasure::per_value, kIris), - PFDTaneMiningParams(44088, 0.1, +algos::PfdErrorMeasure::per_value, kNeighbors10k), - PFDTaneMiningParams(41837, 0.01, +algos::PfdErrorMeasure::per_value, kNeighbors10k) + PFDTaneMiningParams(44381, 0.3, algos::PfdErrorMeasure::kPerValue, kTestFD), + PFDTaneMiningParams(19266, 0.1, algos::PfdErrorMeasure::kPerValue, kIris), + PFDTaneMiningParams(10695, 0.01, algos::PfdErrorMeasure::kPerValue, kIris), + PFDTaneMiningParams(44088, 0.1, algos::PfdErrorMeasure::kPerValue, kNeighbors10k), + PFDTaneMiningParams(41837, 0.01, algos::PfdErrorMeasure::kPerValue, kNeighbors10k) )); INSTANTIATE_TEST_SUITE_P( PFDTaneTestValidationSuite, TestPFDTaneValidation, ::testing::Values( PFDTaneValidationParams({{2, 3, 0.0625}, {4, 5, 0.333333}, {3, 2, 0.291666}, {0, 1, 0.75}, - {1, 0, 0.0}, {4, 3, 0.099999}, {1, 5, 0.416666}, {5, 1, 0.0}}, +algos::PfdErrorMeasure::per_value, kTestFD), + {1, 0, 0.0}, {4, 3, 0.099999}, {1, 5, 0.416666}, {5, 1, 0.0}}, algos::PfdErrorMeasure::kPerValue, kTestFD), PFDTaneValidationParams({{2, 3, 0.083333}, {4, 5, 0.333333}, {3, 2, 0.5}, {0, 1, 0.75}, - {1, 0, 0.0}, {4, 3, 0.083333}, {1, 5, 0.416666}, {5, 1, 0.0}}, +algos::PfdErrorMeasure::per_tuple, kTestFD) + {1, 0, 0.0}, {4, 3, 0.083333}, {1, 5, 0.416666}, {5, 1, 0.0}}, algos::PfdErrorMeasure::kPerTuple, kTestFD) )); // clang-format on diff --git a/src/tests/unit/test_set_based_verifier.cpp b/src/tests/unit/test_set_based_verifier.cpp index 899de61016..800954c06b 100644 --- a/src/tests/unit/test_set_based_verifier.cpp +++ b/src/tests/unit/test_set_based_verifier.cpp @@ -67,61 +67,61 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values(/* {}: Col5 -> Col1 */ SetBasedAodVerifierParams(kTestFD, /*oc_context=*/{}, /*oc_left=*/5, /*oc_right=*/1, - /*ordering=*/Ordering::ascending, + /*ordering=*/Ordering::kAscending, /*ofd_context=*/{5}, /*ofd_right=*/1, /*removal_set=*/{}), /* {}: Col5 -> Col2 */ SetBasedAodVerifierParams(kTestFD, /*oc_context=*/{}, /*oc_left=*/5, /*oc_right=*/2, - /*ordering=*/Ordering::ascending, + /*ordering=*/Ordering::kAscending, /*ofd_context=*/{5}, /*ofd_right=*/2, /*removal_set=*/{2, 5, 8}), /* {Col3}: Col4 -> Col1 */ SetBasedAodVerifierParams(kTestFD, /*oc_context=*/{3}, /*oc_left=*/4, /*oc_right=*/1, - /*ordering=*/Ordering::ascending, + /*ordering=*/Ordering::kAscending, /*ofd_context=*/{3, 4}, /*ofd_right=*/1, /*removal_set=*/{}), /* {Col3}: Col2<= ~ Col4<=, {Col2,Col3}: [] -> Col4 */ SetBasedAodVerifierParams(kTestFD, /*oc_context=*/{3}, /*oc_left=*/2, /*oc_right=*/4, - /*ordering=*/Ordering::ascending, + /*ordering=*/Ordering::kAscending, /*ofd_context=*/{2, 3}, /*ofd_right=*/4, /*removal_set=*/{}), /* {Col1}: Col4>= ~ Col3<=, {}: [] -> Col0 */ SetBasedAodVerifierParams(kTestFD, /*oc_context=*/{1}, /*oc_left=*/4, /*oc_right=*/3, - /*ordering=*/Ordering::descending, + /*ordering=*/Ordering::kDescending, /*ofd_context=*/{}, /*ofd_right=*/0, /*removal_set=*/{}), /* {Col1}: Col4>= ~ Col3<=, {Col1}: [] -> Col5 */ SetBasedAodVerifierParams(kTestFD, /*oc_context=*/{1}, /*oc_left=*/4, /*oc_right=*/3, - /*ordering=*/Ordering::descending, + /*ordering=*/Ordering::kDescending, /*ofd_context=*/{1}, /*ofd_right=*/5, /*removal_set=*/{0, 1, 5, 8, 11}), /* {}: F>= ~ E<=, {B,C,D,E}: [] -> A */ SetBasedAodVerifierParams(kBernoulliRelation, /*oc_context=*/{}, /*oc_left=*/5, /*oc_right=*/4, - /*ordering=*/Ordering::descending, + /*ordering=*/Ordering::kDescending, /*ofd_context=*/{2, 3, 4, 5}, /*ofd_right=*/1, /*removal_set=*/{}), /* {A}: D<= ~ E<=, {A}: [] -> F */ SetBasedAodVerifierParams(kBernoulliRelation, /*oc_context=*/{0}, /*oc_left=*/3, /*oc_right=*/4, - /*ordering=*/Ordering::ascending, + /*ordering=*/Ordering::kAscending, /*ofd_context=*/{0}, /*ofd_right=*/5, /*removal_set=*/{3}), /* {A}: D>= ~ E<=, {A}: [] -> E */ SetBasedAodVerifierParams(kBernoulliRelation, /*oc_context=*/{0}, /*oc_left=*/3, /*oc_right=*/4, - /*ordering=*/Ordering::descending, + /*ordering=*/Ordering::kDescending, /*ofd_context=*/{0}, /*ofd_right=*/4, /*removal_set=*/{4}), /* {}: C>= ~ B<=, {D}: [] -> C */ SetBasedAodVerifierParams(kBernoulliRelation, /*oc_context=*/{}, /*oc_left=*/2, /*oc_right=*/1, - /*ordering=*/Ordering::descending, + /*ordering=*/Ordering::kDescending, /*ofd_context=*/{3}, /*ofd_right=*/2, /*removal_set=*/{0, 4, 5}))); diff --git a/src/tests/unit/test_tane_afd_measures.cpp b/src/tests/unit/test_tane_afd_measures.cpp index 78eff6555b..b90d160af4 100644 --- a/src/tests/unit/test_tane_afd_measures.cpp +++ b/src/tests/unit/test_tane_afd_measures.cpp @@ -80,16 +80,16 @@ TEST_P(TestTaneAfdMeasuresValidation, ErrorCalculationTest) { auto const& rhs = relation->GetColumnData(rhs_id).GetPositionListIndex(); config::ErrorType error; switch (p.error_measure) { - case +algos::AfdErrorMeasure::pdep: + case algos::AfdErrorMeasure::kPdep: error = algos::CalculatePdepMeasure(lhs, lhs->Intersect(rhs).get()); break; - case +algos::AfdErrorMeasure::tau: + case algos::AfdErrorMeasure::kTau: error = algos::CalculateTauMeasure(lhs, rhs, lhs->Intersect(rhs).get()); break; - case +algos::AfdErrorMeasure::mu_plus: + case algos::AfdErrorMeasure::kMuPlus: error = algos::CalculateMuPlusMeasure(lhs, rhs, lhs->Intersect(rhs).get()); break; - case +algos::AfdErrorMeasure::rho: + case algos::AfdErrorMeasure::kRho: error = algos::CalculateRhoMeasure(lhs, lhs->Intersect(rhs).get()); break; default: @@ -131,7 +131,7 @@ INSTANTIATE_TEST_SUITE_P(PdepSelfTaneValidationSuite, TestTanePdepSelfValidation INSTANTIATE_TEST_SUITE_P( AfdMeasuresTaneValidationSuite, TestTaneAfdMeasuresValidation, ::testing::Values( - TaneValidationParams(+algos::AfdErrorMeasure::pdep, + TaneValidationParams(algos::AfdErrorMeasure::kPdep, {{0, 1, 0.25}, {0, 2, 0.13888888888888887}, {0, 3, 0.3749999999999999}, @@ -163,7 +163,7 @@ INSTANTIATE_TEST_SUITE_P( {5, 3, 1.0}, {5, 4, 1.0}}, kTestFD), - TaneValidationParams(+algos::AfdErrorMeasure::pdep, + TaneValidationParams(algos::AfdErrorMeasure::kPdep, {{0, 1, 0.32647619047619053}, {0, 2, 0.29765079365079367}, {0, 3, 0.35943386243386244}, {0, 4, 0.6805925925925925}, {1, 0, 0.21734432234432235}, {1, 2, 0.20246682946682948}, @@ -175,7 +175,7 @@ INSTANTIATE_TEST_SUITE_P( {4, 0, 0.07680000000000001}, {4, 1, 0.10613333333333334}, {4, 2, 0.10933333333333332}, {4, 3, 0.21973333333333336}}, kIris), - TaneValidationParams(+algos::AfdErrorMeasure::tau, + TaneValidationParams(algos::AfdErrorMeasure::kTau, {{0, 1, 0.0}, {0, 2, -3.2232281360085186e-17}, {0, 3, -8.881784197001253e-17}, @@ -207,7 +207,7 @@ INSTANTIATE_TEST_SUITE_P( {5, 3, 1.0}, {5, 4, 1.0}}, kTestFD), - TaneValidationParams(+algos::AfdErrorMeasure::tau, + TaneValidationParams(algos::AfdErrorMeasure::kTau, {{0, 1, 0.26903889087952376}, {0, 2, 0.2692658308121177}, {0, 3, 0.3060122257685817}, {0, 4, 0.5208888888888887}, {1, 0, 0.18473366910866912}, {1, 2, 0.1702350718118775}, @@ -219,7 +219,7 @@ INSTANTIATE_TEST_SUITE_P( {4, 0, 0.038333333333333344}, {4, 1, 0.029905460158209544}, {4, 2, 0.07333764912605197}, {4, 3, 0.15466101694915257}}, kIris), - TaneValidationParams(+algos::AfdErrorMeasure::mu_plus, + TaneValidationParams(algos::AfdErrorMeasure::kMuPlus, {{0, 1, 0.0}, {0, 2, 0.0}, {0, 3, 0.0}, @@ -251,7 +251,7 @@ INSTANTIATE_TEST_SUITE_P( {5, 3, 1.0}, {5, 4, 1.0}}, kTestFD), - TaneValidationParams(+algos::AfdErrorMeasure::mu_plus, + TaneValidationParams(algos::AfdErrorMeasure::kMuPlus, {{0, 1, 0.052928649922165616}, {0, 2, 0.053222685139178605}, {0, 3, 0.10083323164798841}, {0, 4, 0.37923864734299506}, {1, 0, 0.0435064306865488}, {1, 2, 0.026496265354092552}, @@ -263,7 +263,7 @@ INSTANTIATE_TEST_SUITE_P( {4, 0, 0.025249433106575903}, {4, 1, 0.016706894990293986}, {4, 2, 0.060729998093753235}, {4, 3, 0.14315980629539937}}, kIris), - TaneValidationParams(+algos::AfdErrorMeasure::rho, + TaneValidationParams(algos::AfdErrorMeasure::kRho, {{0, 1, 0.25}, {0, 2, 0.125}, {0, 3, 0.25}, @@ -295,7 +295,7 @@ INSTANTIATE_TEST_SUITE_P( {5, 3, 1.0}, {5, 4, 1.0}}, kTestFD), - TaneValidationParams(+algos::AfdErrorMeasure::rho, + TaneValidationParams(algos::AfdErrorMeasure::kRho, {{0, 1, 0.3017241379310345}, {0, 2, 0.2845528455284553}, {0, 3, 0.3181818181818182}, @@ -321,25 +321,25 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( AfdMeasuresTaneMiningSuite, TestTaneAfdMeasuresMining, ::testing::Values( - TaneMiningParams(3325, 0.3, +algos::AfdErrorMeasure::pdep, kTestFD), - TaneMiningParams(19266, 0.174, +algos::AfdErrorMeasure::pdep, kIris), - TaneMiningParams(18528, 0.1, +algos::AfdErrorMeasure::pdep, kIris), - TaneMiningParams(31178, 0.15, +algos::AfdErrorMeasure::pdep, kNeighbors10k), - TaneMiningParams(1182, 0.21, +algos::AfdErrorMeasure::pdep, kNeighbors10k), - TaneMiningParams(33180, 0.01, +algos::AfdErrorMeasure::tau, kTestFD), - TaneMiningParams(11680, 0.1, +algos::AfdErrorMeasure::tau, kIris), - TaneMiningParams(60896, 0.01, +algos::AfdErrorMeasure::tau, kIris), - TaneMiningParams(52638, 0.1, +algos::AfdErrorMeasure::tau, kNeighbors10k), - TaneMiningParams(44991, 0.01, +algos::AfdErrorMeasure::tau, kNeighbors10k), - TaneMiningParams(33180, 0.01, +algos::AfdErrorMeasure::mu_plus, kTestFD), - TaneMiningParams(60841, 0.1, +algos::AfdErrorMeasure::mu_plus, kIris), - TaneMiningParams(60896, 0.01, +algos::AfdErrorMeasure::mu_plus, kIris), - TaneMiningParams(12185, 0.1, +algos::AfdErrorMeasure::mu_plus, kNeighbors10k), - TaneMiningParams(12185, 0.01, +algos::AfdErrorMeasure::mu_plus, kNeighbors10k), - TaneMiningParams(33180, 0.01, +algos::AfdErrorMeasure::rho, kTestFD), - TaneMiningParams(11873, 0.1, +algos::AfdErrorMeasure::rho, kIris), - TaneMiningParams(47878, 0.01, +algos::AfdErrorMeasure::rho, kIris), - TaneMiningParams(52638, 0.1, +algos::AfdErrorMeasure::rho, kNeighbors10k), - TaneMiningParams(52638, 0.01, +algos::AfdErrorMeasure::rho, kNeighbors10k))); + TaneMiningParams(3325, 0.3, algos::AfdErrorMeasure::kPdep, kTestFD), + TaneMiningParams(19266, 0.174, algos::AfdErrorMeasure::kPdep, kIris), + TaneMiningParams(18528, 0.1, algos::AfdErrorMeasure::kPdep, kIris), + TaneMiningParams(31178, 0.15, algos::AfdErrorMeasure::kPdep, kNeighbors10k), + TaneMiningParams(1182, 0.21, algos::AfdErrorMeasure::kPdep, kNeighbors10k), + TaneMiningParams(33180, 0.01, algos::AfdErrorMeasure::kTau, kTestFD), + TaneMiningParams(11680, 0.1, algos::AfdErrorMeasure::kTau, kIris), + TaneMiningParams(60896, 0.01, algos::AfdErrorMeasure::kTau, kIris), + TaneMiningParams(52638, 0.1, algos::AfdErrorMeasure::kTau, kNeighbors10k), + TaneMiningParams(44991, 0.01, algos::AfdErrorMeasure::kTau, kNeighbors10k), + TaneMiningParams(33180, 0.01, algos::AfdErrorMeasure::kMuPlus, kTestFD), + TaneMiningParams(60841, 0.1, algos::AfdErrorMeasure::kMuPlus, kIris), + TaneMiningParams(60896, 0.01, algos::AfdErrorMeasure::kMuPlus, kIris), + TaneMiningParams(12185, 0.1, algos::AfdErrorMeasure::kMuPlus, kNeighbors10k), + TaneMiningParams(12185, 0.01, algos::AfdErrorMeasure::kMuPlus, kNeighbors10k), + TaneMiningParams(33180, 0.01, algos::AfdErrorMeasure::kRho, kTestFD), + TaneMiningParams(11873, 0.1, algos::AfdErrorMeasure::kRho, kIris), + TaneMiningParams(47878, 0.01, algos::AfdErrorMeasure::kRho, kIris), + TaneMiningParams(52638, 0.1, algos::AfdErrorMeasure::kRho, kNeighbors10k), + TaneMiningParams(52638, 0.01, algos::AfdErrorMeasure::kRho, kNeighbors10k))); } // namespace tests