diff --git a/CMakeLists.txt b/CMakeLists.txt index 704cb0c..2384cd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,20 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +# --------------------------------- +# Flags de compilação (warnings + otimização) +# --------------------------------- +if (MSVC) + # Warnings fortes no MSVC + set(COMMON_FLAGS /W4 /permissive- /O2) +else() + # GCC/Clang: warnings + performance + set(COMMON_FLAGS -Wall -Wextra -Wpedantic -O3 -march=native) +endif() + +# Aplica a todos os targets +add_compile_options(${COMMON_FLAGS}) + # ------------------------------- # Biblioteca mlcpppy # ------------------------------- @@ -16,7 +30,7 @@ add_library(mlcpppy SHARED ${MLCPP_SOURCES}) target_include_directories(mlcpppy PUBLIC ${PROJECT_SOURCE_DIR}/include) # ------------------------------- -# Executável de exemplo +# Executáveis de exemplo # ------------------------------- add_executable(example_main examples/main.cpp) add_executable(example_instance examples/atributes_usage.cpp) diff --git a/examples/atributes_usage.cpp b/examples/atributes_usage.cpp index c45f117..9a2680a 100644 --- a/examples/atributes_usage.cpp +++ b/examples/atributes_usage.cpp @@ -2,7 +2,7 @@ #include "mlcpppy/instances/instances.h" -int main(int argc, char const *argv[]) { +int main() { // Exemplo de uso da classe atribute, instances e instance Instance a(Attribute(1), Attribute(2.5), Attribute("Pedro")); Instance b(Attribute(1), Attribute(2.5), Attribute("Pedro")); diff --git a/examples/example_binary_tree.cpp b/examples/example_binary_tree.cpp index 0162f56..5dfad52 100644 --- a/examples/example_binary_tree.cpp +++ b/examples/example_binary_tree.cpp @@ -1,6 +1,6 @@ #include "mlcpppy/data_structures/binary_tree.h" -int main(int argc, char const* argv[]) { +int main() { BinaryTree* binary_tree = new BinaryTree(); // Isso deixa desbalanceado // 20, 8, 22, 4, 12, 10, 14 diff --git a/include/mlcpppy/classifiers/neighbors/kdtree.h b/include/mlcpppy/classifiers/neighbors/kdtree.h index 004f1f7..154aa77 100644 --- a/include/mlcpppy/classifiers/neighbors/kdtree.h +++ b/include/mlcpppy/classifiers/neighbors/kdtree.h @@ -33,24 +33,17 @@ class KDTree : public NearestNeighbor { Point point_; int depth_; - explicit Node() {} - explicit Node(Point point, Node* left, Node* right) - : point_(point), left_(left), right_(right) {} - explicit Node(Point point, Node* left, Node* right, - int depth) - : point_(point), - left_(left), - right_(right), - depth_(depth) {} - explicit Node(Point point) : point_(point) { - this->left_ = nullptr; - this->right_ = nullptr; - } - explicit Node(Point point, int depth) - : point_(point), depth_(depth) { - this->left_ = nullptr; - this->right_ = nullptr; - } + explicit Node() {} + explicit Node(Node* left, Node* right, Point point) : left_(left), right_(right), point_(point) {} + explicit Node(Node* left, Node* right, Point point, int depth) : left_(left), right_(right), point_(point), depth_(depth) {} + explicit Node(Point point) : point_(point) { + this->left_ = nullptr; + this->right_ = nullptr; + } + explicit Node(Point point, int depth) : point_(point), depth_(depth) { + this->left_ = nullptr; + this->right_ = nullptr; + } ~Node() { delete left_; @@ -59,7 +52,7 @@ class KDTree : public NearestNeighbor { }; Node* root_; - int K_; + size_t K_; std::priority_queue> bests_; Node* Build(std::vector> points, int depth) { @@ -80,10 +73,15 @@ class KDTree : public NearestNeighbor { std::vector> points_right( points.begin() + median + 1, points.end()); - return new Node(points.at(median), - Build(points_left, depth + 1), - Build(points_right, depth + 1), depth); - } + + return new Node( + Build(points_left, depth + 1), + Build(points_right, depth + 1), + points.at(median), + depth + ); + } + Node* NearestNeighbor(Node* root, Point& target, int depth) { if (root == nullptr) return nullptr; @@ -251,7 +249,7 @@ class KDTree : public NearestNeighbor { return; } - int initial_size = points.at(0).size(); + size_t initial_size = points.at(0).size(); for (auto& point : points) { if (point.data().empty()) { diff --git a/include/mlcpppy/classifiers/neighbors/point.h b/include/mlcpppy/classifiers/neighbors/point.h index 27ffb8e..2085062 100644 --- a/include/mlcpppy/classifiers/neighbors/point.h +++ b/include/mlcpppy/classifiers/neighbors/point.h @@ -40,7 +40,9 @@ class Point { std::copy(list.begin(), list.end(), data_.begin()); } const std::array &data() const { return data_; } - const size_t size() const { return data_.size(); } + size_t size() const { + return data_.size(); + } }; #endif // POINT_H \ No newline at end of file