diff --git a/Nef_3/include/CGAL/Nef_3/Binary_operation.h b/Nef_3/include/CGAL/Nef_3/Binary_operation.h index bcfe27e3591..8de14ea4101 100644 --- a/Nef_3/include/CGAL/Nef_3/Binary_operation.h +++ b/Nef_3/include/CGAL/Nef_3/Binary_operation.h @@ -319,6 +319,9 @@ class Binary_operation : public CGAL::SNC_decorator { CGAL_NEF_TRACEN("=> for all v0 in snc1, qualify v0 with respect snc2"); // int i=2; Association A; + A.reserve(snc1.number_of_shalfedges() + snc1.number_of_shalfloops() + + snc2.number_of_shalfedges() + snc2.number_of_shalfloops()); + SHalfedge_const_iterator sei; CGAL_forall_shalfedges(sei, snc1) A.initialize_hash(sei); diff --git a/Nef_3/include/CGAL/Nef_3/ID_support_handler.h b/Nef_3/include/CGAL/Nef_3/ID_support_handler.h index 53a946a0fd6..13235bc9415 100644 --- a/Nef_3/include/CGAL/Nef_3/ID_support_handler.h +++ b/Nef_3/include/CGAL/Nef_3/ID_support_handler.h @@ -56,11 +56,27 @@ class ID_support_handler { } }; std::unordered_map f2m; - std::map hash; + std::unordered_map hash; public: ID_support_handler() {} + void reserve(std::size_t n) { + hash.reserve(n); + } + + /* + The method get_hash implements a + two-pass union find algorithm + __ __ _______ + / \ / \ / _____\ + _|__|__|__|_ _/__/__/__|_ + | | v | v | | | | | v | + | O O O O | => | O O O O | + |____|__^____| |____________| + | | root + \_/ + */ int get_hash(int i) { int root(i); while(hash[root] != root) @@ -78,12 +94,13 @@ class ID_support_handler { hash[get_hash(i)] = parent; } + void initialize_hash(int i) { + hash[i] = i; + } + template void initialize_hash(Handle h) { - hash[h->get_index()] = h->get_index(); - } - void initialize_hash(int i) { - hash[i] = i; + initialize_hash(h->get_index()); } void hash_facet_pair(SVertex_handle sv, diff --git a/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h b/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h index d66bc30ac18..50074dc6ce7 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h @@ -30,6 +30,7 @@ #include #include #include +#include #undef CGAL_NEF_DEBUG #define CGAL_NEF_DEBUG 43 @@ -1308,8 +1309,9 @@ public: // O0.print(); link_shalfedges_to_facet_cycles(); - std::map hash; - CGAL::Unique_hash_map done(false, this->sncp()->number_of_shalfedges()); + std::size_t num_shalfedges = this->sncp()->number_of_shalfedges(); + std::unordered_map hash(num_shalfedges); + CGAL::Unique_hash_map done(false, num_shalfedges); SHalfedge_iterator sei; CGAL_forall_shalfedges(sei, *this->sncp()) { diff --git a/Nef_S2/include/CGAL/Nef_S2/ID_support_handler.h b/Nef_S2/include/CGAL/Nef_S2/ID_support_handler.h index 9a9b3bcfcd1..c9033b607f2 100644 --- a/Nef_S2/include/CGAL/Nef_S2/ID_support_handler.h +++ b/Nef_S2/include/CGAL/Nef_S2/ID_support_handler.h @@ -38,6 +38,8 @@ class ID_support_handler { public: ID_support_handler() {} + void reserve(std::size_t) {} + int get_hash(int) { return 0; } template void initialize_hash(Handle /*h*/) {} void initialize_hash(int /*i*/) {}