mirror of https://github.com/CGAL/cgal
Merge pull request #6471 from GilesBathgate/Nef_3-performance_stdmap-GilesBathgate
Nef_3: Performance std::map -> std::unordered_map
This commit is contained in:
commit
0e0b813736
|
|
@ -319,6 +319,9 @@ class Binary_operation : public CGAL::SNC_decorator<Map> {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -56,11 +56,27 @@ class ID_support_handler<SNC_indexed_items, Decorator> {
|
|||
}
|
||||
};
|
||||
std::unordered_map<Halffacet_pair, int, Handle_pair_hash_function> f2m;
|
||||
std::map<int, int> hash;
|
||||
std::unordered_map<int, int> 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,14 +94,15 @@ class ID_support_handler<SNC_indexed_items, Decorator> {
|
|||
hash[get_hash(i)] = parent;
|
||||
}
|
||||
|
||||
template<typename Handle>
|
||||
void initialize_hash(Handle h) {
|
||||
hash[h->get_index()] = h->get_index();
|
||||
}
|
||||
void initialize_hash(int i) {
|
||||
hash[i] = i;
|
||||
}
|
||||
|
||||
template<typename Handle>
|
||||
void initialize_hash(Handle h) {
|
||||
initialize_hash(h->get_index());
|
||||
}
|
||||
|
||||
void hash_facet_pair(SVertex_handle sv,
|
||||
Halffacet_const_handle f1,
|
||||
Halffacet_const_handle f2) {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <CGAL/Nef_3/SNC_simplify.h>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
|
||||
#undef CGAL_NEF_DEBUG
|
||||
#define CGAL_NEF_DEBUG 43
|
||||
|
|
@ -1308,8 +1309,9 @@ public:
|
|||
// O0.print();
|
||||
link_shalfedges_to_facet_cycles();
|
||||
|
||||
std::map<int, int> hash;
|
||||
CGAL::Unique_hash_map<SHalfedge_handle, bool> done(false, this->sncp()->number_of_shalfedges());
|
||||
std::size_t num_shalfedges = this->sncp()->number_of_shalfedges();
|
||||
std::unordered_map<int, int> hash(num_shalfedges);
|
||||
CGAL::Unique_hash_map<SHalfedge_handle, bool> done(false, num_shalfedges);
|
||||
|
||||
SHalfedge_iterator sei;
|
||||
CGAL_forall_shalfedges(sei, *this->sncp()) {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ class ID_support_handler {
|
|||
public:
|
||||
ID_support_handler() {}
|
||||
|
||||
void reserve(std::size_t) {}
|
||||
|
||||
int get_hash(int) { return 0; }
|
||||
template<typename Handle> void initialize_hash(Handle /*h*/) {}
|
||||
void initialize_hash(int /*i*/) {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue