Replace std::map by std::unordered_map for save/load of CMap/GMap.

This commit is contained in:
Guillaume Damiand 2021-10-14 17:19:33 +02:00
parent 26322683d7
commit 5c57f83fda
3 changed files with 23 additions and 22 deletions

View File

@ -42,6 +42,7 @@
#include <vector> #include <vector>
#include <deque> #include <deque>
#include <tuple> #include <tuple>
#include <unordered_map>
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include <boost/graph/graph_traits.hpp> #include <boost/graph/graph_traits.hpp>
@ -2581,7 +2582,7 @@ namespace CGAL {
/// @return the size (in number of darts) of the biggest cc. /// @return the size (in number of darts) of the biggest cc.
std::size_t keep_biggest_connected_component() std::size_t keep_biggest_connected_component()
{ {
std::map<std::size_t, Dart_handle> ccs; std::unordered_map<std::size_t, Dart_handle> ccs;
size_type treated=get_new_mark(); size_type treated=get_new_mark();
for (auto it=darts().begin(), itend=darts().end(); it!=itend; ++it) for (auto it=darts().begin(), itend=darts().end(); it!=itend; ++it)

View File

@ -23,7 +23,7 @@
#include <CGAL/Combinatorial_map_functors.h> #include <CGAL/Combinatorial_map_functors.h>
#include <algorithm> #include <algorithm>
#include <map> #include <unordered_map>
#include <vector> #include <vector>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
@ -161,8 +161,8 @@ namespace CGAL {
struct My_functor_cmap_save_one_attrib<CMap, i, true, true> struct My_functor_cmap_save_one_attrib<CMap, i, true, true>
{ {
static void run(CMap& amap, boost::property_tree::ptree& ptree, static void run(CMap& amap, boost::property_tree::ptree& ptree,
std::map<typename CMap::Dart_const_handle, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
// add dimension & type // add dimension & type
boost::property_tree::ptree& ndim = ptree.add("dimension", ""); boost::property_tree::ptree& ndim = ptree.add("dimension", "");
@ -194,8 +194,8 @@ namespace CGAL {
struct My_functor_cmap_save_one_attrib<CMap, i, false, true> struct My_functor_cmap_save_one_attrib<CMap, i, false, true>
{ {
static void run(CMap& amap, boost::property_tree::ptree& ptree, static void run(CMap& amap, boost::property_tree::ptree& ptree,
std::map<typename CMap::Dart_const_handle, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
// add dimension & type // add dimension & type
boost::property_tree::ptree& ndim = ptree.add("dimension", ""); boost::property_tree::ptree& ndim = ptree.add("dimension", "");
@ -226,8 +226,8 @@ namespace CGAL {
struct My_functor_cmap_save_one_attrib<CMap, i, true, false> struct My_functor_cmap_save_one_attrib<CMap, i, true, false>
{ {
static void run(CMap& amap, boost::property_tree::ptree& ptree, static void run(CMap& amap, boost::property_tree::ptree& ptree,
std::map<typename CMap::Dart_const_handle, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
// add dimension & type // add dimension & type
boost::property_tree::ptree& ndim = ptree.add("dimension", ""); boost::property_tree::ptree& ndim = ptree.add("dimension", "");
@ -259,8 +259,8 @@ namespace CGAL {
struct My_functor_cmap_save_one_attrib<CMap, i, false, false> struct My_functor_cmap_save_one_attrib<CMap, i, false, false>
{ {
static void run(CMap& amap, boost::property_tree::ptree& ptree, static void run(CMap& amap, boost::property_tree::ptree& ptree,
std::map<typename CMap::Dart_const_handle, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
// add dimension & type // add dimension & type
boost::property_tree::ptree& ndim = ptree.add("dimension", ""); boost::property_tree::ptree& ndim = ptree.add("dimension", "");
@ -288,8 +288,8 @@ namespace CGAL {
{ {
template <unsigned int i> template <unsigned int i>
static void run(CMap& amap, boost::property_tree::ptree& ptree, static void run(CMap& amap, boost::property_tree::ptree& ptree,
std::map<typename CMap::Dart_const_handle, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
My_functor_cmap_save_one_attrib<CMap, i>::run(amap, ptree, myDarts); My_functor_cmap_save_one_attrib<CMap, i>::run(amap, ptree, myDarts);
} }
@ -297,12 +297,12 @@ namespace CGAL {
template < class CMap > template < class CMap >
boost::property_tree::ptree cmap_save_darts boost::property_tree::ptree cmap_save_darts
(CMap& amap, std::map<typename CMap::Dart_const_handle, (CMap& amap, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
CGAL_assertion( myDarts.empty() ); CGAL_assertion( myDarts.empty() );
// First we numbered each dart by using the std::map. // First we numbered each dart by using the unordered_map.
typename CMap::Dart_range::const_iterator it(amap.darts().begin()); typename CMap::Dart_range::const_iterator it(amap.darts().begin());
for(typename CMap::size_type num=1; num<=amap.number_of_darts(); for(typename CMap::size_type num=1; num<=amap.number_of_darts();
++num, ++it) ++num, ++it)
@ -341,8 +341,8 @@ namespace CGAL {
template < class CMap > template < class CMap >
boost::property_tree::ptree cmap_save_attributes boost::property_tree::ptree cmap_save_attributes
(const CMap& amap, std::map<typename CMap::Dart_const_handle, (const CMap& amap, std::unordered_map<typename CMap::Dart_const_handle,
typename CMap::size_type>& myDarts) typename CMap::size_type>& myDarts)
{ {
using boost::property_tree::ptree; using boost::property_tree::ptree;
ptree pt; ptree pt;
@ -375,7 +375,7 @@ namespace CGAL {
f(tree); f(tree);
// map dart => number // map dart => number
std::map<typename CMap::Dart_const_handle, typename CMap::size_type> myDarts; std::unordered_map<typename CMap::Dart_const_handle, typename CMap::size_type> myDarts;
// Save darts // Save darts
ptree pt_darts=cmap_save_darts(amap, myDarts); ptree pt_darts=cmap_save_darts(amap, myDarts);

View File

@ -21,7 +21,7 @@
#include <CGAL/Combinatorial_map_save_load.h> #include <CGAL/Combinatorial_map_save_load.h>
#include <algorithm> #include <algorithm>
#include <map> #include <unordered_map>
#include <vector> #include <vector>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
@ -70,12 +70,12 @@ namespace CGAL {
template < class GMap > template < class GMap >
boost::property_tree::ptree gmap_save_darts boost::property_tree::ptree gmap_save_darts
(const GMap& amap, (const GMap& amap,
std::map<typename GMap::Dart_const_handle, std::unordered_map<typename GMap::Dart_const_handle,
typename GMap::size_type>& myDarts) typename GMap::size_type>& myDarts)
{ {
CGAL_assertion( myDarts.empty() ); CGAL_assertion( myDarts.empty() );
// First we numbered each dart by using the std::map. // First we numbered each dart by using the unordered_map.
typename GMap::Dart_range::const_iterator it(amap.darts().begin()); typename GMap::Dart_range::const_iterator it(amap.darts().begin());
for(typename GMap::size_type num=1; num<=amap.number_of_darts(); for(typename GMap::size_type num=1; num<=amap.number_of_darts();
++num, ++it) ++num, ++it)
@ -119,7 +119,7 @@ namespace CGAL {
ptree tree; ptree tree;
// map dart => number // map dart => number
std::map<typename GMap::Dart_const_handle, typename GMap::size_type> myDarts; std::unordered_map<typename GMap::Dart_const_handle, typename GMap::size_type> myDarts;
// Save darts // Save darts
ptree pt_darts=gmap_save_darts(amap, myDarts); ptree pt_darts=gmap_save_darts(amap, myDarts);