From 3feac5dc4cdfe0d447f3b34fbac3bd5f5c47c5f9 Mon Sep 17 00:00:00 2001 From: Christophe Delage Date: Wed, 5 Sep 2007 13:57:52 +0000 Subject: [PATCH] Faster insert for iterator ranges in Triangulation_hierarchy_2. --- .../include/CGAL/Triangulation_hierarchy_2.h | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Triangulation_2/include/CGAL/Triangulation_hierarchy_2.h b/Triangulation_2/include/CGAL/Triangulation_hierarchy_2.h index d8dd8d35ab6..ecf195fd1fe 100644 --- a/Triangulation_2/include/CGAL/Triangulation_hierarchy_2.h +++ b/Triangulation_2/include/CGAL/Triangulation_hierarchy_2.h @@ -97,20 +97,39 @@ public: template < class InputIterator > int insert(InputIterator first, InputIterator last) - { + { int n = this->number_of_vertices(); std::vector points CGAL_make_vector(first, last); std::random_shuffle (points.begin(), points.end()); CGAL::spatial_sort (points.begin(), points.end(), geom_traits()); - Face_handle hint; + // hints[i] is the face of the previously inserted point in level i. + // Thanks to spatial sort, they are better hints than what the hierarchy + // would give us. + Face_handle hints[Triangulation_hierarchy_2__maxlevel]; for (typename std::vector::const_iterator p = points.begin(), end = points.end(); p != end; ++p) - hint = insert (*p, hint)->face(); + { + int vertex_level = random_level(); + + Vertex_handle v = hierarchy[0]->insert (*p, hints[0]); + hints[0] = v->face(); + + Vertex_handle prev = v; + + for (int level = 1; level <= vertex_level; ++level) { + v = hierarchy[level]->insert (*p, hints[level]); + hints[level] = v->face(); + + v->set_down (prev); + prev->set_up (v); + prev = v; + } + } return this->number_of_vertices() - n; - } + } void remove_degree_3(Vertex_handle v); void remove_first(Vertex_handle v);