From 52e0166b5f25118aa4a4d7b1d9260013a3a094c0 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 3 Apr 2022 17:10:18 +0100 Subject: [PATCH 1/6] Use std::unordered map instead of std::map --- Nef_3/include/CGAL/Nef_3/Binary_operation.h | 3 +++ Nef_3/include/CGAL/Nef_3/ID_support_handler.h | 15 ++++++++++----- Nef_3/include/CGAL/Nef_3/SNC_external_structure.h | 6 ++++-- 3 files changed, 17 insertions(+), 7 deletions(-) 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..43e70d77d63 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,15 @@ 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); + } + int get_hash(int i) { int root(i); while(hash[root] != root) @@ -78,12 +82,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..e995a7ea80c 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h @@ -1308,8 +1308,10 @@ 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; + hash.reserve(num_shalfedges); + CGAL::Unique_hash_map done(false, num_shalfedges); SHalfedge_iterator sei; CGAL_forall_shalfedges(sei, *this->sncp()) { From 4f9bb6629217e392ddd274421ceef963226b22ef Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 3 Apr 2022 23:30:42 +0100 Subject: [PATCH 2/6] Use bucket_count constructor in std::unordered_map --- Nef_3/include/CGAL/Nef_3/SNC_external_structure.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 e995a7ea80c..89e5d17b04d 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_external_structure.h @@ -1309,8 +1309,7 @@ public: link_shalfedges_to_facet_cycles(); std::size_t num_shalfedges = this->sncp()->number_of_shalfedges(); - std::unordered_map hash; - hash.reserve(num_shalfedges); + std::unordered_map hash(num_shalfedges); CGAL::Unique_hash_map done(false, num_shalfedges); SHalfedge_iterator sei; From 104aca6295728c8e488ae4a37f9c3fa783ee97dd Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Mon, 4 Apr 2022 17:38:41 +0100 Subject: [PATCH 3/6] Add a comment to the get_hash method --- Nef_3/include/CGAL/Nef_3/ID_support_handler.h | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 43e70d77d63..a6dd108b221 100644 --- a/Nef_3/include/CGAL/Nef_3/ID_support_handler.h +++ b/Nef_3/include/CGAL/Nef_3/ID_support_handler.h @@ -65,6 +65,16 @@ class ID_support_handler { 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) From 2a5fcdcfb13352d15d9a59ab1b0d2ee78562fa5a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 13 Apr 2022 12:59:21 +0100 Subject: [PATCH 4/6] Add reserve() in generic code and change comment to avoid warning --- Nef_3/include/CGAL/Nef_3/ID_support_handler.h | 22 ++++++++++--------- .../include/CGAL/Nef_S2/ID_support_handler.h | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) 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 a6dd108b221..13235bc9415 100644 --- a/Nef_3/include/CGAL/Nef_3/ID_support_handler.h +++ b/Nef_3/include/CGAL/Nef_3/ID_support_handler.h @@ -65,16 +65,18 @@ class ID_support_handler { 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 - // \_/ + /* + 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) 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..c8523a2ee7d 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 n) {} + int get_hash(int) { return 0; } template void initialize_hash(Handle /*h*/) {} void initialize_hash(int /*i*/) {} From 95675222972aabef55949c4934923e77cbdffbf6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 19 Apr 2022 17:02:20 +0100 Subject: [PATCH 5/6] Include header --- Nef_3/include/CGAL/Nef_3/SNC_external_structure.h | 1 + 1 file changed, 1 insertion(+) 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 89e5d17b04d..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 From 8770c7a0cdebea0f42bdf92bacdd277e704b0c7d Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Tue, 10 May 2022 12:06:32 +0100 Subject: [PATCH 6/6] Update Nef_S2/include/CGAL/Nef_S2/ID_support_handler.h Co-authored-by: Sebastien Loriot --- Nef_S2/include/CGAL/Nef_S2/ID_support_handler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c8523a2ee7d..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,7 +38,7 @@ class ID_support_handler { public: ID_support_handler() {} - void reserve(std::size_t n) {} + void reserve(std::size_t) {} int get_hash(int) { return 0; } template void initialize_hash(Handle /*h*/) {}