From 962ef0781208773a524058e693de1d9b38a7f336 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 12 Mar 2015 16:21:56 +0100 Subject: [PATCH 01/47] Add hash_value for Compact_container, Inplace_list, Index --- Hash_map/test/Hash_map/Hash.cpp | 48 ++++++++++++ .../include/CGAL/Compact_container.h | 6 ++ STL_Extension/include/CGAL/In_place_list.h | 19 +++++ .../include/CGAL/Surface_mesh/Surface_mesh.h | 75 ++++++++++++++++++- 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 Hash_map/test/Hash_map/Hash.cpp diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp new file mode 100644 index 00000000000..a05fbff3694 --- /dev/null +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -0,0 +1,48 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + + +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Polyhedron_3 Polyhedron; +typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Triangulation_2 Triangulation_2; + + + +template +void +fct(const P& p) +{ + typedef boost::graph_traits

::vertex_descriptor vertex_descriptor; + + std::map M; + vertex_descriptor vd; + M.find(vd); + + boost::unordered_map U; + U[vd] = 12; +} + + +int main() +{ + Polyhedron P; + fct(P); + + Surface_mesh S; + fct(S); + + Triangulation_2 T; + fct(T); + + return 0; +} + + diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 8b96bce8ba5..c5b9c62b81c 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -1159,6 +1159,12 @@ namespace internal { return &*rhs != NULL; } + template + std::size_t hash_value(const CC_iterator& i) + { + return reinterpret_cast(&*i); + } + } // namespace internal } //namespace CGAL diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index e0e54588535..22f7d19b083 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace CGAL { @@ -170,6 +171,24 @@ namespace internal { return In_place_list_iterator(const_cast(node)); } }; + + + +template + std::size_t hash_value(const In_place_list_iterator& i) + { + T* ptr = &*i; + return reinterpret_cast(ptr); + } + + +template + std::size_t hash_value(const In_place_list_const_iterator& i) + { + T* ptr = &*i; + return reinterpret_cast(ptr); + } + } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 8b5dbce5aab..5d20bc17eb9 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -48,6 +48,77 @@ #include namespace CGAL { + + /// Base class for vertex, halfedge, edge, and face index. + /// + /// \attention Note that `Index` is not a model of the concept `Handle`, + /// because it cannot be dereferenced. + /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index`, `Face_index`. + template + class Index + { + public: + typedef boost::uint32_t size_type; + /// Constructor. %Default construction creates an invalid index. + /// We write -1, which is + /// std::numeric_limits::max() + /// as `size_type` is an unsigned type. + explicit Index(size_type _idx=-1) : idx_(_idx) {} + + /// Get the underlying index of this index + operator size_type() const { return idx_; } + + /// reset index to be invalid (index=-1) + void reset() { idx_=-1; } + + /// return whether the index is valid, i.e., the index is not equal to -1. + bool is_valid() const { + size_type inf = -1; + return idx_ != inf; + } + + /// are two indices equal? + bool operator==(const T& _rhs) const { + return idx_ == _rhs.idx_; + } + + /// are two indices different? + bool operator!=(const T& _rhs) const { + return idx_ != _rhs.idx_; + } + + /// Comparison by index. + bool operator<(const T& _rhs) const { + return idx_ < _rhs.idx_; + } + + /// increments the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// increment. + Index& operator++() { ++idx_; return *this; } + /// decrements the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// decrement. + Index& operator--() { --idx_; return *this; } + + /// increments the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// increment. + Index operator++(int) { Index tmp(*this); ++idx_; return tmp; } + /// decrements the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// decrement. + Index operator--(int) { Index tmp(*this); --idx_; return tmp; } + private: + size_type idx_; + }; + + template + std::size_t hash_value(const CGAL::Index& i) + { + return i; + } + /// \ingroup PkgSurface_mesh /// This class is a data structure that can be used as halfedge data structure or polyhedral /// surface. It is an alternative to the classes `HalfedgeDS` and `Polyhedron_3` @@ -540,6 +611,7 @@ private: /// ///@{ +#if 0 #ifndef DOXYGEN_RUNNING /// Base class for vertex, halfedge, edge, and face index. /// @@ -603,7 +675,7 @@ private: private: size_type idx_; }; - +#endif #endif /// This class represents a vertex. @@ -2786,6 +2858,7 @@ collect_garbage() garbage_ = false; } + } // CGAL #endif /* CGAL_SURFACE_MESH_H */ From c2871c92e6385d4ab3ecf24eb37e64f694ae430e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 15 Apr 2015 19:15:34 +0200 Subject: [PATCH 02/47] Move the Index class back into Suface_mesh; Add doc --- .../STL_Extension/CGAL/Compact_container.h | 8 ++ .../doc/STL_Extension/CGAL/In_place_list.h | 18 ++++ .../include/CGAL/Surface_mesh/Surface_mesh.h | 93 +++++-------------- 3 files changed, 47 insertions(+), 72 deletions(-) diff --git a/STL_Extension/doc/STL_Extension/CGAL/Compact_container.h b/STL_Extension/doc/STL_Extension/CGAL/Compact_container.h index 260e751fae2..af19d6f60dd 100644 --- a/STL_Extension/doc/STL_Extension/CGAL/Compact_container.h +++ b/STL_Extension/doc/STL_Extension/CGAL/Compact_container.h @@ -828,4 +828,12 @@ static void * & pointer(T &t); }; /* end Compact_container_traits */ + +/*! +returns a hash value for the pointee of `i`. +\relates Compact_container +*/ + template + std::size_t hash_value(const Compact_container::iterator i); + } /* end namespace CGAL */ diff --git a/STL_Extension/doc/STL_Extension/CGAL/In_place_list.h b/STL_Extension/doc/STL_Extension/CGAL/In_place_list.h index a9ba823d6cf..d0aa69ce56b 100644 --- a/STL_Extension/doc/STL_Extension/CGAL/In_place_list.h +++ b/STL_Extension/doc/STL_Extension/CGAL/In_place_list.h @@ -762,4 +762,22 @@ void sort(); }; /* end In_place_list */ + +/*! +returns a hash value for the pointee of `i`. +\relates In_place_list +*/ + + template + std::size_t hash_value(const In_place_list::iterator i); + +/*! +returns a hash value for the pointee of `i`. +\relates In_place_list +*/ + +template +std::size_t hash_value(const In_place_list::const_iterator i); + + } /* end namespace CGAL */ diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 5d20bc17eb9..7665315f3f2 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -49,76 +49,6 @@ namespace CGAL { - /// Base class for vertex, halfedge, edge, and face index. - /// - /// \attention Note that `Index` is not a model of the concept `Handle`, - /// because it cannot be dereferenced. - /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index`, `Face_index`. - template - class Index - { - public: - typedef boost::uint32_t size_type; - /// Constructor. %Default construction creates an invalid index. - /// We write -1, which is - /// std::numeric_limits::max() - /// as `size_type` is an unsigned type. - explicit Index(size_type _idx=-1) : idx_(_idx) {} - - /// Get the underlying index of this index - operator size_type() const { return idx_; } - - /// reset index to be invalid (index=-1) - void reset() { idx_=-1; } - - /// return whether the index is valid, i.e., the index is not equal to -1. - bool is_valid() const { - size_type inf = -1; - return idx_ != inf; - } - - /// are two indices equal? - bool operator==(const T& _rhs) const { - return idx_ == _rhs.idx_; - } - - /// are two indices different? - bool operator!=(const T& _rhs) const { - return idx_ != _rhs.idx_; - } - - /// Comparison by index. - bool operator<(const T& _rhs) const { - return idx_ < _rhs.idx_; - } - - /// increments the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// increment. - Index& operator++() { ++idx_; return *this; } - /// decrements the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// decrement. - Index& operator--() { --idx_; return *this; } - - /// increments the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// increment. - Index operator++(int) { Index tmp(*this); ++idx_; return tmp; } - /// decrements the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// decrement. - Index operator--(int) { Index tmp(*this); --idx_; return tmp; } - private: - size_type idx_; - }; - - template - std::size_t hash_value(const CGAL::Index& i) - { - return i; - } - /// \ingroup PkgSurface_mesh /// This class is a data structure that can be used as halfedge data structure or polyhedral /// surface. It is an alternative to the classes `HalfedgeDS` and `Polyhedron_3` @@ -611,7 +541,7 @@ private: /// ///@{ -#if 0 + #ifndef DOXYGEN_RUNNING /// Base class for vertex, halfedge, edge, and face index. /// @@ -672,10 +602,18 @@ private: /// guarantee that the index is valid or undeleted after the /// decrement. Index operator--(int) { Index tmp(*this); --idx_; return tmp; } + + + + friend std::size_t hash_value(const Index& i) + { + return i; + } + private: size_type idx_; }; -#endif + #endif /// This class represents a vertex. @@ -2858,6 +2796,17 @@ collect_garbage() garbage_ = false; } +#ifdef DOXYGEN_RUNNING +/*! +returns `i` as hash value for the index types `Vertex_index`, `Halfedge_index`, +`Edge_index`, and `Face_index`. +\relates Surface_mesh +*/ + template + std::size_t hash_value(Surface_mesh

