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");
|
CGAL_NEF_TRACEN("=> for all v0 in snc1, qualify v0 with respect snc2");
|
||||||
// int i=2;
|
// int i=2;
|
||||||
Association A;
|
Association A;
|
||||||
|
A.reserve(snc1.number_of_shalfedges() + snc1.number_of_shalfloops() +
|
||||||
|
snc2.number_of_shalfedges() + snc2.number_of_shalfloops());
|
||||||
|
|
||||||
SHalfedge_const_iterator sei;
|
SHalfedge_const_iterator sei;
|
||||||
CGAL_forall_shalfedges(sei, snc1)
|
CGAL_forall_shalfedges(sei, snc1)
|
||||||
A.initialize_hash(sei);
|
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::unordered_map<Halffacet_pair, int, Handle_pair_hash_function> f2m;
|
||||||
std::map<int, int> hash;
|
std::unordered_map<int, int> hash;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ID_support_handler() {}
|
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 get_hash(int i) {
|
||||||
int root(i);
|
int root(i);
|
||||||
while(hash[root] != root)
|
while(hash[root] != root)
|
||||||
|
|
@ -78,12 +94,13 @@ class ID_support_handler<SNC_indexed_items, Decorator> {
|
||||||
hash[get_hash(i)] = parent;
|
hash[get_hash(i)] = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initialize_hash(int i) {
|
||||||
|
hash[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Handle>
|
template<typename Handle>
|
||||||
void initialize_hash(Handle h) {
|
void initialize_hash(Handle h) {
|
||||||
hash[h->get_index()] = h->get_index();
|
initialize_hash(h->get_index());
|
||||||
}
|
|
||||||
void initialize_hash(int i) {
|
|
||||||
hash[i] = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hash_facet_pair(SVertex_handle sv,
|
void hash_facet_pair(SVertex_handle sv,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#include <CGAL/Nef_3/SNC_simplify.h>
|
#include <CGAL/Nef_3/SNC_simplify.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#undef CGAL_NEF_DEBUG
|
#undef CGAL_NEF_DEBUG
|
||||||
#define CGAL_NEF_DEBUG 43
|
#define CGAL_NEF_DEBUG 43
|
||||||
|
|
@ -1308,8 +1309,9 @@ public:
|
||||||
// O0.print();
|
// O0.print();
|
||||||
link_shalfedges_to_facet_cycles();
|
link_shalfedges_to_facet_cycles();
|
||||||
|
|
||||||
std::map<int, int> hash;
|
std::size_t num_shalfedges = this->sncp()->number_of_shalfedges();
|
||||||
CGAL::Unique_hash_map<SHalfedge_handle, bool> done(false, 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;
|
SHalfedge_iterator sei;
|
||||||
CGAL_forall_shalfedges(sei, *this->sncp()) {
|
CGAL_forall_shalfedges(sei, *this->sncp()) {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ class ID_support_handler {
|
||||||
public:
|
public:
|
||||||
ID_support_handler() {}
|
ID_support_handler() {}
|
||||||
|
|
||||||
|
void reserve(std::size_t) {}
|
||||||
|
|
||||||
int get_hash(int) { return 0; }
|
int get_hash(int) { return 0; }
|
||||||
template<typename Handle> void initialize_hash(Handle /*h*/) {}
|
template<typename Handle> void initialize_hash(Handle /*h*/) {}
|
||||||
void initialize_hash(int /*i*/) {}
|
void initialize_hash(int /*i*/) {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue