Call target() so that we do not need a vertex as key

This commit is contained in:
Andreas Fabri 2020-04-10 13:55:40 +01:00
parent a79c6720c7
commit d5cf4c504e
2 changed files with 19 additions and 10 deletions

View File

@ -783,7 +783,7 @@ void add_faces(const RangeofVertexRange& faces_to_add, PolygonMesh& pm)
typedef boost::container::small_vector<halfedge_descriptor,8> Halfedges;
#else
//typedef boost::unordered_map<vertex_descriptor, halfedge_descriptor, boost::hash<vertex_descriptor> > Halfedges;
typedef Small_unordered_mapV2<vertex_descriptor, halfedge_descriptor, 8> Halfedges;
typedef Small_unordered_mapV2<PolygonMesh,vertex_descriptor, halfedge_descriptor, 8> Halfedges;
#endif
typedef typename CGAL::GetInitializedVertexIndexMap<PolygonMesh>::type Vid_map;
@ -808,8 +808,12 @@ void add_faces(const RangeofVertexRange& faces_to_add, PolygonMesh& pm)
std::vector<halfedge_descriptor> former_border_hedges;
//TODO: use vertex index map for v -> vector
#ifdef SV
std::vector<Halfedges> outgoing_hedges(num_vertices(pm));
#else
std::vector<Halfedges> outgoing_hedges(num_vertices(pm),Halfedges(pm));
#endif
for (const Vertex_range& vr : faces_to_add)
{
std::size_t nbh=vr.size();

View File

@ -21,16 +21,19 @@
namespace CGAL {
template <typename K, typename T, int M>
template <typename Mesh, typename K, typename T, int M>
class Small_unordered_mapV2 {
std::array<std::pair<K, T>, M> data;
const Mesh& mesh;
// std::array<std::pair<K, T>, M> data;
std::array<T, M> data;
boost::unordered_map<K, T> * big = nullptr;
int N = 0; // the number of stored elements
public:
Small_unordered_mapV2()
Small_unordered_mapV2(const Mesh& mesh)
: mesh(mesh)
{}
@ -46,14 +49,16 @@ public:
void set(const K& k, const T& t)
{
if (N < M) {
data[N].first = k;
data[N].second = t;
//data[N].first = k;
//data[N].second = t;
data[N] = t;
++N;
}else{
if (N == M) {
big = new boost::unordered_map<K, T>();
for(int pos = 0; pos < M; ++pos){
big->insert(data[pos]);
// big->insert(data[pos]);
big->insert(std::make_pair(target(data[pos],mesh),data[pos]));
}
(*big)[k] = t;
}else{
@ -77,7 +82,7 @@ public:
{
if (N <= M) {
for(int i =0; i < M; ++i){
if (data[i].first == k) {
if (target(data[i],mesh) == k) {
return const_iterator(*this,i);
}
}
@ -163,7 +168,7 @@ public:
return *bigit;
}
else {
return map.data[pos];
return std::make_pair(target(map.data[pos],map.mesh),map.data[pos]);
}
}
};