::Index i); + + +#endif } // CGAL From a3a9a9c8738f03e3bc00f8f5bd4dfb5195207684 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 16 Apr 2015 13:23:38 +0200 Subject: [PATCH 03/47] move Index out of the class and rename it to SM_Index --- .../examples/Surface_mesh/CMakeLists.txt | 1 + .../include/CGAL/Surface_mesh/Surface_mesh.h | 167 +++++++++--------- 2 files changed, 86 insertions(+), 82 deletions(-) diff --git a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt index 2f8a933a74a..392a9480cac 100644 --- a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt +++ b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt @@ -31,6 +31,7 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "sm_kruskal.cpp" ) create_single_source_cgal_program( "sm_memory.cpp" ) create_single_source_cgal_program( "sm_properties.cpp" ) + create_single_source_cgal_program( "unordered_set.cpp" ) else() diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 7665315f3f2..b73e8a96f51 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -49,6 +49,82 @@ namespace CGAL { + +#ifndef DOXYGEN_RUNNING + /// Base class for vertex, halfedge, edge, and face index. + /// + /// \attention Note that `Index` is not a model of the concept `Handle`, + /// because it cannot be dereferenced. + /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index`, `Face_index`. + template + class SM_Index + { + public: + typedef boost::uint32_t size_type; + /// Constructor. %Default construction creates an invalid index. + /// We write -1, which is + /// std::numeric_limits::max() + /// as `size_type` is an unsigned type. + explicit SM_Index(size_type _idx=-1) : idx_(_idx) {} + + /// Get the underlying index of this index + operator size_type() const { return idx_; } + + /// reset index to be invalid (index=-1) + void reset() { idx_=-1; } + + /// return whether the index is valid, i.e., the index is not equal to -1. + bool is_valid() const { + size_type inf = -1; + return idx_ != inf; + } + + /// are two indices equal? + bool operator==(const T& _rhs) const { + return idx_ == _rhs.idx_; + } + + /// are two indices different? + bool operator!=(const T& _rhs) const { + return idx_ != _rhs.idx_; + } + + /// Comparison by index. + bool operator<(const T& _rhs) const { + return idx_ < _rhs.idx_; + } + + /// increments the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// increment. + SM_Index& operator++() { ++idx_; return *this; } + /// decrements the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// decrement. + SM_Index& operator--() { --idx_; return *this; } + + /// increments the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// increment. + SM_Index operator++(int) { SM_Index tmp(*this); ++idx_; return tmp; } + /// decrements the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// decrement. + SM_Index operator--(int) { SM_Index tmp(*this); --idx_; return tmp; } + + + + friend std::size_t hash_value(const SM_Index& i) + { + return i; + } + + private: + size_type idx_; + }; + +#endif + /// \ingroup PkgSurface_mesh /// This class is a data structure that can be used as halfedge data structure or polyhedral /// surface. It is an alternative to the classes `HalfedgeDS` and `Polyhedron_3` @@ -542,93 +618,20 @@ private: ///@{ -#ifndef DOXYGEN_RUNNING - /// Base class for vertex, halfedge, edge, and face index. - /// - /// \attention Note that `Index` is not a model of the concept `Handle`, - /// because it cannot be dereferenced. - /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index`, `Face_index`. - template - class Index - { - public: - /// Constructor. %Default construction creates an invalid index. - /// We write -1, which is - /// std::numeric_limits::max() - /// as `size_type` is an unsigned type. - explicit Index(size_type _idx=-1) : idx_(_idx) {} - - /// Get the underlying index of this index - operator size_type() const { return idx_; } - - /// reset index to be invalid (index=-1) - void reset() { idx_=-1; } - - /// return whether the index is valid, i.e., the index is not equal to -1. - bool is_valid() const { - size_type inf = -1; - return idx_ != inf; - } - - /// are two indices equal? - bool operator==(const T& _rhs) const { - return idx_ == _rhs.idx_; - } - - /// are two indices different? - bool operator!=(const T& _rhs) const { - return idx_ != _rhs.idx_; - } - - /// Comparison by index. - bool operator<(const T& _rhs) const { - return idx_ < _rhs.idx_; - } - - /// increments the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// increment. - Index& operator++() { ++idx_; return *this; } - /// decrements the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// decrement. - Index& operator--() { --idx_; return *this; } - - /// increments the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// increment. - Index operator++(int) { Index tmp(*this); ++idx_; return tmp; } - /// decrements the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// decrement. - Index operator--(int) { Index tmp(*this); --idx_; return tmp; } - - - - friend std::size_t hash_value(const Index& i) - { - return i; - } - - private: - size_type idx_; - }; - -#endif /// This class represents a vertex. /// \cgalModels `Index` /// \sa `Halfedge_index`, `Edge_index`, `Face_index` class Vertex_index #ifndef DOXYGEN_RUNNING - : public Index + : public SM_Index #endif { public: /// %Default constructor. - Vertex_index() : Index(-1) {} + Vertex_index() : SM_Index(-1) {} - explicit Vertex_index(size_type _idx) : Index(_idx) {} + explicit Vertex_index(size_type _idx) : SM_Index(_idx) {} /// prints the index and a short identification string to an ostream. friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Vertex_index const& v) @@ -642,14 +645,14 @@ private: /// \sa `Vertex_index`, `Edge_index`, `Face_index` class Halfedge_index #ifndef DOXYGEN_RUNNING - : public Index + : public SM_Index #endif { public: /// %Default constructor - Halfedge_index() : Index(-1) {} + Halfedge_index() : SM_Index(-1) {} - explicit Halfedge_index(size_type _idx) : Index(_idx) {} + explicit Halfedge_index(size_type _idx) : SM_Index(_idx) {} /// prints the index and a short identification string to an ostream. friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Halfedge_index const& h) @@ -663,14 +666,14 @@ private: /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index` class Face_index #ifndef DOXYGEN_RUNNING - : public Index + : public SM_Index #endif { public: /// %Default constructor - Face_index() : Index(-1) {} + Face_index() : SM_Index(-1) {} - explicit Face_index(size_type _idx) : Index(_idx) {} + explicit Face_index(size_type _idx) : SM_Index(_idx) {} /// prints the index and a short identification string to an ostream. friend std::ostream& operator<<(std::ostream& os, typename Surface_mesh::Face_index const& f) From 144e4772c13f6316f9abe9e66a5809745e5279fe Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 16 Apr 2015 13:27:38 +0200 Subject: [PATCH 04/47] move Vertex_index --- .../include/CGAL/Surface_mesh/Surface_mesh.h | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index b73e8a96f51..330dc647f08 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -123,6 +123,25 @@ namespace CGAL { size_type idx_; }; + /// This class represents a vertex. + /// \cgalModels `Index` + /// \sa `Halfedge_index`, `Edge_index`, `Face_index` + class SM_Vertex_index + : public SM_Index + { + public: + /// %Default constructor. + SM_Vertex_index() : SM_Index(-1) {} + + explicit SM_Vertex_index(size_type _idx) : SM_Index(_idx) {} + + /// prints the index and a short identification string to an ostream. + friend std::ostream& operator<<(std::ostream& os, SM_Vertex_index const& v) + { + return (os << 'v' << (size_type)v ); + } + }; + #endif /// \ingroup PkgSurface_mesh @@ -618,6 +637,7 @@ private: ///@{ +#ifdef DOXYGEN_RUNNING /// This class represents a vertex. /// \cgalModels `Index` @@ -639,6 +659,9 @@ private: return (os << 'v' << (size_type)v ); } }; +#else + typedef SM_Vertex_index Vertex_index; +#endif /// This class represents a halfedge. /// \cgalModels `Index` From 0a2e3f8a8bf3e58e11333dd329ef553929ad56a0 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 16 Apr 2015 13:31:40 +0200 Subject: [PATCH 05/47] move Halfedge_index --- .../include/CGAL/Surface_mesh/Surface_mesh.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 330dc647f08..7a2f667ed92 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -142,6 +142,25 @@ namespace CGAL { } }; + /// This class represents a halfedge. + /// \cgalModels `Index` + /// \sa `Vertex_index`, `Edge_index`, `Face_index` + class SM_Halfedge_index + : public SM_Index + { + public: + /// %Default constructor + SM_Halfedge_index() : SM_Index(-1) {} + + explicit SM_Halfedge_index(size_type _idx) : SM_Index(_idx) {} + + /// prints the index and a short identification string to an ostream. + friend std::ostream& operator<<(std::ostream& os, SM_Halfedge_index const& h) + { + return (os << 'h' << (size_type)h ); + } + }; + #endif /// \ingroup PkgSurface_mesh @@ -663,6 +682,8 @@ private: typedef SM_Vertex_index Vertex_index; #endif +#ifdef DOXYGEN_RUNNING + /// This class represents a halfedge. /// \cgalModels `Index` /// \sa `Vertex_index`, `Edge_index`, `Face_index` @@ -683,6 +704,10 @@ private: return (os << 'h' << (size_type)h ); } }; +#else + typedef SM_Halfedge_index Halfedge_index; +#endif + /// This class represents a face /// \cgalModels `Index` From 821ccc33734104509071f06af0da54fd3699b2d7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 16 Apr 2015 13:38:37 +0200 Subject: [PATCH 06/47] move Face_index and add fake unordered set --- .../examples/Surface_mesh/unordered_set.cpp | 49 +++++++++++++++++++ .../include/CGAL/Surface_mesh/Surface_mesh.h | 24 ++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Surface_mesh/examples/Surface_mesh/unordered_set.cpp diff --git a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp new file mode 100644 index 00000000000..3c0a56d8c67 --- /dev/null +++ b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp @@ -0,0 +1,49 @@ +#include + +namespace std { +template +struct HashFct { + void operator()(const T& t) + { + std::cerr << "generic HashFct" << std::endl; + } +}; +} + +#include +#include + +namespace std { + template <> +struct HashFct { + void operator()(const CGAL::SM_Halfedge_index& t) + { + std::cerr << "SM_Halfegge_index HashFct" << std::endl; + } +}; +} + +template +struct Unordered +{ + Unordered() + { + std::HashFct fct; + T t; + fct(t); + } +}; + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Surface_mesh Mesh; +typedef Mesh::Halfedge_index Halfedge_index; + +int main() +{ + Unordered U; + return 0; +} diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 7a2f667ed92..d0ae4ec45f9 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -161,6 +161,25 @@ namespace CGAL { } }; + /// This class represents a face + /// \cgalModels `Index` + /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index` + class SM_Face_index + : public SM_Index + { + public: + /// %Default constructor + SM_Face_index() : SM_Index(-1) {} + + explicit SM_Face_index(size_type _idx) : SM_Index(_idx) {} + + /// prints the index and a short identification string to an ostream. + friend std::ostream& operator<<(std::ostream& os, SM_Face_index const& f) + { + return (os << 'f' << (size_type)f ); + } + }; + #endif /// \ingroup PkgSurface_mesh @@ -708,7 +727,7 @@ private: typedef SM_Halfedge_index Halfedge_index; #endif - +#ifdef DOXYGEN_RUNNING /// This class represents a face /// \cgalModels `Index` /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index` @@ -729,6 +748,9 @@ private: return (os << 'f' << (size_type)f ); } }; +#else + typedef SM_Face_index Face_index; +#endif /// This class represents an edge. /// \cgalModels `Index` From 205a594a7747ace821286592206dc9a27a182c6c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Apr 2015 10:21:14 +0200 Subject: [PATCH 07/47] add specializations of hash and add tests --- .../boost/graph/graph_traits_HalfedgeDS.h | 14 +++ .../graph/graph_traits_Triangulation_2.h | 25 +++- .../include/CGAL/Compact_container.h | 13 ++ STL_Extension/include/CGAL/In_place_list.h | 23 ++++ .../examples/Surface_mesh/unordered_set.cpp | 74 +++++++----- .../include/CGAL/Surface_mesh/Surface_mesh.h | 112 +++++++++++++++++- 6 files changed, 231 insertions(+), 30 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h index 03565011b18..2972a02db60 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h @@ -217,4 +217,18 @@ public: } //namespace CGAL + +namespace std { + template struct hash; + + template + struct hash > { + std::size_t operator()(const CGAL::internal::HDS_edge& e) + { + std::cerr << "HDS_edge HashFct" << std::endl; + std::hash fct; + return fct(e.halfedge()); + } + }; +} #endif // CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index 4670aad79d6..9577f52a85c 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -40,8 +40,9 @@ namespace CGAL { template < class T, class EdgeBase > class Edge : public EdgeBase { + +public: typedef typename T::Face_handle Face_handle ; - public: Edge() {} @@ -64,7 +65,12 @@ class Edge : public EdgeBase { this->first = e.first; this->second = e.second; return *this; -} + } + + Face_handle face_handle() const + { + return this->first; + } bool operator==(const Edge& other) const { @@ -811,6 +817,21 @@ namespace boost { }; } // namespace boost + +namespace std { + template struct hash; + + template < class T, class EdgeBase> + struct hash > { + std::size_t operator()(const CGAL::detail::Edge& e) + { + std::cerr << "Triangulation_2::Edge HashFct" << std::endl; + std::hash::Face_handle> fct; + return fct(e.face_handle()); + } + }; +} // namespace std + //#include #endif // CGAL_GRAPH_TRAITS_TRIANGULATION_2_H diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index c5b9c62b81c..88b98e219c2 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -1169,4 +1169,17 @@ namespace internal { } //namespace CGAL +namespace std { + template struct hash; + + template < class DSC, bool Const > + struct hash > { + std::size_t operator()(const CGAL::internal::CC_iterator& i) + { + std::cerr << "CC::iterator HashFct" << std::endl; + return reinterpret_cast(&*i); + } + }; +} + #endif // CGAL_COMPACT_CONTAINER_H diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 22f7d19b083..2fdbb00de74 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -771,4 +771,27 @@ void In_place_list::sort() { } //namespace CGAL +namespace std { + template struct hash; + + template < class T, class Alloc > + struct hash > { + std::size_t operator()(const CGAL::internal::In_place_list_iterator& i) + { + std::cerr << "In_place_list::iterator HashFct" << std::endl; + T* ptr = &*i; + return reinterpret_cast(ptr); + } + }; + + template < class T, class Alloc > + struct hash > { + std::size_t operator()(const CGAL::internal::In_place_list_const_iterator& i) + { + std::cerr << "In_place_list::const_iterator HashFct" << std::endl; + T* ptr = &*i; + return reinterpret_cast(ptr); + } + }; +} #endif // CGAL_IN_PLACE_LIST_H diff --git a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp index 3c0a56d8c67..b8a3f3b3a63 100644 --- a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp +++ b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp @@ -1,49 +1,69 @@ #include - -namespace std { -template -struct HashFct { - void operator()(const T& t) - { - std::cerr << "generic HashFct" << std::endl; - } -}; -} - -#include #include +#include +#include +#include -namespace std { - template <> -struct HashFct { - void operator()(const CGAL::SM_Halfedge_index& t) - { - std::cerr << "SM_Halfegge_index HashFct" << std::endl; - } -}; -} +#include +#include +#include template struct Unordered { Unordered() { - std::HashFct fct; + std::hash fct; T t; fct(t); } }; -#include -#include typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point; -typedef CGAL::Surface_mesh Mesh; -typedef Mesh::Halfedge_index Halfedge_index; + +typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Triangulation_2 Triangulation_2; +typedef CGAL::Polyhedron_3 Polyhedron_3; int main() { - Unordered U; + { + std::cout << "Surface_mesh::.._index"<< std::endl; + Unordered U1; + Unordered U2; + Unordered U3; + Unordered U4; + + std::cout << "\ngraph_traits::_descriptor"<< std::endl; + Unordered::vertex_descriptor> U5; + Unordered::halfedge_descriptor> U6; + Unordered::edge_descriptor> U7; + Unordered::face_descriptor> U8; + } + { + std::cout << "\nTriangulation_2::.._handle"<< std::endl; + Unordered U1; + Unordered U2; + + std::cout << "\ngraph_traits::_descriptor"<< std::endl; + Unordered::vertex_descriptor> U3; + // Unordered::halfedge_descriptor> U4; + Unordered::edge_descriptor> U5; + Unordered::face_descriptor> U6; + } + { + std::cout << "\nPolyhedron_3::.._handle"<< std::endl; + Unordered U1; + Unordered U2; + Unordered U3; + + std::cout << "\ngraph_traits::_descriptor"<< std::endl; + Unordered::vertex_descriptor> U5; + Unordered::halfedge_descriptor> U6; + Unordered::edge_descriptor> U7; + Unordered::face_descriptor> U8; + } return 0; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index d0ae4ec45f9..25dc46c78a3 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -180,6 +180,72 @@ namespace CGAL { } }; + /// This class represents an edge. + /// \cgalModels `Index` + /// \sa `Vertex_index`, `Halfedge_index`, `Face_index` + class SM_Edge_index + { + public: + typedef boost::uint32_t size_type; + /// %Default constructor + SM_Edge_index() : halfedge_(-1) { } + + SM_Edge_index(size_type idx) : halfedge_(idx * 2) { } + + /// constructs an `SM_Edge_index` from a halfedge. + SM_Edge_index(SM_Halfedge_index he) : halfedge_(he) { } + /// @cond CGAL_DOCUMENT_INTERNALS + /// returns the internal halfedge. + SM_Halfedge_index halfedge() const { return halfedge_; } + + /// returns the underlying index of this index. + operator size_type() const { return (size_type)halfedge_ / 2; } + + /// resets index to be invalid (index=-1) + void reset() { halfedge_.reset(); } + + /// returns whether the index is valid, i.e., the index is not equal to -1. + bool is_valid() const { return halfedge_.is_valid(); } + + /// Are two indices equal? + bool operator==(const SM_Edge_index& other) const { return (size_type)(*this) == (size_type)other; } + + /// Are two indices different? + bool operator!=(const SM_Edge_index& other) const { return (size_type)(*this) != (size_type)other; } + + /// compares by index. + bool operator<(const SM_Edge_index& other) const { return (size_type)(*this) < (size_type)other;} + + /// decrements the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// decrement. + SM_Edge_index& operator--() { halfedge_ = SM_Halfedge_index((size_type)halfedge_ - 2); return *this; } + + /// increments the internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// increment. + SM_Edge_index& operator++() { halfedge_ = SM_Halfedge_index((size_type)halfedge_ + 2); return *this; } + + /// decrements internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// decrement. + SM_Edge_index operator--(int) { SM_Edge_index tmp(*this); halfedge_ = SM_Halfedge_index((size_type)halfedge_ - 2); return tmp; } + + /// increments internal index. This operation does not + /// guarantee that the index is valid or undeleted after the + /// increment. + SM_Edge_index operator++(int) { SM_Edge_index tmp(*this); halfedge_ = SM_Halfedge_index((size_type)halfedge_ + 2); return tmp; } + + /// @endcond + + /// prints the index and a short identification string to an ostream. + friend std::ostream& operator<<(std::ostream& os, SM_Edge_index const& e) + { + return (os << 'e' << (size_type)e << " on " << e.halfedge()); + } + private: + SM_Halfedge_index halfedge_; + }; #endif /// \ingroup PkgSurface_mesh @@ -752,6 +818,7 @@ private: typedef SM_Face_index Face_index; #endif +#ifdef DOXYGEN_RUNNING /// This class represents an edge. /// \cgalModels `Index` /// \sa `Vertex_index`, `Halfedge_index`, `Face_index` @@ -817,7 +884,9 @@ private: private: Halfedge_index halfedge_; }; - +#else + typedef SM_Edge_index Edge_index; +#endif ///@} @@ -2883,5 +2952,46 @@ returns `i` as hash value for the index types `Vertex_index`, `Halfedge_index`, } // CGAL + +namespace std { + template struct hash; + + template <> + struct hash { + std::size_t operator()(const CGAL::SM_Halfedge_index& i) + { + std::cerr << "SM_Halfege_index HashFct" << std::endl; + return i; + } + }; + + template <> + struct hash { + std::size_t operator()(const CGAL::SM_Vertex_index& i) + { + std::cerr << "SM_Vertex_index HashFct" << std::endl; + return i; + } + }; + + template <> + struct hash { + std::size_t operator()(const CGAL::SM_Face_index& i) + { + std::cerr << "SM_Face_index HashFct" << std::endl; + return i; + } + }; + + template <> + struct hash { + std::size_t operator()(const CGAL::SM_Edge_index& i) + { + std::cerr << "SM_Edge_index HashFct" << std::endl; + return i; + } + }; +} + #endif /* CGAL_SURFACE_MESH_H */ From 7f0bdd272daf5d476a498b820f1a61d92b261906 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Apr 2015 10:33:22 +0200 Subject: [PATCH 08/47] move halfedge_descriptor out of the graph_traits class --- .../graph/graph_traits_Triangulation_2.h | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index 9577f52a85c..ae1ecb7efab 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -253,6 +253,44 @@ public: } }; + + template + struct T2_halfedge_descriptor + { + typedef typename Tr::Face_handle face_descriptor; + face_descriptor first; + int second; + operator std::pair() { return std::make_pair(first,second); } + + T2_halfedge_descriptor() + {} + + T2_halfedge_descriptor(const typename Tr::Edge& e) + : first(e.first), second(e.second) + {} + + T2_halfedge_descriptor(face_descriptor fd, int i) + : first(fd), second(i) + {} + + bool operator==(const T2_halfedge_descriptor& other) const + { + return (first == other.first) && (second == other.second); + } + + bool operator!=(const T2_halfedge_descriptor& other) const + { + return (first != other.first) || (second != other.second); + } + + bool operator<(const T2_halfedge_descriptor& other) const + { + if(first < other.first) return true; + if(first > other.first) return false; + return second < other.second; + } + }; + } // namespace detail } // namespace CGAL @@ -276,41 +314,7 @@ namespace boost { typedef typename CGAL::Triangulation_2::All_edges_iterator edge_iterator; - // with just a typedef to Edge VC++ has ambiguities for function `next()` - struct halfedge_descriptor - { - face_descriptor first; - int second; - operator std::pair() { return std::make_pair(first,second); } - - halfedge_descriptor() - {} - - halfedge_descriptor(const typename Triangulation::Edge& e) - : first(e.first), second(e.second) - {} - - halfedge_descriptor(face_descriptor fd, int i) - : first(fd), second(i) - {} - - bool operator==(const halfedge_descriptor& other) const - { - return (first == other.first) && (second == other.second); - } - - bool operator!=(const halfedge_descriptor& other) const - { - return (first != other.first) || (second != other.second); - } - - bool operator<(const halfedge_descriptor& other) const - { - if(first < other.first) return true; - if(first > other.first) return false; - return second < other.second; - } - }; + typedef CGAL::detail::T2_halfedge_descriptor halfedge_descriptor; typedef typename CGAL::Triangulation_2::All_halfedges_iterator halfedge_iterator; From 0eaa9235d0e884d680fde1657e43878ea91e042c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Apr 2015 10:44:43 +0200 Subject: [PATCH 09/47] Add specializations of hash --- .../graph/graph_traits_Triangulation_2.h | 23 +++++++++++++++---- .../examples/Surface_mesh/unordered_set.cpp | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index ae1ecb7efab..8eb58e59a92 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -67,9 +67,10 @@ public: return *this; } - Face_handle face_handle() const + std::size_t hash() const { - return this->first; + std::hash fct; + return fct(this->first); } bool operator==(const Edge& other) const @@ -273,6 +274,12 @@ public: : first(fd), second(i) {} + std::size_t hash() const + { + std::hash fct; + return fct(first); + } + bool operator==(const T2_halfedge_descriptor& other) const { return (first == other.first) && (second == other.second); @@ -830,8 +837,16 @@ namespace std { std::size_t operator()(const CGAL::detail::Edge& e) { std::cerr << "Triangulation_2::Edge HashFct" << std::endl; - std::hash::Face_handle> fct; - return fct(e.face_handle()); + return e.hash(); + } + }; + + template < class Tr> + struct hash > { + std::size_t operator()(const CGAL::detail::T2_halfedge_descriptor& e) + { + std::cerr << "Triangulation_2::halfedge_descriptor HashFct" << std::endl; + return e.hash(); } }; } // namespace std diff --git a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp index b8a3f3b3a63..106782b81bd 100644 --- a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp +++ b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp @@ -49,7 +49,7 @@ int main() std::cout << "\ngraph_traits::_descriptor"<< std::endl; Unordered::vertex_descriptor> U3; - // Unordered::halfedge_descriptor> U4; + Unordered::halfedge_descriptor> U4; Unordered::edge_descriptor> U5; Unordered::face_descriptor> U6; } From 832208d81546dcb33518def08a20ac6b37fb7894 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Apr 2015 15:49:21 +0200 Subject: [PATCH 10/47] simplifications --- .../boost/graph/graph_traits_Triangulation_2.h | 14 ++++++-------- STL_Extension/include/CGAL/In_place_list.h | 6 ++---- .../include/CGAL/Surface_mesh/Surface_mesh.h | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index 8eb58e59a92..e9f70932c6c 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -67,10 +67,9 @@ public: return *this; } - std::size_t hash() const + friend std::size_t hash_value(const Edge& e) { - std::hash fct; - return fct(this->first); + return hash_value(e.first); } bool operator==(const Edge& other) const @@ -274,10 +273,9 @@ public: : first(fd), second(i) {} - std::size_t hash() const + friend std::size_t hash_value(const T2_halfedge_descriptor& h) { - std::hash fct; - return fct(first); + return hash_value(h.first); } bool operator==(const T2_halfedge_descriptor& other) const @@ -837,7 +835,7 @@ namespace std { std::size_t operator()(const CGAL::detail::Edge& e) { std::cerr << "Triangulation_2::Edge HashFct" << std::endl; - return e.hash(); + return hash_value(e); } }; @@ -846,7 +844,7 @@ namespace std { std::size_t operator()(const CGAL::detail::T2_halfedge_descriptor& e) { std::cerr << "Triangulation_2::halfedge_descriptor HashFct" << std::endl; - return e.hash(); + return hash_value(e); } }; } // namespace std diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 2fdbb00de74..5dc2bf1a74b 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -779,8 +779,7 @@ namespace std { std::size_t operator()(const CGAL::internal::In_place_list_iterator& i) { std::cerr << "In_place_list::iterator HashFct" << std::endl; - T* ptr = &*i; - return reinterpret_cast(ptr); + return hash_value(i); } }; @@ -789,8 +788,7 @@ namespace std { std::size_t operator()(const CGAL::internal::In_place_list_const_iterator& i) { std::cerr << "In_place_list::const_iterator HashFct" << std::endl; - T* ptr = &*i; - return reinterpret_cast(ptr); + return hash_value(i); } }; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 25dc46c78a3..50dd9317801 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -114,15 +114,19 @@ namespace CGAL { - friend std::size_t hash_value(const SM_Index& i) - { - return i; - } + private: size_type idx_; }; + template + std::size_t hash_value(const SM_Index& i) + { + std::size_t ret = i; + return ret; + } + /// This class represents a vertex. /// \cgalModels `Index` /// \sa `Halfedge_index`, `Edge_index`, `Face_index` @@ -243,6 +247,12 @@ namespace CGAL { { return (os << 'e' << (size_type)e << " on " << e.halfedge()); } + + friend std::size_t hash_value(const SM_Edge_index& i) + { + return i; + } + private: SM_Halfedge_index halfedge_; }; From 0574d70b740103ac3f2780f4c94ad633979949b5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Apr 2015 15:50:10 +0200 Subject: [PATCH 11/47] add a hashing benchmark --- Hash_map/benchmark/Hash_map/CMakeLists.txt | 62 ++++++++++++ Hash_map/benchmark/Hash_map/data/triangle.off | 6 ++ Hash_map/benchmark/Hash_map/hm.cpp | 94 +++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 Hash_map/benchmark/Hash_map/CMakeLists.txt create mode 100644 Hash_map/benchmark/Hash_map/data/triangle.off create mode 100644 Hash_map/benchmark/Hash_map/hm.cpp diff --git a/Hash_map/benchmark/Hash_map/CMakeLists.txt b/Hash_map/benchmark/Hash_map/CMakeLists.txt new file mode 100644 index 00000000000..394642f4ade --- /dev/null +++ b/Hash_map/benchmark/Hash_map/CMakeLists.txt @@ -0,0 +1,62 @@ +# Created by the script cgal_create_CMakeLists +# This is the CMake script for compiling a set of CGAL applications. + +project( Hash_map ) + + +cmake_minimum_required(VERSION 2.6.2) +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) + if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) + cmake_policy(VERSION 2.8.4) + else() + cmake_policy(VERSION 2.6) + endif() +endif() + +set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) + +if ( COMMAND cmake_policy ) + + cmake_policy( SET CMP0003 NEW ) + +endif() + +# CGAL and its components +find_package( CGAL QUIET COMPONENTS ) + +if ( NOT CGAL_FOUND ) + + message(STATUS "This project requires the CGAL library, and will not be compiled.") + return() + +endif() + +# include helper file +include( ${CGAL_USE_FILE} ) + + +# Boost and its components +find_package( Boost REQUIRED ) + +if ( NOT Boost_FOUND ) + + message(STATUS "This project requires the Boost library, and will not be compiled.") + + return() + +endif() + +# include for local directory + +# include for local package +include_directories( BEFORE ../../include ) + + +# Creating entries for all .cpp/.C files with "main" routine +# ########################################################## + +include( CGAL_CreateSingleSourceCGALProgram ) + +create_single_source_cgal_program( "hm.cpp" ) + + diff --git a/Hash_map/benchmark/Hash_map/data/triangle.off b/Hash_map/benchmark/Hash_map/data/triangle.off new file mode 100644 index 00000000000..a3c407f60fb --- /dev/null +++ b/Hash_map/benchmark/Hash_map/data/triangle.off @@ -0,0 +1,6 @@ +OFF +3 1 0 +0 0 0 +1 0 0 +0 1 0 +3 0 1 2 diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp new file mode 100644 index 00000000000..c4b139c82ac --- /dev/null +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -0,0 +1,94 @@ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; + +typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Polyhedron_3 Polyhedron_3; +typedef CGAL::Timer Timer; + +template +void +run(char* fname) +{ + typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + G g; + std::ifstream input(fname); + input >> g; + + typedef boost::property_map::type VPM; + VPM vpm = get(CGAL::vertex_point,g); + + + std::vector V; + std::vector P1, P2; + BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ + V.push_back(vd); + } + std::random_shuffle(V.begin(), V.end()); + + std::map vm; + boost::unordered_map vum; + BOOST_FOREACH(vertex_descriptor vd, V){ + vm[vd] = get(vpm,vd); + vum[vd] = get(vpm,vd); + + } + + Timer t; + t.start(); + for(int i= 0; i < 1; i++){ + BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ + P1.push_back(vm[vd]); + /* + if(vm[vd] != get(vpm,vd)){ + std::cerr << "error1" << std::endl; + } + */ + } + } + t.stop(); + std::cerr << t.time() << " sec."<< std::endl; + t.reset(); + t.start(); + for(int i= 0; i < 1; i++){ + BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ + boost::unordered_map::iterator it = vum.find(vd); + P2.push_back((*it).second); + /* + if(vum[vd] != get(vpm,vd)){ + std::cerr << "error2" << std::endl; + } + */ + } + } + t.stop(); + std::cerr << t.time() << " sec."<< std::endl; + if(P1.size() != P2.size()){ + std::cerr << "error3" << std::endl; + } +} + +int main(int , char* argv[]) +{ + run(argv[1]); + run(argv[1]); + return 0; +} From cebaa850be0dbfc833cb6f651bcf471901ffade1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 17 Apr 2015 17:05:06 +0200 Subject: [PATCH 12/47] add missing typenames --- Hash_map/benchmark/Hash_map/hm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index c4b139c82ac..2883fad2ef8 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -28,12 +28,12 @@ template void run(char* fname) { - typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; G g; std::ifstream input(fname); input >> g; - typedef boost::property_map::type VPM; + typedef typename boost::property_map::type VPM; VPM vpm = get(CGAL::vertex_point,g); @@ -70,7 +70,7 @@ run(char* fname) t.start(); for(int i= 0; i < 1; i++){ BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ - boost::unordered_map::iterator it = vum.find(vd); + typename boost::unordered_map::iterator it = vum.find(vd); P2.push_back((*it).second); /* if(vum[vd] != get(vpm,vd)){ From d36593eb72018225e3ac412c992435400a48783a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 17 Apr 2015 17:22:26 +0200 Subject: [PATCH 13/47] add missing const and remove debug output --- .../CGAL/boost/graph/graph_traits_HalfedgeDS.h | 2 +- .../CGAL/boost/graph/graph_traits_Triangulation_2.h | 4 ++-- STL_Extension/include/CGAL/Compact_container.h | 2 +- STL_Extension/include/CGAL/In_place_list.h | 6 ++---- Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h | 11 ++++------- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h index 2972a02db60..94ac62dc5b2 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h @@ -223,7 +223,7 @@ namespace std { template struct hash > { - std::size_t operator()(const CGAL::internal::HDS_edge& e) + std::size_t operator()(const CGAL::internal::HDS_edge& e) const { std::cerr << "HDS_edge HashFct" << std::endl; std::hash fct; diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index e9f70932c6c..f2142ca3c22 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -832,7 +832,7 @@ namespace std { template < class T, class EdgeBase> struct hash > { - std::size_t operator()(const CGAL::detail::Edge& e) + std::size_t operator()(const CGAL::detail::Edge& e) const { std::cerr << "Triangulation_2::Edge HashFct" << std::endl; return hash_value(e); @@ -841,7 +841,7 @@ namespace std { template < class Tr> struct hash > { - std::size_t operator()(const CGAL::detail::T2_halfedge_descriptor& e) + std::size_t operator()(const CGAL::detail::T2_halfedge_descriptor& e) const { std::cerr << "Triangulation_2::halfedge_descriptor HashFct" << std::endl; return hash_value(e); diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 88b98e219c2..72cb2e835fd 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -1174,7 +1174,7 @@ namespace std { template < class DSC, bool Const > struct hash > { - std::size_t operator()(const CGAL::internal::CC_iterator& i) + std::size_t operator()(const CGAL::internal::CC_iterator& i) const { std::cerr << "CC::iterator HashFct" << std::endl; return reinterpret_cast(&*i); diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 5dc2bf1a74b..88bd11cb416 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -776,18 +776,16 @@ namespace std { template < class T, class Alloc > struct hash > { - std::size_t operator()(const CGAL::internal::In_place_list_iterator& i) + std::size_t operator()(const CGAL::internal::In_place_list_iterator& i) const { - std::cerr << "In_place_list::iterator HashFct" << std::endl; return hash_value(i); } }; template < class T, class Alloc > struct hash > { - std::size_t operator()(const CGAL::internal::In_place_list_const_iterator& i) + std::size_t operator()(const CGAL::internal::In_place_list_const_iterator& i) const { - std::cerr << "In_place_list::const_iterator HashFct" << std::endl; return hash_value(i); } }; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 50dd9317801..5a04a81b4b4 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2968,7 +2968,7 @@ namespace std { template <> struct hash { - std::size_t operator()(const CGAL::SM_Halfedge_index& i) + std::size_t operator()(const CGAL::SM_Halfedge_index& i) const { std::cerr << "SM_Halfege_index HashFct" << std::endl; return i; @@ -2977,27 +2977,24 @@ namespace std { template <> struct hash { - std::size_t operator()(const CGAL::SM_Vertex_index& i) + std::size_t operator()(const CGAL::SM_Vertex_index& i) const { - std::cerr << "SM_Vertex_index HashFct" << std::endl; return i; } }; template <> struct hash { - std::size_t operator()(const CGAL::SM_Face_index& i) + std::size_t operator()(const CGAL::SM_Face_index& i) const { - std::cerr << "SM_Face_index HashFct" << std::endl; return i; } }; template <> struct hash { - std::size_t operator()(const CGAL::SM_Edge_index& i) + std::size_t operator()(const CGAL::SM_Edge_index& i) const { - std::cerr << "SM_Edge_index HashFct" << std::endl; return i; } }; From 0c2a568d7382078f51d844544a5791ecab6df643 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 Apr 2015 10:40:03 +0200 Subject: [PATCH 14/47] better coverage of the combinations of mesh and map classes --- Hash_map/benchmark/Hash_map/hm.cpp | 152 ++++++++++++------ STL_Extension/include/CGAL/Iterator_range.h | 11 +- .../include/CGAL/Surface_mesh/Surface_mesh.h | 11 ++ 3 files changed, 126 insertions(+), 48 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index 2883fad2ef8..413c3b610c5 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -13,82 +13,140 @@ #include #include #include - +#include #include +#include +#include +#include typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3; +typedef Kernel::Vector_3 Vector_3; -typedef CGAL::Surface_mesh Surface_mesh; -typedef CGAL::Polyhedron_3 Polyhedron_3; typedef CGAL::Timer Timer; -template +template void -run(char* fname) +run(const G& g) { typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - G g; - std::ifstream input(fname); - input >> g; - typedef typename boost::property_map::type VPM; + typedef typename boost::property_map::const_type VPM; VPM vpm = get(CGAL::vertex_point,g); - std::vector V; + std::vector V, V2; std::vector P1, P2; BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ V.push_back(vd); + V2.push_back(vd); } - std::random_shuffle(V.begin(), V.end()); - std::map vm; - boost::unordered_map vum; - BOOST_FOREACH(vertex_descriptor vd, V){ - vm[vd] = get(vpm,vd); - vum[vd] = get(vpm,vd); - - } + boost::rand48 random; + boost::random_number_generator rng(random); + std::random_shuffle(V.begin(), V.end(), rng); Timer t; t.start(); - for(int i= 0; i < 1; i++){ - BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ - P1.push_back(vm[vd]); - /* - if(vm[vd] != get(vpm,vd)){ - std::cerr << "error1" << std::endl; - } - */ + Map vm; + BOOST_FOREACH(vertex_descriptor vd, V){ + vm[vd] = get(vpm,vd); } + t.stop(); std::cerr << "Insertion: " << t.time() << " sec. " << std::endl; + + Vector_3 v(0,0,0); + + std::cerr << "BOOST_FOREACH std::vector::iterator it = vum.find(vd); - P2.push_back((*it).second); - /* - if(vum[vd] != get(vpm,vd)){ - std::cerr << "error2" << std::endl; - } - */ + + t.stop(); std::cerr << " " <::vertex_iterator> r = vertices(g); + BOOST_FOREACH(vertex_descriptor& vd, r) { + typename Map::iterator it = vm.find(vd); + v = v + ((*it).second - CGAL::ORIGIN); } + t.stop(); std::cerr << " " <::vertex_iterator> ir = vertices(g); + BOOST_FOREACH(vertex_descriptor& vd, ir) { + typename Map::iterator it = vm.find(vd); + v = v + ((*it).second - CGAL::ORIGIN); } - t.stop(); - std::cerr << t.time() << " sec."<< std::endl; - if(P1.size() != P2.size()){ - std::cerr << "error3" << std::endl; - } + t.stop(); std::cerr << " " <::vertex_iterator vb, ve; + boost::tie(vb,ve) = vertices(g); + for(; vb != ve; ++vb) { + vertex_descriptor vd = *vb; + typename Map::iterator it = vm.find(vd); + v = v + ((*it).second - CGAL::ORIGIN); + } + t.stop(); std::cerr << " " <(m); + std::cerr << "\nSurface_mesh std::unordered_map"<< std::endl; + run(m); + std::cerr << "\nSurface_mesh boost::unordered_map"<< std::endl; + run(m); + } + + { + typedef CGAL::Polyhedron_3 Mesh; + typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef std::map SM; + typedef std::unordered_map SUM; + typedef boost::unordered_map BUM; + + Mesh m; + std::ifstream input(argv[1]); + input >> m; + + std::cerr << "\nPolyhedron_3 std::map" << std::endl; + run(m); + std::cerr << "\nPolyhedron_3 std::unordered_map"<< std::endl; + run(m); + std::cerr << "\nPolyhedron_3 boost::unordered_map"<< std::endl; + run(m); + } + + return 0; } diff --git a/STL_Extension/include/CGAL/Iterator_range.h b/STL_Extension/include/CGAL/Iterator_range.h index 01ba4980248..3d356fc25c7 100644 --- a/STL_Extension/include/CGAL/Iterator_range.h +++ b/STL_Extension/include/CGAL/Iterator_range.h @@ -22,7 +22,7 @@ #include #include - +#include namespace CGAL { @@ -92,4 +92,13 @@ namespace CGAL { } } // namespace CGAL + +namespace boost { namespace foreach +{ + template + struct is_lightweight_proxy< CGAL::Iterator_range > + : mpl::true_ + { + }; +}} #endif // CGAL_ITERATOR_RANGE_H diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 5a04a81b4b4..394f45ae1a8 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -123,6 +123,7 @@ namespace CGAL { template std::size_t hash_value(const SM_Index& i) { + std::cerr << "hash_value" << std::endl; std::size_t ret = i; return ret; } @@ -3000,5 +3001,15 @@ namespace std { }; } +namespace boost { + template <> + struct hash { + std::size_t operator()(const CGAL::SM_Vertex_index& i) const + { + // std::cerr <<"hash"< Date: Mon, 20 Apr 2015 14:32:52 +0200 Subject: [PATCH 15/47] divide by sizeof(pointee) in the hash --- STL_Extension/include/CGAL/In_place_list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 88bd11cb416..b04f22b70a8 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -178,7 +178,7 @@ template std::size_t hash_value(const In_place_list_iterator& i) { T* ptr = &*i; - return reinterpret_cast(ptr); + return reinterpret_cast(ptr)/ sizeof(T); } @@ -186,7 +186,7 @@ template std::size_t hash_value(const In_place_list_const_iterator& i) { T* ptr = &*i; - return reinterpret_cast(ptr); + return reinterpret_cast(ptr)/ sizeof(T); } } From 6f5b92796878a01b4249551f818b4ff37c281581 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 Apr 2015 14:33:27 +0200 Subject: [PATCH 16/47] Add hashing plain pointers --- Hash_map/benchmark/Hash_map/hm.cpp | 46 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index 413c3b610c5..c1f114e3f68 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -107,6 +107,11 @@ run(const G& g) std::cerr << "v = " << v << std::endl; } +struct blob { + int a, b, c, d, e, f, g; +}; + + int main(int , char* argv[]) { @@ -120,7 +125,7 @@ int main(int , char* argv[]) Mesh m; std::ifstream input(argv[1]); input >> m; - + std::cerr << num_vertices(m) << " items\n"; std::cerr << "\nSurface_mesh std::map"<< std::endl; run(m); std::cerr << "\nSurface_mesh std::unordered_map"<< std::endl; @@ -145,8 +150,43 @@ int main(int , char* argv[]) std::cerr << "\nPolyhedron_3 std::unordered_map"<< std::endl; run(m); std::cerr << "\nPolyhedron_3 boost::unordered_map"<< std::endl; - run(m); + run(m); } + + { + const int N = 3165798; + std::cerr << "\nHashing "<< N << " pointers\n"; + std::vector ints(N); - return 0; + std::vector data(N); + for(int i =0; i um; + Timer t; + t.start(); + for(int i= 0; i < N; i++){ + um[& (data[ints[i]])] = i; + } + t.stop(); + std::cerr << " boost::unordered_map: " << t.time() << " sec.\n"; + } + + { + std::unordered_map um; + Timer t; + t.start(); + for(int i= 0; i < N; i++){ + um[& (data[ints[i]])] = i; + } + t.stop(); + std::cerr << " std::unordered_map: " << t.time() << " sec.\n"; + } + } + + return 0; } From d74567a177c0cc9b48355fec65192969cc35bc2c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 Apr 2015 16:11:08 +0200 Subject: [PATCH 17/47] WIP --- Hash_map/benchmark/Hash_map/hm.cpp | 22 +++++++++++---------- STL_Extension/include/CGAL/Iterator_range.h | 15 ++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index c1f114e3f68..7c8b83af85a 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -35,7 +35,6 @@ run(const G& g) typedef typename boost::property_map::const_type VPM; VPM vpm = get(CGAL::vertex_point,g); - std::vector V, V2; std::vector P1, P2; BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ @@ -69,16 +68,17 @@ run(const G& g) std::cerr << "BOOST_FOREACH boost::iterator_range r = vertices(g))\n"; t.reset(); t.start(); boost::iterator_range::vertex_iterator> r = vertices(g); - BOOST_FOREACH(vertex_descriptor& vd, r) { + BOOST_FOREACH(vertex_descriptor vd, r) { typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); } t.stop(); std::cerr << " " <::vertex_iterator> ir = vertices(g); - BOOST_FOREACH(vertex_descriptor& vd, ir) { + BOOST_FOREACH(vertex_descriptor vd, ir) { typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); } @@ -91,7 +91,7 @@ run(const G& g) v = v + ((*it).second - CGAL::ORIGIN); } t.stop(); std::cerr << " " <(m); + //std::cerr << num_vertices(m) << " items\n"; + //std::cerr << "\nSurface_mesh std::map"<< std::endl; + //run(m); std::cerr << "\nSurface_mesh std::unordered_map"<< std::endl; run(m); std::cerr << "\nSurface_mesh boost::unordered_map"<< std::endl; run(m); } - +#if 0 { typedef CGAL::Polyhedron_3 Mesh; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; @@ -187,6 +188,7 @@ int main(int , char* argv[]) std::cerr << " std::unordered_map: " << t.time() << " sec.\n"; } } - +#endif + return 0; } diff --git a/STL_Extension/include/CGAL/Iterator_range.h b/STL_Extension/include/CGAL/Iterator_range.h index 3d356fc25c7..f4448dac400 100644 --- a/STL_Extension/include/CGAL/Iterator_range.h +++ b/STL_Extension/include/CGAL/Iterator_range.h @@ -45,6 +45,11 @@ namespace CGAL { : Base(b,e) {} + + // Iterator_range(const Iterator_range& ip) + // : Base(ip) + // {} + Iterator_range(const std::pair& ip) : Base(ip) {} @@ -90,9 +95,19 @@ namespace CGAL { { return x.second; } + + + } // namespace CGAL +// At global scope... + template +inline boost::mpl::true_ * + boost_foreach_is_lightweight_proxy( CGAL::Iterator_range *&, boost::foreach::tag ) +{ + return 0; +} namespace boost { namespace foreach { template From 187f7e247d8c99d96939bbb71c8440b6cc3927d4 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 Apr 2015 17:47:27 +0200 Subject: [PATCH 18/47] Add a #define so that one does not hash --- Hash_map/benchmark/Hash_map/CMakeLists.txt | 1 + Hash_map/benchmark/Hash_map/hm.cpp | 49 ++++++++++++++++++---- Stream_support/include/CGAL/IO/io.h | 1 + 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/CMakeLists.txt b/Hash_map/benchmark/Hash_map/CMakeLists.txt index 394642f4ade..9e87d76f426 100644 --- a/Hash_map/benchmark/Hash_map/CMakeLists.txt +++ b/Hash_map/benchmark/Hash_map/CMakeLists.txt @@ -58,5 +58,6 @@ include_directories( BEFORE ../../include ) include( CGAL_CreateSingleSourceCGALProgram ) create_single_source_cgal_program( "hm.cpp" ) +create_single_source_cgal_program( "foreach.cpp" ) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index 7c8b83af85a..8a07d7dbdcb 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -1,3 +1,4 @@ +#define NOHASH 1 #include #include @@ -37,15 +38,18 @@ run(const G& g) std::vector V, V2; std::vector P1, P2; + BOOST_FOREACH(vertex_descriptor vd, vertices(g)){ V.push_back(vd); V2.push_back(vd); } - + boost::rand48 random; boost::random_number_generator rng(random); std::random_shuffle(V.begin(), V.end(), rng); - + for(int i=0; i < 10; i++){ + std::cerr << get(vpm,V[i]) << std::endl; + } Timer t; t.start(); Map vm; @@ -58,50 +62,79 @@ run(const G& g) std::cerr << "BOOST_FOREACH std::vector::vertex_iterator> r = vertices(g); BOOST_FOREACH(vertex_descriptor vd, r) { +#ifdef NOHASH + v = v + (get(vpm,vd) - CGAL::ORIGIN); +#else typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); +#endif + } } t.stop(); std::cerr << " " <::vertex_iterator> ir = vertices(g); BOOST_FOREACH(vertex_descriptor vd, ir) { +#ifdef NOHASH + v = v + (get(vpm,vd) - CGAL::ORIGIN); +#else typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); +#endif + } } t.stop(); std::cerr << " " <::vertex_iterator vb, ve; boost::tie(vb,ve) = vertices(g); for(; vb != ve; ++vb) { vertex_descriptor vd = *vb; +#ifdef NOHASH + v = v + (get(vpm,vd) - CGAL::ORIGIN); +#else typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); +#endif } + } t.stop(); std::cerr << " " <(m); + std::cerr << num_vertices(m) << " items\n"; + std::cerr << "\nSurface_mesh std::map"<< std::endl; + run(m); std::cerr << "\nSurface_mesh std::unordered_map"<< std::endl; run(m); std::cerr << "\nSurface_mesh boost::unordered_map"<< std::endl; run(m); } -#if 0 +#if 1 { typedef CGAL::Polyhedron_3 Mesh; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index 3e16c8d18b6..d416f268630 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -140,6 +140,7 @@ public: } }while(true); + std::cerr << "|" << buffer.c_str() << "|" << std::endl; if(sscanf(buffer.c_str(), "%lf", &t) != 1) { // if a 'buffer' does not contain a double, set the fail bit. is.setstate(std::ios_base::failbit); From 5454a9d05756da71d76d402e412b5b57f07240dd Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 21 Apr 2015 09:44:32 +0200 Subject: [PATCH 19/47] just test BOOST_FOREACH not containers --- Hash_map/benchmark/Hash_map/hm.cpp | 44 ++++++++++++++++++++--------- Stream_support/include/CGAL/IO/io.h | 1 - 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index 8a07d7dbdcb..d2d606c4498 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -47,25 +47,27 @@ run(const G& g) boost::rand48 random; boost::random_number_generator rng(random); std::random_shuffle(V.begin(), V.end(), rng); - for(int i=0; i < 10; i++){ - std::cerr << get(vpm,V[i]) << std::endl; - } + Timer t; +#if 0 t.start(); Map vm; BOOST_FOREACH(vertex_descriptor vd, V){ vm[vd] = get(vpm,vd); } t.stop(); std::cerr << "Insertion: " << t.time() << " sec. " << std::endl; +#endif Vector_3 v(0,0,0); + std::size_t st=0; +#if 0 std::cerr << "BOOST_FOREACH std::vector::vertex_iterator> r = vertices(g); + for(int i=0; i<100; i++){ + BOOST_FOREACH(vertex_descriptor vd, r) { #ifdef NOHASH - v = v + (get(vpm,vd) - CGAL::ORIGIN); + st += std::size_t(vd); + // v = v + (get(vpm,vd) - CGAL::ORIGIN); #else typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); @@ -93,11 +100,12 @@ run(const G& g) std::cerr << "BOOST_FOREACH CGAL::Iterator_range r = vertices(g))\n"; t.reset(); t.start(); - for(int i=0; i<100; i++){ CGAL::Iterator_range::vertex_iterator> ir = vertices(g); + for(int i=0; i<100; i++){ BOOST_FOREACH(vertex_descriptor vd, ir) { -#ifdef NOHASH - v = v + (get(vpm,vd) - CGAL::ORIGIN); +#ifdef NOHASH + st += std::size_t(vd); + //v = v + (get(vpm,vd) - CGAL::ORIGIN); #else typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); @@ -110,8 +118,9 @@ run(const G& g) t.reset(); t.start(); for(int i=0; i<100; i++){ BOOST_FOREACH(vertex_descriptor vd, vertices(g)) { -#ifdef NOHASH - v = v + (get(vpm,vd) - CGAL::ORIGIN); +#ifdef NOHASH + st += std::size_t(vd); + //v = v + (get(vpm,vd) - CGAL::ORIGIN); #else typename Map::iterator it = vm.find(vd); v = v + ((*it).second - CGAL::ORIGIN); @@ -120,6 +129,7 @@ run(const G& g) } t.stop(); std::cerr << " " <(m); +#if 0 std::cerr << "\nSurface_mesh std::unordered_map"<< std::endl; run(m); std::cerr << "\nSurface_mesh boost::unordered_map"<< std::endl; run(m); +#endif } -#if 1 + +#if 0 { typedef CGAL::Polyhedron_3 Mesh; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index d416f268630..3e16c8d18b6 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -140,7 +140,6 @@ public: } }while(true); - std::cerr << "|" << buffer.c_str() << "|" << std::endl; if(sscanf(buffer.c_str(), "%lf", &t) != 1) { // if a 'buffer' does not contain a double, set the fail bit. is.setstate(std::ios_base::failbit); From d2f22bfc82e3b432c688fdd291e57b94e2204641 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 21 Apr 2015 11:49:06 +0200 Subject: [PATCH 20/47] Add C++11 for loop --- Hash_map/benchmark/Hash_map/hm.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index d2d606c4498..5556b2df0a6 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -128,7 +128,27 @@ run(const G& g) } } t.stop(); std::cerr << " " < Date: Tue, 21 Apr 2015 11:57:45 +0200 Subject: [PATCH 21/47] remove free functions in Iterator_range --- STL_Extension/include/CGAL/Iterator_range.h | 25 --------------------- 1 file changed, 25 deletions(-) diff --git a/STL_Extension/include/CGAL/Iterator_range.h b/STL_Extension/include/CGAL/Iterator_range.h index f4448dac400..6db854dfde6 100644 --- a/STL_Extension/include/CGAL/Iterator_range.h +++ b/STL_Extension/include/CGAL/Iterator_range.h @@ -72,31 +72,6 @@ namespace CGAL { return Iterator_range(b,e); } - template - inline T range_begin( Iterator_range & x ) - { - return x.first; - } - - template - inline T range_end( Iterator_range & x ) - { - return x.second; - } - - template - inline T range_begin(const Iterator_range& x ) - { - return x.first; - } - - template - inline T range_end(const Iterator_range& x ) - { - return x.second; - } - - } // namespace CGAL From 62700ded92566f110bd55a8e98f9645d7ea4c233 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 21 Apr 2015 12:26:50 +0200 Subject: [PATCH 22/47] a bench for a vector --- BGL/include/CGAL/boost/graph/helpers.h | 3 +- Hash_map/benchmark/Hash_map/foreach.cpp | 43 +++++++++++++++++++++++++ Hash_map/benchmark/Hash_map/hm.cpp | 12 +++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Hash_map/benchmark/Hash_map/foreach.cpp diff --git a/BGL/include/CGAL/boost/graph/helpers.h b/BGL/include/CGAL/boost/graph/helpers.h index 5bdb9470178..4660ec58f39 100644 --- a/BGL/include/CGAL/boost/graph/helpers.h +++ b/BGL/include/CGAL/boost/graph/helpers.h @@ -165,7 +165,8 @@ template bool is_pure_triangle(const FaceGraph& g) { typedef typename boost::graph_traits::face_descriptor face_descriptor; - BOOST_FOREACH(face_descriptor fd, faces(g)){ + // BOOST_FOREACH(face_descriptor fd, faces(g)){ + for(face_descriptor fd : faces(g)){ if(! is_triangle(fd,g)){ return false; } diff --git a/Hash_map/benchmark/Hash_map/foreach.cpp b/Hash_map/benchmark/Hash_map/foreach.cpp new file mode 100644 index 00000000000..3e8b9859af1 --- /dev/null +++ b/Hash_map/benchmark/Hash_map/foreach.cpp @@ -0,0 +1,43 @@ +#include +#include + +#include +#include + +#include +#include +#include + +typedef CGAL::Timer Timer; + +int main() +{ + int N = 100000; + std::vector V(N), V2(N); + + Timer t; + + t.start(); + for(int k=0; k < N; k++){ + boost::iterator_range::iterator> bir(V.begin(), V.end()); + int j = 0; + BOOST_FOREACH(int i, bir){ + V2[j++] = i; + } + } + t.stop(); + std::cerr << "boost::iterator_range: " << t.time() << "sec.\n"; + + t.reset(); + t.start(); + for(int k=0; k < N; k++){ + int j = 0; + BOOST_FOREACH(int i, CGAL::make_range(V.begin(), V.end())){ + V2[j++] = i; + } + } + t.stop(); + std::cerr << "CGAL::iterator_range: " << t.time() << "sec.\n"; + + return 0; +} diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index 5556b2df0a6..010fa01925c 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -192,6 +193,17 @@ int main(int , char* argv[]) Mesh m; std::ifstream input(argv[1]); input >> m; + + Timer t; + t.start(); + if(is_pure_triangle(m)) + { + std::cerr << "is pure triangle" << std::endl; + } + t.stop(); + std::cerr << t.time() << std::endl; + return 0; + std::cerr << num_vertices(m) << " items\n"; std::cerr << "\nSurface_mesh std::map"<< std::endl; run(m); From e9766c0ffdb8746d9e3db31d50df21b57f82ac9c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 21 Apr 2015 13:24:10 +0200 Subject: [PATCH 23/47] slight change of Index_iterator::increment --- BGL/include/CGAL/boost/graph/helpers.h | 3 +- Hash_map/benchmark/Hash_map/hm.cpp | 28 ++++++++----------- .../include/CGAL/Surface_mesh/Surface_mesh.h | 14 +++++++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/helpers.h b/BGL/include/CGAL/boost/graph/helpers.h index 4660ec58f39..5bdb9470178 100644 --- a/BGL/include/CGAL/boost/graph/helpers.h +++ b/BGL/include/CGAL/boost/graph/helpers.h @@ -165,8 +165,7 @@ template bool is_pure_triangle(const FaceGraph& g) { typedef typename boost::graph_traits::face_descriptor face_descriptor; - // BOOST_FOREACH(face_descriptor fd, faces(g)){ - for(face_descriptor fd : faces(g)){ + BOOST_FOREACH(face_descriptor fd, faces(g)){ if(! is_triangle(fd,g)){ return false; } diff --git a/Hash_map/benchmark/Hash_map/hm.cpp b/Hash_map/benchmark/Hash_map/hm.cpp index 010fa01925c..2b285142f8f 100644 --- a/Hash_map/benchmark/Hash_map/hm.cpp +++ b/Hash_map/benchmark/Hash_map/hm.cpp @@ -79,12 +79,12 @@ run(const G& g) t.stop(); std::cerr << " " <::vertex_iterator> r = vertices(g); for(int i=0; i<100; i++){ + boost::iterator_range::vertex_iterator> r = vertices(g); BOOST_FOREACH(vertex_descriptor vd, r) { #ifdef NOHASH @@ -97,12 +97,14 @@ run(const G& g) } } t.stop(); std::cerr << " " <::vertex_iterator> ir = vertices(g); for(int i=0; i<100; i++){ + CGAL::Iterator_range::vertex_iterator> ir = vertices(g); BOOST_FOREACH(vertex_descriptor vd, ir) { #ifdef NOHASH st += std::size_t(vd); @@ -115,6 +117,10 @@ run(const G& g) } t.stop(); std::cerr << " " <> m; - Timer t; - t.start(); - if(is_pure_triangle(m)) - { - std::cerr << "is pure triangle" << std::endl; - } - t.stop(); - std::cerr << t.time() << std::endl; - return 0; - std::cerr << num_vertices(m) << " items\n"; std::cerr << "\nSurface_mesh std::map"<< std::endl; run(m); diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 394f45ae1a8..172c16b04b4 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -951,8 +951,9 @@ private: //------------------------------------------------------ iterator types Index_iterator() : hnd_(), mesh_(NULL) {} Index_iterator(const Index_& h, const Surface_mesh* m) : hnd_(h), mesh_(m) { - if (mesh_ && mesh_->has_garbage()) + if (mesh_ && mesh_->has_garbage()){ while (mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) ++hnd_; + } } private: friend class boost::iterator_core_access; @@ -960,14 +961,17 @@ private: //------------------------------------------------------ iterator types { ++hnd_; CGAL_assertion(mesh_ != NULL); - while (mesh_->has_garbage() && mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) ++hnd_; + bool hg = mesh_->has_garbage(); + if(hg) + while ( mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) ++hnd_; } void decrement() { --hnd_; CGAL_assertion(mesh_ != NULL); - while (mesh_->has_garbage() && mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) --hnd_; + if(mesh_->has_garbage()) + while ( mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) --hnd_; } bool equal(const Index_iterator& other) const @@ -979,6 +983,7 @@ private: //------------------------------------------------------ iterator types Index_ hnd_; const Surface_mesh* mesh_; + }; public: /// \name Range Types @@ -1644,7 +1649,8 @@ public: bool has_valid_index(Vertex_index v) const { return ((size_type)v < num_vertices()); - } + } + /// returns whether the index of halfedge `h` is valid, that is within the current array bounds. bool has_valid_index(Halfedge_index h) const { From 6dbdea042958d22d49ca422853c3e7394b54c661 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 21 Apr 2015 13:44:26 +0200 Subject: [PATCH 24/47] The results on this version with VC11 boost 1_55 are: $ ./build/hm.exe data/iphi.off 3165798 items Surface_mesh std::map BOOST_FOREACH boost::iterator_range r = vertices(g)) 0.53 sec. BOOST_FOREACH CGAL::Iterator_range r = vertices(g)) 0.13 sec. BOOST_FOREACH vertices(g)) 1.49 sec. for vertices(g)) 0.18 sec. v = 0 0 0 2004454762201200 --- Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 172c16b04b4..357f6159abd 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -961,11 +961,11 @@ private: //------------------------------------------------------ iterator types { ++hnd_; CGAL_assertion(mesh_ != NULL); - bool hg = mesh_->has_garbage(); - if(hg) + + if(mesh_->has_garbage()) while ( mesh_->has_valid_index(hnd_) && mesh_->is_removed(hnd_)) ++hnd_; } - + void decrement() { --hnd_; From 6f42513e5866ffbc536a798b748cf9a811d7790b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 27 Apr 2015 13:44:18 +0200 Subject: [PATCH 25/47] divide by sizeof(pointee) for Compact_container --- Hash_map/benchmark/Hash_map/CMakeLists.txt | 1 + STL_Extension/include/CGAL/Compact_container.h | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/CMakeLists.txt b/Hash_map/benchmark/Hash_map/CMakeLists.txt index 9e87d76f426..9668eeef59b 100644 --- a/Hash_map/benchmark/Hash_map/CMakeLists.txt +++ b/Hash_map/benchmark/Hash_map/CMakeLists.txt @@ -59,5 +59,6 @@ include( CGAL_CreateSingleSourceCGALProgram ) create_single_source_cgal_program( "hm.cpp" ) create_single_source_cgal_program( "foreach.cpp" ) +create_single_source_cgal_program( "triangulation.cpp" ) diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 72cb2e835fd..6fc20576f93 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -1162,7 +1162,7 @@ namespace internal { template std::size_t hash_value(const CC_iterator& i) { - return reinterpret_cast(&*i); + return reinterpret_cast(&*i) / sizeof(typename DSC::value_type); } } // namespace internal @@ -1176,8 +1176,7 @@ namespace std { struct hash > { std::size_t operator()(const CGAL::internal::CC_iterator& i) const { - std::cerr << "CC::iterator HashFct" << std::endl; - return reinterpret_cast(&*i); + return reinterpret_cast(&*i) / sizeof(typename DSC::value_type); } }; } From e0af3613ee7d6088355a3ba26331ac5dbb20272e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 27 Apr 2015 13:51:57 +0200 Subject: [PATCH 26/47] add a bench --- Hash_map/benchmark/Hash_map/triangulation.cpp | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 Hash_map/benchmark/Hash_map/triangulation.cpp diff --git a/Hash_map/benchmark/Hash_map/triangulation.cpp b/Hash_map/benchmark/Hash_map/triangulation.cpp new file mode 100644 index 00000000000..c1b757e539d --- /dev/null +++ b/Hash_map/benchmark/Hash_map/triangulation.cpp @@ -0,0 +1,127 @@ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_2 Point_2; +typedef Kernel::Vector_2 Vector_2; +typedef CGAL::Creator_uniform_2 Pt_creator; +typedef CGAL::Random_points_in_disc_2 Random_points;; +typedef CGAL::Delaunay_triangulation_2 Dt; +typedef Dt::Vertex_handle Vertex_handle; +typedef Dt::Finite_vertices_iterator Finite_vertices_iterator; + +typedef CGAL::Timer Timer; + + + + + +void fct(int ii, int jj) +{ + typedef std::map SM; + typedef std::unordered_map SUM; + typedef boost::unordered_map BUM; + + Dt dt; + Vector_2 v(0,0,0); + Random_points rp( 250); + std::vector points; + for(int i =0; i < ii; i++){ + Point_2 p = *rp++; + points.push_back(p); + } + + dt.insert(points.begin(), points.end()); + + std::vector vertices; + Finite_vertices_iterator b = dt.finite_vertices_begin(), e = dt.finite_vertices_end(); + for(; b!=e; ++b){ + vertices.push_back(b); + } + random_shuffle(vertices.begin(), vertices.end()); + + Timer tsmc, tsumc, tbumc; + Timer tsmq, tsumq, tbumq; + for(int j=0; j point(); + } + tsmc.stop(); + + + tsmq.start(); + for(Vertex_handle vh : vertices){ + v = v + (sm[vh] - CGAL::ORIGIN); + } + tsmq.stop(); + } + { + tsumc.start(); + SUM sm; + for(Vertex_handle vh : vertices){ + sm[vh] = vh->point(); + } + tsumc.stop(); + + + tsumq.start(); + for(Vertex_handle vh : vertices){ + v = v + (sm[vh] - CGAL::ORIGIN); + } + tsumq.stop(); + } + { + tbumc.start(); + BUM sm; + for(Vertex_handle vh : vertices){ + sm[vh] = vh->point(); + } + tbumc.stop(); + + + tbumq.start(); + for(Vertex_handle vh : vertices){ + v = v + (sm[vh] - CGAL::ORIGIN); + } + tbumq.stop(); + } + } + std::cerr << ii << " items and queries (repeated " << jj << " times)" << std::endl; + std::cerr << "std::map construction : "<< tsmc.time() << " sec." << std::endl; + std::cerr << "std::map queries : "<< tsmq.time() << " sec." << std::endl; + + std::cerr << "std::unordered_map construction : "<< tsumc.time() << " sec." << std::endl; + std::cerr << "std::unordered_map queries : "<< tsumq.time() << " sec." << std::endl; + + std::cerr << "boost::unordered_map construction : "<< tbumc.time() << " sec." << std::endl; + std::cerr << "boost::unordered_map queries : "<< tbumq.time() << " sec.\n" << std::endl; +} + +int main(int , char* argv[]) +{ + fct(1000000, 10); + fct(100000, 100); + fct(10000, 1000); + fct(1000, 10000); + fct(100, 100000); + return 0; +} From 8f96587c1f973731524fb2c0209f964f9e4fa964 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 27 Apr 2015 14:47:51 +0200 Subject: [PATCH 27/47] add bench for Polyhedron_3 and Surface_mesh --- Hash_map/benchmark/Hash_map/CMakeLists.txt | 2 + Hash_map/benchmark/Hash_map/polyhedron.cpp | 131 ++++++++++++++++++ Hash_map/benchmark/Hash_map/surface_mesh.cpp | 131 ++++++++++++++++++ Hash_map/benchmark/Hash_map/triangulation.cpp | 2 + 4 files changed, 266 insertions(+) create mode 100644 Hash_map/benchmark/Hash_map/polyhedron.cpp create mode 100644 Hash_map/benchmark/Hash_map/surface_mesh.cpp diff --git a/Hash_map/benchmark/Hash_map/CMakeLists.txt b/Hash_map/benchmark/Hash_map/CMakeLists.txt index 9668eeef59b..1458021afb5 100644 --- a/Hash_map/benchmark/Hash_map/CMakeLists.txt +++ b/Hash_map/benchmark/Hash_map/CMakeLists.txt @@ -60,5 +60,7 @@ include( CGAL_CreateSingleSourceCGALProgram ) create_single_source_cgal_program( "hm.cpp" ) create_single_source_cgal_program( "foreach.cpp" ) create_single_source_cgal_program( "triangulation.cpp" ) +create_single_source_cgal_program( "polyhedron.cpp" ) +create_single_source_cgal_program( "surface_mesh.cpp" ) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp new file mode 100644 index 00000000000..5a887231b38 --- /dev/null +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -0,0 +1,131 @@ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Vector_3 Vector_3; + + +typedef CGAL::Polyhedron_3 Mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +typedef CGAL::Timer Timer; + + + +void fct(int ii, int jj) +{ + typedef std::map SM; + typedef std::unordered_map SUM; + typedef boost::unordered_map BUM; + + Mesh mesh; + typedef boost::property_map::type VPM; + VPM vpm = get(CGAL::vertex_point,mesh); + + + Vector_3 v(0,0,0); + + for(int i =0; i < ii; i++){ + vertex_descriptor vd = add_vertex(mesh); + put(vpm,vd, Point_3(i,0,0)); + } + + std::vector V; + for(vertex_descriptor vd : vertices(mesh)){ + V.push_back(vd); + } + random_shuffle(V.begin(), V.end()); + + + Timer tsmc, tsumc, tbumc; + Timer tsmq, tsumq, tbumq; + for(int j=0; j +#include +#include +#include + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Vector_3 Vector_3; + + +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +typedef CGAL::Timer Timer; + + + +void fct(int ii, int jj) +{ + typedef std::map SM; + typedef std::unordered_map SUM; + typedef boost::unordered_map BUM; + + Mesh mesh; + typedef boost::property_map::type VPM; + VPM vpm = get(CGAL::vertex_point,mesh); + + + Vector_3 v(0,0,0); + + for(int i =0; i < ii; i++){ + vertex_descriptor vd = add_vertex(mesh); + put(vpm,vd, Point_3(i,0,0)); + } + + std::vector V; + for(vertex_descriptor vd : vertices(mesh)){ + V.push_back(vd); + } + random_shuffle(V.begin(), V.end()); + + + Timer tsmc, tsumc, tbumc; + Timer tsmq, tsumq, tbumq; + for(int j=0; j Date: Wed, 29 Apr 2015 14:30:36 +0200 Subject: [PATCH 28/47] Add std::hash and boost::hash for the arrangement --- .../Arrangement_2/Arrangement_2_iterators.h | 98 +++++++++++++++++++ Hash_map/benchmark/Hash_map/CMakeLists.txt | 1 + Hash_map/benchmark/Hash_map/arrangement.cpp | 40 ++++++++ 3 files changed, 139 insertions(+) create mode 100644 Hash_map/benchmark/Hash_map/arrangement.cpp diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h index 779b9e6efb0..1fde617881b 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h @@ -340,6 +340,11 @@ public: return !(*this == it); } + bool operator< (const Self& it) const + { + return &(**this) < (&*it); + } + /*! Dereferencing operators. */ reference operator*() const { @@ -495,6 +500,11 @@ public: return !(*this == it); } + bool operator< (const Self& it) const + { + return &(**this) < (&*it); + } + /*! Dereferencing operators. */ reference operator*() const { @@ -545,4 +555,92 @@ public: } //namespace CGAL +namespace std { + template struct hash; + +template +struct hash > { + + typedef CGAL::I_Filtered_const_iterator I; + + std::size_t operator()(const I& i) const + { + return reinterpret_cast(&*i) / sizeof(Value_); + } + }; + + template + struct hash > { + typedef CGAL::I_Filtered_iterator I; + + std::size_t operator()(const I& i) const + { + return reinterpret_cast(&*i) / sizeof(typename I::value_type); + } + }; +} +namespace boost { + template struct hash; + +template +struct hash > { + + typedef CGAL::I_Filtered_const_iterator I; + + std::size_t operator()(const I& i) const + { + return reinterpret_cast(&*i) / sizeof(Value_); + } + }; + + template + struct hash > { + typedef CGAL::I_Filtered_iterator I; + + std::size_t operator()(const I& i) const + { + return reinterpret_cast(&*i) / sizeof(typename I::value_type); + } + }; +} #endif diff --git a/Hash_map/benchmark/Hash_map/CMakeLists.txt b/Hash_map/benchmark/Hash_map/CMakeLists.txt index 1458021afb5..bd5473864c9 100644 --- a/Hash_map/benchmark/Hash_map/CMakeLists.txt +++ b/Hash_map/benchmark/Hash_map/CMakeLists.txt @@ -62,5 +62,6 @@ create_single_source_cgal_program( "foreach.cpp" ) create_single_source_cgal_program( "triangulation.cpp" ) create_single_source_cgal_program( "polyhedron.cpp" ) create_single_source_cgal_program( "surface_mesh.cpp" ) +create_single_source_cgal_program( "arrangement.cpp" ) diff --git a/Hash_map/benchmark/Hash_map/arrangement.cpp b/Hash_map/benchmark/Hash_map/arrangement.cpp new file mode 100644 index 00000000000..6a66e260e86 --- /dev/null +++ b/Hash_map/benchmark/Hash_map/arrangement.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +#include +#include + + +typedef int Number_type; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_segment_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::X_monotone_curve_2 Segment_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef Arrangement_2::Vertex_handle Vertex_handle; +typedef Arrangement_2::Halfedge_handle Halfedge_handle; + +int main() +{ + Arrangement_2 arr; + + Segment_2 s1(Point_2(1, 3), Point_2(3, 5)); + Segment_2 s2(Point_2(3, 5), Point_2(5, 3)); + Segment_2 s3(Point_2(5, 3), Point_2(3, 1)); + Segment_2 s4(Point_2(3, 1), Point_2(1, 3)); + Segment_2 s5(Point_2(1, 3), Point_2(5, 3)); + + Halfedge_handle e1 = arr.insert_in_face_interior(s1, arr.unbounded_face()); + Vertex_handle v1 = e1->source(); + + + + std::map sm; + sm[v1]= 1; + std::unordered_map sum; + sum[v1]= 1; + boost::unordered_map bum; + bum[v1]= 1; + return 0; +} From f74173f73cb693f4f885e6310ec3b3e76e3c631c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 4 May 2015 11:54:41 +0200 Subject: [PATCH 29/47] add typename --- Hash_map/test/Hash_map/Hash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp index a05fbff3694..428d152a1c8 100644 --- a/Hash_map/test/Hash_map/Hash.cpp +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -20,7 +20,7 @@ template void fct(const P& p) { - typedef boost::graph_traits

::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits

::vertex_descriptor vertex_descriptor; std::map M; vertex_descriptor vd; From 3491e73509f7d8fbcd0725b43fe7c5eedcee1e99 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 26 May 2015 14:59:20 +0200 Subject: [PATCH 30/47] remove debug output --- Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 357f6159abd..68edc45596e 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2977,7 +2977,6 @@ namespace std { struct hash { std::size_t operator()(const CGAL::SM_Halfedge_index& i) const { - std::cerr << "SM_Halfege_index HashFct" << std::endl; return i; } }; @@ -3012,7 +3011,6 @@ namespace boost { struct hash { std::size_t operator()(const CGAL::SM_Vertex_index& i) const { - // std::cerr <<"hash"< Date: Wed, 27 May 2015 11:33:25 +0200 Subject: [PATCH 31/47] Add concept Hashable --- .../doc/STL_Extension/Concepts/Hashable.h | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 STL_Extension/doc/STL_Extension/Concepts/Hashable.h diff --git a/STL_Extension/doc/STL_Extension/Concepts/Hashable.h b/STL_Extension/doc/STL_Extension/Concepts/Hashable.h new file mode 100644 index 00000000000..1b0df458143 --- /dev/null +++ b/STL_Extension/doc/STL_Extension/Concepts/Hashable.h @@ -0,0 +1,23 @@ + +/*! +\ingroup PkgStlExtensionConcepts +\cgalConcept + +A type `Key` is a model of the concept `Hashable` if the +specializations `boost::hash` and `std::hash` exist. + +\cgalHasModel All handles and indices of \cgal data structures. + + +\sa `CGAL::Unique_hash_map` +\sa `std::unordered_set` +\sa `std::unordered_map` +\sa `boost::unordered_set` +\sa `boost::unordered_map` + +*/ + +class Hashable { + +}; + From 98e160e9989156489778f2a36a230da4b3344265 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 27 May 2015 11:36:02 +0200 Subject: [PATCH 32/47] Polyhedron_3::..._handle are model of Hashable --- Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h b/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h index 2dc4c83dd84..084faf7f2a7 100644 --- a/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h +++ b/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h @@ -837,6 +837,9 @@ public: convenience, the `Point_iterator` enumerates all points in the polyhedral surface in the same order as the `Vertex_iterator`, but with the value type `Point`. Similarly, a `Plane_iterator` is provided. + + + All handles are model of `LessThanComparable` and `Hashable`. */ /// @{ From 425cdf0b0c30664be9afdf26d1cfdeb24a4ee569 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 27 May 2015 12:19:55 +0200 Subject: [PATCH 33/47] derive from unary_function; Add #define switch to hash underlying pointer --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 30 ++++++++++++++--- Hash_map/benchmark/Hash_map/triangulation.cpp | 2 +- .../include/CGAL/Compact_container.h | 4 ++- STL_Extension/include/CGAL/In_place_list.h | 33 ++++++++++++++++--- .../include/CGAL/Surface_mesh/Surface_mesh.h | 16 ++++++--- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index 5a887231b38..8bdbef7faad 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -1,4 +1,4 @@ - +//#define CGAL_USE_HASH_OF_POINTERS #include #include #include @@ -9,7 +9,7 @@ #include #include #include - +#include #include #include @@ -36,6 +36,8 @@ void fct(int ii, int jj) typedef std::map SM; typedef std::unordered_map SUM; typedef boost::unordered_map BUM; + typedef CGAL::Unique_hash_map UHM; + Mesh mesh; typedef boost::property_map::type VPM; @@ -56,8 +58,9 @@ void fct(int ii, int jj) random_shuffle(V.begin(), V.end()); - Timer tsmc, tsumc, tbumc; - Timer tsmq, tsumq, tbumq; + Timer tsmc, tsumc, tbumc, tuhmc; + Timer tsmq, tsumq, tbumq, tuhmq; + for(int j=0; j BUM; Dt dt; - Vector_2 v(0,0,0); + Vector_2 v(0,0); Random_points rp( 250); std::vector points; for(int i =0; i < ii; i++){ diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 6fc20576f93..df521d6e8cb 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -1173,7 +1173,9 @@ namespace std { template struct hash; template < class DSC, bool Const > - struct hash > { + struct hash > + : public std::unary_function, std::size_t> { + std::size_t operator()(const CGAL::internal::CC_iterator& i) const { return reinterpret_cast(&*i) / sizeof(typename DSC::value_type); diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index b04f22b70a8..0ef0fa83994 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -178,7 +178,11 @@ template std::size_t hash_value(const In_place_list_iterator& i) { T* ptr = &*i; +#ifdef CGAL_USE_HASH_OF_POINTERS + return boost::hash_value(ptr); +#else return reinterpret_cast(ptr)/ sizeof(T); +#endif } @@ -186,8 +190,12 @@ template std::size_t hash_value(const In_place_list_const_iterator& i) { T* ptr = &*i; +#ifdef CGAL_USE_HASH_OF_POINTERS + return boost::hash_value(ptr); +#else return reinterpret_cast(ptr)/ sizeof(T); - } +#endif + } } @@ -775,18 +783,33 @@ namespace std { template struct hash; template < class T, class Alloc > - struct hash > { + struct hash > + : public std::unary_function, std::size_t> { + std::size_t operator()(const CGAL::internal::In_place_list_iterator& i) const { - return hash_value(i); + const T* ptr = &*i; +#ifdef CGAL_USE_HASH_OF_POINTERS + return std::hash()(ptr); +#else + return reinterpret_cast(ptr)/ sizeof(T); +#endif } }; template < class T, class Alloc > - struct hash > { + struct hash > + : public std::unary_function, std::size_t> { + std::size_t operator()(const CGAL::internal::In_place_list_const_iterator& i) const { - return hash_value(i); + const T* ptr = &*i; +#ifdef CGAL_USE_HASH_OF_POINTERS + return std::hash()(ptr); +#else + return reinterpret_cast(ptr)/ sizeof(T); +#endif + } }; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 68edc45596e..52b7ce04793 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2974,7 +2974,9 @@ namespace std { template struct hash; template <> - struct hash { + struct hash + : public std::unary_function { + std::size_t operator()(const CGAL::SM_Halfedge_index& i) const { return i; @@ -2982,7 +2984,9 @@ namespace std { }; template <> - struct hash { + struct hash + : public std::unary_function { + std::size_t operator()(const CGAL::SM_Vertex_index& i) const { return i; @@ -2990,7 +2994,9 @@ namespace std { }; template <> - struct hash { + struct hash + : public std::unary_function { + std::size_t operator()(const CGAL::SM_Face_index& i) const { return i; @@ -2998,7 +3004,9 @@ namespace std { }; template <> - struct hash { + struct hash + : public std::unary_function { + std::size_t operator()(const CGAL::SM_Edge_index& i) const { return i; From cf058cba9c6bbf4c80f5af81e2293674b5775a2f Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 27 May 2015 17:02:00 +0200 Subject: [PATCH 34/47] do not use hash of pointers so that our specializations for handles are injective --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 1 - STL_Extension/include/CGAL/In_place_list.h | 17 ----------------- 2 files changed, 18 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index 8bdbef7faad..7dd8567e9b7 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -1,4 +1,3 @@ -//#define CGAL_USE_HASH_OF_POINTERS #include #include #include diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 0ef0fa83994..ff29afcfe59 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -178,11 +178,7 @@ template std::size_t hash_value(const In_place_list_iterator& i) { T* ptr = &*i; -#ifdef CGAL_USE_HASH_OF_POINTERS - return boost::hash_value(ptr); -#else return reinterpret_cast(ptr)/ sizeof(T); -#endif } @@ -190,11 +186,7 @@ template std::size_t hash_value(const In_place_list_const_iterator& i) { T* ptr = &*i; -#ifdef CGAL_USE_HASH_OF_POINTERS - return boost::hash_value(ptr); -#else return reinterpret_cast(ptr)/ sizeof(T); -#endif } } @@ -789,11 +781,7 @@ namespace std { std::size_t operator()(const CGAL::internal::In_place_list_iterator& i) const { const T* ptr = &*i; -#ifdef CGAL_USE_HASH_OF_POINTERS - return std::hash()(ptr); -#else return reinterpret_cast(ptr)/ sizeof(T); -#endif } }; @@ -804,12 +792,7 @@ namespace std { std::size_t operator()(const CGAL::internal::In_place_list_const_iterator& i) const { const T* ptr = &*i; -#ifdef CGAL_USE_HASH_OF_POINTERS - return std::hash()(ptr); -#else return reinterpret_cast(ptr)/ sizeof(T); -#endif - } }; } From a58e0247887cb6996b5be13b4e1ed66f37978103 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 28 May 2015 09:15:37 +0200 Subject: [PATCH 35/47] Fix dependencies. Add links to std/boost::unordered_.. --- STL_Extension/doc/STL_Extension/Concepts/Hashable.h | 10 +++++----- STL_Extension/doc/STL_Extension/dependencies | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/STL_Extension/doc/STL_Extension/Concepts/Hashable.h b/STL_Extension/doc/STL_Extension/Concepts/Hashable.h index 1b0df458143..c5d6e51c292 100644 --- a/STL_Extension/doc/STL_Extension/Concepts/Hashable.h +++ b/STL_Extension/doc/STL_Extension/Concepts/Hashable.h @@ -9,11 +9,11 @@ specializations `boost::hash` and `std::hash` exist. \cgalHasModel All handles and indices of \cgal data structures. -\sa `CGAL::Unique_hash_map` -\sa `std::unordered_set` -\sa `std::unordered_map` -\sa `boost::unordered_set` -\sa `boost::unordered_map` +\sa `CGAL::Unique_hash_map` +\sa `std::unordered_set` +\sa `std::unordered_map` +\sa `boost::unordered_set` +\sa `boost::unordered_map` */ diff --git a/STL_Extension/doc/STL_Extension/dependencies b/STL_Extension/doc/STL_Extension/dependencies index bbcf5ae4cde..dc379c2bac1 100644 --- a/STL_Extension/doc/STL_Extension/dependencies +++ b/STL_Extension/doc/STL_Extension/dependencies @@ -2,3 +2,4 @@ Manual Circulator Number_types Kernel_23 +Miscellany From 5ffa02c7960e349594e98186d23356b38f96cdcc Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 29 May 2015 08:49:31 +0200 Subject: [PATCH 36/47] remove unused parameter --- Hash_map/test/Hash_map/Hash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp index 428d152a1c8..5e2a51ce937 100644 --- a/Hash_map/test/Hash_map/Hash.cpp +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -18,7 +18,7 @@ typedef CGAL::Triangulation_2 Triangulation_2; template void -fct(const P& p) +fct(const P& ) { typedef typename boost::graph_traits

::vertex_descriptor vertex_descriptor; From b6850d35c04b00c6b85269c0774fd5b65206849c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 1 Jun 2015 10:42:52 +0200 Subject: [PATCH 37/47] #include and suppress struct/class warning for VC10 --- .../CGAL/Arrangement_2/Arrangement_2_iterators.h | 13 ++++++++++++- .../CGAL/boost/graph/graph_traits_HalfedgeDS.h | 15 +++++++++++++-- .../boost/graph/graph_traits_Triangulation_2.h | 14 +++++++++++++- STL_Extension/include/CGAL/Compact_container.h | 11 ++++++++++- STL_Extension/include/CGAL/In_place_list.h | 12 +++++++++++- .../include/CGAL/Surface_mesh/Surface_mesh.h | 13 ++++++++++++- 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h index 1fde617881b..4f3c2946b67 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h @@ -21,6 +21,8 @@ #ifndef CGAL_ARRANGEMENT_2_ITERATORS_H #define CGAL_ARRANGEMENT_2_ITERATORS_H +#include + /*! \file * Definitions of auxiliary iterator adaptors. */ @@ -556,7 +558,11 @@ public: } //namespace CGAL namespace std { - template struct hash; + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif template @@ -642,5 +648,10 @@ struct hash(&*i) / sizeof(typename I::value_type); } }; + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + } #endif diff --git a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h index 94ac62dc5b2..f4b8e19ccfb 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h @@ -20,6 +20,8 @@ #ifndef CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H #define CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H +#include + #include #include #include @@ -30,7 +32,6 @@ #include #include - #include #ifndef CGAL_NO_DEPRECATED_CODE @@ -219,7 +220,11 @@ public: namespace std { - template struct hash; + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif template struct hash > { @@ -230,5 +235,11 @@ namespace std { return fct(e.halfedge()); } }; + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + } + #endif // CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index f2142ca3c22..5d22c196372 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -20,6 +20,8 @@ #ifndef CGAL_GRAPH_TRAITS_TRIANGULATION_2_H #define CGAL_GRAPH_TRAITS_TRIANGULATION_2_H +#include + #include #include #include @@ -828,7 +830,12 @@ namespace boost { namespace std { - template struct hash; + + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif template < class T, class EdgeBase> struct hash > { @@ -847,6 +854,11 @@ namespace std { return hash_value(e); } }; + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + } // namespace std //#include diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index df521d6e8cb..637cfff6f1e 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1170,7 +1171,11 @@ namespace internal { } //namespace CGAL namespace std { - template struct hash; + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif template < class DSC, bool Const > struct hash > @@ -1181,6 +1186,10 @@ namespace std { return reinterpret_cast(&*i) / sizeof(typename DSC::value_type); } }; +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + } #endif // CGAL_COMPACT_CONTAINER_H diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index ff29afcfe59..8f405bac5a2 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace CGAL { @@ -772,7 +773,11 @@ void In_place_list::sort() { } //namespace CGAL namespace std { - template struct hash; + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif template < class T, class Alloc > struct hash > @@ -795,5 +800,10 @@ namespace std { return reinterpret_cast(ptr)/ sizeof(T); } }; + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + } #endif // CGAL_IN_PLACE_LIST_H diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 52b7ce04793..7a34c336c77 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -2971,7 +2972,11 @@ returns `i` as hash value for the index types `Vertex_index`, `Halfedge_index`, namespace std { - template struct hash; + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif template <> struct hash @@ -3022,6 +3027,12 @@ namespace boost { return i; } }; + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + } + #endif /* CGAL_SURFACE_MESH_H */ From dadb1291476e2af55e915799eac7c7d4a22087ee Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 2 Jun 2015 08:46:20 +0200 Subject: [PATCH 38/47] g++ needs a forward declaration for std::hash --- .../include/CGAL/Arrangement_2/Arrangement_2_iterators.h | 3 +++ BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h | 3 +++ BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h | 3 +++ STL_Extension/include/CGAL/Compact_container.h | 5 ++++- STL_Extension/include/CGAL/In_place_list.h | 4 +++- Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h | 3 +++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h index 4f3c2946b67..c5e94fc3144 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h @@ -564,6 +564,9 @@ namespace std { # pragma warning(disable:4099) // For VC10 it is class hash #endif +template < class T> +struct hash; + template struct hash + struct hash; + template struct hash > { std::size_t operator()(const CGAL::internal::HDS_edge& e) const diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index 5d22c196372..a7989c446c0 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -837,6 +837,9 @@ namespace std { # pragma warning(disable:4099) // For VC10 it is class hash #endif + template < class T> + struct hash; + template < class T, class EdgeBase> struct hash > { std::size_t operator()(const CGAL::detail::Edge& e) const diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 637cfff6f1e..7191cdbfc4a 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -1176,7 +1176,10 @@ namespace std { # pragma warning(push) # pragma warning(disable:4099) // For VC10 it is class hash #endif - + + template < class T> + struct hash; + template < class DSC, bool Const > struct hash > : public std::unary_function, std::size_t> { diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 8f405bac5a2..cc199efd39c 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -34,7 +34,6 @@ #include #include #include -#include namespace CGAL { @@ -779,6 +778,9 @@ namespace std { # pragma warning(disable:4099) // For VC10 it is class hash #endif + template < class T> + struct hash; + template < class T, class Alloc > struct hash > : public std::unary_function, std::size_t> { diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 7a34c336c77..7acf35f14c5 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -2978,6 +2978,9 @@ namespace std { # pragma warning(disable:4099) // For VC10 it is class hash #endif + template < class T> + struct hash; + template <> struct hash : public std::unary_function { From b197a3402f190808029c52da26f1d4b797d4ceca Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 22 Jun 2015 12:16:46 +0200 Subject: [PATCH 39/47] do not document hash_value as it is an implementation detail --- Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 7acf35f14c5..57e3d075cba 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -124,7 +124,6 @@ namespace CGAL { template std::size_t hash_value(const SM_Index& i) { - std::cerr << "hash_value" << std::endl; std::size_t ret = i; return ret; } @@ -2956,18 +2955,8 @@ collect_garbage() garbage_ = false; } -#ifdef DOXYGEN_RUNNING -/*! -returns `i` as hash value for the index types `Vertex_index`, `Halfedge_index`, -`Edge_index`, and `Face_index`. -\relates Surface_mesh -*/ - template - std::size_t hash_value(Surface_mesh

::Index i); -#endif - } // CGAL From 92a647b1af2afe0f5bfe430192436c61826786dd Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 22 Jun 2015 12:31:48 +0200 Subject: [PATCH 40/47] add example for unordered_set --- .../CGAL/Arrangement_2.h | 2 ++ .../doc/STL_Extension/STL_Extension.txt | 7 +++++++ STL_Extension/doc/STL_Extension/dependencies | 1 + STL_Extension/doc/STL_Extension/examples.txt | 1 + .../examples/STL_Extension/unordered_map.cpp | 19 +++++++++++++++++++ .../include/CGAL/Surface_mesh/Surface_mesh.h | 8 ++++++++ 6 files changed, 38 insertions(+) create mode 100644 STL_Extension/examples/STL_Extension/unordered_map.cpp diff --git a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h index 84b9dbb502c..1207d8d8ae1 100644 --- a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h +++ b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h @@ -370,6 +370,8 @@ counterparts. `Vertex_iterator`, `Halfedge_iterator`, and the handles appear in function parameter lists, the respective iterators can be passed as well. +All handles are model of `LessThanComparable` and `Hashable`. + */ /// @{ diff --git a/STL_Extension/doc/STL_Extension/STL_Extension.txt b/STL_Extension/doc/STL_Extension/STL_Extension.txt index bd3ee2b4b6f..2fbab5fcb8b 100644 --- a/STL_Extension/doc/STL_Extension/STL_Extension.txt +++ b/STL_Extension/doc/STL_Extension/STL_Extension.txt @@ -130,6 +130,13 @@ looking up keys whose type may differ from `Type`, as long as users supply a comparison functor `CompareKey`, between the keys and set elements; and catenating and splitting sets. +\section stl_hash Hashing + +For handles and indices of vertices, halfedges, faces, etc., we provide specializations of `boost::hash` and `std::hash, so that they can be used with classes such as `boost::unordered_map`. + +\cgalExample{STL_Extension/unordered_map.cpp} + + \section stl_polyobject Polymorphic Object The class `Object` can store an object of whatever other type. diff --git a/STL_Extension/doc/STL_Extension/dependencies b/STL_Extension/doc/STL_Extension/dependencies index dc379c2bac1..cf8c5e176f3 100644 --- a/STL_Extension/doc/STL_Extension/dependencies +++ b/STL_Extension/doc/STL_Extension/dependencies @@ -3,3 +3,4 @@ Circulator Number_types Kernel_23 Miscellany +Surface_mesh diff --git a/STL_Extension/doc/STL_Extension/examples.txt b/STL_Extension/doc/STL_Extension/examples.txt index 5cac450259b..f26952e7154 100644 --- a/STL_Extension/doc/STL_Extension/examples.txt +++ b/STL_Extension/doc/STL_Extension/examples.txt @@ -3,4 +3,5 @@ \example STL_Extension/in_place_list_prog.cpp \example STL_Extension/min_element_if_example.cpp \example STL_Extension/min_max_element_example.cpp +\example STL_Extension/unordered_map.cpp */ diff --git a/STL_Extension/examples/STL_Extension/unordered_map.cpp b/STL_Extension/examples/STL_Extension/unordered_map.cpp new file mode 100644 index 00000000000..a4ddbea3cb2 --- /dev/null +++ b/STL_Extension/examples/STL_Extension/unordered_map.cpp @@ -0,0 +1,19 @@ + +#include +#include +#include + + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +int main() +{ + boost::unordered_map bum; + Mesh mesh; + vertex_descriptor vd = mesh.add_vertex(); + bum[vd] = 7812; + return 0; +} diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 57e3d075cba..bcc09c482a2 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -130,6 +130,8 @@ namespace CGAL { /// This class represents a vertex. /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Halfedge_index`, `Edge_index`, `Face_index` class SM_Vertex_index : public SM_Index @@ -149,6 +151,8 @@ namespace CGAL { /// This class represents a halfedge. /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Vertex_index`, `Edge_index`, `Face_index` class SM_Halfedge_index : public SM_Index @@ -168,6 +172,8 @@ namespace CGAL { /// This class represents a face /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index` class SM_Face_index : public SM_Index @@ -187,6 +193,8 @@ namespace CGAL { /// This class represents an edge. /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Vertex_index`, `Halfedge_index`, `Face_index` class SM_Edge_index { From 6c8122683195f34101cc8040a1fb9579d1b7507e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 22 Jun 2015 12:40:44 +0200 Subject: [PATCH 41/47] improve wording in the manual --- .../doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h | 4 +++- Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h | 4 +++- Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h | 5 ++++- Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h index 1207d8d8ae1..aa20c362f07 100644 --- a/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h +++ b/Arrangement_on_surface_2/doc/Arrangement_on_surface_2/CGAL/Arrangement_2.h @@ -370,7 +370,9 @@ counterparts. `Vertex_iterator`, `Halfedge_iterator`, and the handles appear in function parameter lists, the respective iterators can be passed as well. -All handles are model of `LessThanComparable` and `Hashable`. +All handles are model of `LessThanComparable` and `Hashable`, +that is they can be used as keys in containers such as `std::map` +and `boost::unordered_map`. */ /// @{ diff --git a/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h b/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h index 084faf7f2a7..d7de9bcfd09 100644 --- a/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h +++ b/Polyhedron/doc/Polyhedron/CGAL/Polyhedron_3.h @@ -839,7 +839,9 @@ public: value type `Point`. Similarly, a `Plane_iterator` is provided. - All handles are model of `LessThanComparable` and `Hashable`. + All handles are model of `LessThanComparable` and `Hashable`, + that is they can be used as keys in containers such as `std::map` + and `boost::unordered_map`. */ /// @{ diff --git a/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h b/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h index 7ee344c3dc5..2e685c22713 100644 --- a/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h +++ b/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h @@ -229,7 +229,10 @@ typedef Tds::difference_type difference_type; /// The vertices and faces of the triangulations are accessed through /// handles, iterators and circulators. The handles are models /// of the concept `Handle` which basically offers the two dereference -/// operators and `->`. The iterators and circulators are all +/// operators and `->`. The handles are also model of the concepts +/// `LessThanComparable` and `Hashable`, that is they can be used as keys +/// in containers such as `std::map` and `boost::unordered_map`. +/// The iterators and circulators are all /// bidirectional and non-mutable. The circulators and iterators are /// convertible to handles with the same value type, so that whenever /// a handle appear in the parameter list of a function, an diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h index 7440b2900c6..17a955fe9d4 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h @@ -126,7 +126,9 @@ non-mutable. The edges and facets of the triangulation can also be visited through iterators and circulators which are bidirectional and non-mutable. Iterators and circulators are convertible to the corresponding handles, thus the user can pass them directly as -arguments to the functions. +arguments to the functions. The handles are also model of the concepts +`LessThanComparable` and `Hashable`, that is they can be used as keys +in containers such as `std::map` and `boost::unordered_map`. */ /// @{ From d3fdd07861d6c616eae0d2e3fd181c4b698a2dd4 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 22 Jun 2015 15:44:13 +0200 Subject: [PATCH 42/47] Add test for linear cell complex --- Hash_map/test/Hash_map/Hash.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp index 5e2a51ce937..8f232bcbf58 100644 --- a/Hash_map/test/Hash_map/Hash.cpp +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -13,7 +14,7 @@ typedef CGAL::Simple_cartesian Kernel; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::Surface_mesh Surface_mesh; typedef CGAL::Triangulation_2 Triangulation_2; - +typedef CGAL::Linear_cell_complex<3, 3> Linear_cell_complex_3; template @@ -30,6 +31,27 @@ fct(const P& ) U[vd] = 12; } +void fct2(Linear_cell_complex_3& lcc) +{ + typedef typename Linear_cell_complex_3::Dart_handle dh; + typedef typename Linear_cell_complex_3::Vertex_attribute_handle vh; + + { // For dart handle + std::map M; + dh e; + M.find(e); + boost::unordered_map U; + U[e] = 12; + } + + { // For vertex attribute handle + std::map M; + vh e; + M.find(e); + boost::unordered_map U; + U[e] = 12; + } +} int main() { @@ -42,6 +64,9 @@ int main() Triangulation_2 T; fct(T); + Linear_cell_complex_3 L; + fct2(L); + return 0; } From a8226e874345ad5cdc52a2cddd0e21c4a5d7ad67 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 22 Jun 2015 15:45:07 +0200 Subject: [PATCH 43/47] Add sentence about handle that are LessThanComparable and Hashable --- .../doc/Combinatorial_map/Combinatorial_map.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Combinatorial_map/doc/Combinatorial_map/Combinatorial_map.txt b/Combinatorial_map/doc/Combinatorial_map/Combinatorial_map.txt index 0439839b63b..0b7bd690326 100644 --- a/Combinatorial_map/doc/Combinatorial_map/Combinatorial_map.txt +++ b/Combinatorial_map/doc/Combinatorial_map/Combinatorial_map.txt @@ -579,10 +579,15 @@ Section \ref ssecattributes "Cell Attributes"). Users can customize a combinatorial map thanks to an items class (see Section \ref ssecitem "Combinatorial Map Items"), which defines the dart type and the attribute types. These types may be different for different -dimensions, and they may also be void. The darts and attributes are +dimensions, and they may also be void. + +The darts and attributes are accessed through handles. A handle is a model of the `Handle` concept, thus supporting the two dereference operators `operator*` and `operator->`. +All handles are model of `LessThanComparable` and `Hashable`, +that is they can be used as keys in containers such as `std::map` +and `boost::unordered_map`. \cgalFigureBegin{figdiagram_class,Diagramme_class.png} UML diagram of the main classes of the package. k is the number of non void attributes. From c48bf3a3e66ade6edc42ddd0c865597e642aab0a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 25 Jun 2015 09:17:08 +0200 Subject: [PATCH 44/47] more tests; small fixes --- Hash_map/test/Hash_map/Hash.cpp | 13 ++- .../doc/STL_Extension/STL_Extension.txt | 2 +- .../include/CGAL/Surface_mesh/Surface_mesh.h | 106 ++++++++---------- 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp index 8f232bcbf58..0af83de079f 100644 --- a/Hash_map/test/Hash_map/Hash.cpp +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -1,9 +1,12 @@ #include +#include +#include #include #include #include #include +#include #include #include #include @@ -11,6 +14,9 @@ typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_segment_traits_2 Arrangement_traits_2; +typedef CGAL::Arrangement_2 Arrangement_2; + typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::Surface_mesh Surface_mesh; typedef CGAL::Triangulation_2 Triangulation_2; @@ -33,8 +39,8 @@ fct(const P& ) void fct2(Linear_cell_complex_3& lcc) { - typedef typename Linear_cell_complex_3::Dart_handle dh; - typedef typename Linear_cell_complex_3::Vertex_attribute_handle vh; + typedef Linear_cell_complex_3::Dart_handle dh; + typedef Linear_cell_complex_3::Vertex_attribute_handle vh; { // For dart handle std::map M; @@ -55,6 +61,9 @@ void fct2(Linear_cell_complex_3& lcc) int main() { + Arrangement_2 A; + fct(A); + Polyhedron P; fct(P); diff --git a/STL_Extension/doc/STL_Extension/STL_Extension.txt b/STL_Extension/doc/STL_Extension/STL_Extension.txt index 2fbab5fcb8b..bd1d8478ed8 100644 --- a/STL_Extension/doc/STL_Extension/STL_Extension.txt +++ b/STL_Extension/doc/STL_Extension/STL_Extension.txt @@ -132,7 +132,7 @@ and catenating and splitting sets. \section stl_hash Hashing -For handles and indices of vertices, halfedges, faces, etc., we provide specializations of `boost::hash` and `std::hash, so that they can be used with classes such as `boost::unordered_map`. +For handles and indices of vertices, halfedges, faces, etc., we provide specializations of `boost::hash` and `std::hash`, so that they can be used with classes such as `boost::unordered_map`. \cgalExample{STL_Extension/unordered_map.cpp} diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index bcc09c482a2..1114234fd76 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -128,130 +128,113 @@ namespace CGAL { return ret; } - /// This class represents a vertex. - /// \cgalModels `Index` - /// \cgalModels `LessThanComparable` - /// \cgalModels `Hashable` - /// \sa `Halfedge_index`, `Edge_index`, `Face_index` + // Implementation for Surface_mesh::Vertex_index + class SM_Vertex_index : public SM_Index { public: - /// %Default constructor. + SM_Vertex_index() : SM_Index(-1) {} explicit SM_Vertex_index(size_type _idx) : SM_Index(_idx) {} - /// prints the index and a short identification string to an ostream. + friend std::ostream& operator<<(std::ostream& os, SM_Vertex_index const& v) { return (os << 'v' << (size_type)v ); } }; - /// This class represents a halfedge. - /// \cgalModels `Index` - /// \cgalModels `LessThanComparable` - /// \cgalModels `Hashable` - /// \sa `Vertex_index`, `Edge_index`, `Face_index` + // Implementation of Surface_mesh::Halfedge_index class SM_Halfedge_index : public SM_Index { public: - /// %Default constructor + SM_Halfedge_index() : SM_Index(-1) {} explicit SM_Halfedge_index(size_type _idx) : SM_Index(_idx) {} - /// prints the index and a short identification string to an ostream. friend std::ostream& operator<<(std::ostream& os, SM_Halfedge_index const& h) { return (os << 'h' << (size_type)h ); } }; - /// This class represents a face - /// \cgalModels `Index` - /// \cgalModels `LessThanComparable` - /// \cgalModels `Hashable` - /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index` + /// Implementation of Surfae_mesh::Face_index class SM_Face_index : public SM_Index { public: - /// %Default constructor + SM_Face_index() : SM_Index(-1) {} explicit SM_Face_index(size_type _idx) : SM_Index(_idx) {} - /// prints the index and a short identification string to an ostream. + friend std::ostream& operator<<(std::ostream& os, SM_Face_index const& f) { return (os << 'f' << (size_type)f ); } }; - /// This class represents an edge. - /// \cgalModels `Index` - /// \cgalModels `LessThanComparable` - /// \cgalModels `Hashable` - /// \sa `Vertex_index`, `Halfedge_index`, `Face_index` + /// Implementation of Surface_mesh::Edge_index class SM_Edge_index { public: typedef boost::uint32_t size_type; - /// %Default constructor + SM_Edge_index() : halfedge_(-1) { } SM_Edge_index(size_type idx) : halfedge_(idx * 2) { } - /// constructs an `SM_Edge_index` from a halfedge. + SM_Edge_index(SM_Halfedge_index he) : halfedge_(he) { } - /// @cond CGAL_DOCUMENT_INTERNALS - /// returns the internal halfedge. + + // returns the internal halfedge. SM_Halfedge_index halfedge() const { return halfedge_; } - /// returns the underlying index of this index. + // returns the underlying index of this index. operator size_type() const { return (size_type)halfedge_ / 2; } - /// resets index to be invalid (index=-1) + // resets index to be invalid (index=-1) void reset() { halfedge_.reset(); } - /// returns whether the index is valid, i.e., the index is not equal to -1. + // returns whether the index is valid, i.e., the index is not equal to -1. bool is_valid() const { return halfedge_.is_valid(); } - /// Are two indices equal? + // Are two indices equal? bool operator==(const SM_Edge_index& other) const { return (size_type)(*this) == (size_type)other; } - /// Are two indices different? + // Are two indices different? bool operator!=(const SM_Edge_index& other) const { return (size_type)(*this) != (size_type)other; } - /// compares by index. + // compares by index. bool operator<(const SM_Edge_index& other) const { return (size_type)(*this) < (size_type)other;} - /// decrements the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// decrement. + // decrements the internal index. This operation does not + // guarantee that the index is valid or undeleted after the + // decrement. SM_Edge_index& operator--() { halfedge_ = SM_Halfedge_index((size_type)halfedge_ - 2); return *this; } - /// increments the internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// increment. + // increments the internal index. This operation does not + // guarantee that the index is valid or undeleted after the + // increment. SM_Edge_index& operator++() { halfedge_ = SM_Halfedge_index((size_type)halfedge_ + 2); return *this; } - /// decrements internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// decrement. + // decrements internal index. This operation does not + // guarantee that the index is valid or undeleted after the + // decrement. SM_Edge_index operator--(int) { SM_Edge_index tmp(*this); halfedge_ = SM_Halfedge_index((size_type)halfedge_ - 2); return tmp; } - /// increments internal index. This operation does not - /// guarantee that the index is valid or undeleted after the - /// increment. + // increments internal index. This operation does not + // guarantee that the index is valid or undeleted after the + // increment. SM_Edge_index operator++(int) { SM_Edge_index tmp(*this); halfedge_ = SM_Halfedge_index((size_type)halfedge_ + 2); return tmp; } - /// @endcond - /// prints the index and a short identification string to an ostream. + // prints the index and a short identification string to an ostream. friend std::ostream& operator<<(std::ostream& os, SM_Edge_index const& e) { return (os << 'e' << (size_type)e << " on " << e.halfedge()); @@ -272,7 +255,7 @@ namespace CGAL { /// surface. It is an alternative to the classes `HalfedgeDS` and `Polyhedron_3` /// defined in the packages \ref PkgHDSSummary and \ref PkgPolyhedronSummary. /// The main difference is that it is indexed based and not pointer based, - /// and that the mechanism for adding information to vertices, halfedges, + /// and that the mechanism for adding information to vertices, halfedges, edges, /// and faces is much simpler and done at runtime and not at compile time. /// When elements are removed, they are only marked as removed, and a garbage /// collection function must be called to really remove them. @@ -764,11 +747,10 @@ private: /// This class represents a vertex. /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Halfedge_index`, `Edge_index`, `Face_index` class Vertex_index -#ifndef DOXYGEN_RUNNING - : public SM_Index -#endif { public: /// %Default constructor. @@ -790,11 +772,10 @@ private: /// This class represents a halfedge. /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Vertex_index`, `Edge_index`, `Face_index` class Halfedge_index -#ifndef DOXYGEN_RUNNING - : public SM_Index -#endif { public: /// %Default constructor @@ -815,11 +796,10 @@ private: #ifdef DOXYGEN_RUNNING /// This class represents a face /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Vertex_index`, `Halfedge_index`, `Edge_index` class Face_index -#ifndef DOXYGEN_RUNNING - : public SM_Index -#endif { public: /// %Default constructor @@ -840,6 +820,8 @@ private: #ifdef DOXYGEN_RUNNING /// This class represents an edge. /// \cgalModels `Index` + /// \cgalModels `LessThanComparable` + /// \cgalModels `Hashable` /// \sa `Vertex_index`, `Halfedge_index`, `Face_index` class Edge_index { @@ -2327,6 +2309,7 @@ private: //------------------------------------------------------- private data return os; } +#ifndef DOXYGEN_RUNNING inline std::istream& sm_skip_comments( std::istream& in) { char c; in >> c; @@ -2336,6 +2319,7 @@ private: //------------------------------------------------------- private data in.putback(c); return in; } +#endif /// \relates Surface_mesh /// Extracts the surface mesh from an input stream in Ascii OFF format. @@ -2975,8 +2959,10 @@ namespace std { # pragma warning(disable:4099) // For VC10 it is class hash #endif +#ifndef DOXYGEN_RUNNING template < class T> struct hash; +#endif template <> struct hash From 5c58b6fe210594257b71db1e7069f31155947996 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 16 Jul 2015 13:34:40 +0200 Subject: [PATCH 45/47] fix changes.html --- Installation/changes.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Installation/changes.html b/Installation/changes.html index 32412e44c25..39424e6a135 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -118,6 +118,13 @@ and src/ directories).

Release date: September 2015

+

General

+
    +
  • + Support for unordered sets and maps of the stdlib and of boost for handle and index classes. +
  • +
+

Advancing Front Surface Reconstruction (new package)

    From 909f424cf58d966ffaf89916bfd66aa2e85c3b01 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 16 Jul 2015 13:56:16 +0200 Subject: [PATCH 46/47] remove unused parameter --- Hash_map/test/Hash_map/Hash.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp index 0af83de079f..caaed81dbd8 100644 --- a/Hash_map/test/Hash_map/Hash.cpp +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -37,7 +37,7 @@ fct(const P& ) U[vd] = 12; } -void fct2(Linear_cell_complex_3& lcc) +void fct2() { typedef Linear_cell_complex_3::Dart_handle dh; typedef Linear_cell_complex_3::Vertex_attribute_handle vh; @@ -73,8 +73,7 @@ int main() Triangulation_2 T; fct(T); - Linear_cell_complex_3 L; - fct2(L); + fct2(); return 0; } From eb221489028929fe7df595e28f03102ede3df577 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Jul 2015 11:11:07 +0200 Subject: [PATCH 47/47] remove a file that is not an example --- .../examples/Surface_mesh/CMakeLists.txt | 1 - .../examples/Surface_mesh/unordered_set.cpp | 69 ------------------- 2 files changed, 70 deletions(-) delete mode 100644 Surface_mesh/examples/Surface_mesh/unordered_set.cpp diff --git a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt index 958ac61fe61..6889357d7b8 100644 --- a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt +++ b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt @@ -32,7 +32,6 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "sm_kruskal.cpp" ) create_single_source_cgal_program( "sm_memory.cpp" ) create_single_source_cgal_program( "sm_properties.cpp" ) - create_single_source_cgal_program( "unordered_set.cpp" ) else() diff --git a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp b/Surface_mesh/examples/Surface_mesh/unordered_set.cpp deleted file mode 100644 index 106782b81bd..00000000000 --- a/Surface_mesh/examples/Surface_mesh/unordered_set.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -template -struct Unordered -{ - Unordered() - { - std::hash fct; - T t; - fct(t); - } -}; - - -typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point; - -typedef CGAL::Surface_mesh Surface_mesh; -typedef CGAL::Triangulation_2 Triangulation_2; -typedef CGAL::Polyhedron_3 Polyhedron_3; - -int main() -{ - { - std::cout << "Surface_mesh::.._index"<< std::endl; - Unordered U1; - Unordered U2; - Unordered U3; - Unordered U4; - - std::cout << "\ngraph_traits::_descriptor"<< std::endl; - Unordered::vertex_descriptor> U5; - Unordered::halfedge_descriptor> U6; - Unordered::edge_descriptor> U7; - Unordered::face_descriptor> U8; - } - { - std::cout << "\nTriangulation_2::.._handle"<< std::endl; - Unordered U1; - Unordered U2; - - std::cout << "\ngraph_traits::_descriptor"<< std::endl; - Unordered::vertex_descriptor> U3; - Unordered::halfedge_descriptor> U4; - Unordered::edge_descriptor> U5; - Unordered::face_descriptor> U6; - } - { - std::cout << "\nPolyhedron_3::.._handle"<< std::endl; - Unordered U1; - Unordered U2; - Unordered U3; - - std::cout << "\ngraph_traits::_descriptor"<< std::endl; - Unordered::vertex_descriptor> U5; - Unordered::halfedge_descriptor> U6; - Unordered::edge_descriptor> U7; - Unordered::face_descriptor> U8; - } - return 0; -}