From 0183aac33219fa6e8ccbfce2ea92b9488aacef64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 1 Dec 2021 10:19:58 +0100 Subject: [PATCH] plug pairing_heap with result of runtime of other heaps also add reserve --- .../include/CGAL/Modifiable_priority_queue.h | 64 ++++++++++++++----- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/STL_Extension/include/CGAL/Modifiable_priority_queue.h b/STL_Extension/include/CGAL/Modifiable_priority_queue.h index cdad2f2aef6..270fe8250e2 100644 --- a/STL_Extension/include/CGAL/Modifiable_priority_queue.h +++ b/STL_Extension/include/CGAL/Modifiable_priority_queue.h @@ -17,13 +17,13 @@ #include #include -#include +#include #include namespace CGAL { -enum Heap_type { CGAL_BOOST_FIBONACCI_HEAP, CGAL_BOOST_PENDING_MUTABLE_QUEUE, CGAL_BOOST_PENDING_RELAXED_HEAP }; +enum Heap_type { CGAL_BOOST_PAIRING_HEAP, CGAL_BOOST_PENDING_MUTABLE_QUEUE, CGAL_BOOST_PENDING_RELAXED_HEAP }; template @@ -92,12 +92,10 @@ private: } ; template -class Modifiable_priority_queue +struct Modifiable_priority_queue { -public: - typedef Modifiable_priority_queue Self; typedef IndexedType_ IndexedType ; @@ -105,34 +103,60 @@ public: typedef ID_ ID ; struct Reverse_compare{ - const Compare c; - Reverse_compare(){} - Reverse_compare(Compare const& c):c(c){} - template - bool operator() (T const& a, T const& b) const - { - return !c(a,b); - } + Compare c; + Reverse_compare(const Compare& c):c(c){} + bool operator() (const IndexedType& a, const IndexedType& b) const + { + return !c(a,b); + } }; - typedef boost::heap::fibonacci_heap > Heap; + // reference time (SMS Iphigenia, keeping 0.05% of edges, all default parameters + Surface_mesh): 12045ms + // -- + // boost::heap::priority_queue is ummutable and cannot be used + // -- + // typedef boost::heap::d_ary_heap, boost::heap::compare, boost::heap::mutable_ > Heap; //(15291ms) + // typedef boost::heap::d_ary_heap, boost::heap::compare, boost::heap::mutable_ > Heap; //(14351ms) + // typedef boost::heap::d_ary_heap, boost::heap::compare, boost::heap::mutable_ > Heap; //(13869ms) + // typedef boost::heap::d_ary_heap, boost::heap::compare, boost::heap::mutable_ > Heap; //(13879ms) + // typedef boost::heap::d_ary_heap, boost::heap::compare, boost::heap::mutable_ > Heap; //(13881ms) + // -- + //typedef boost::heap::binomial_heap> Heap; //(16216ms) + // -- + // typedef boost::heap::fibonacci_heap> Heap; // (13523ms) + // -- + typedef boost::heap::pairing_heap> Heap; // (12174ms) + // -- + // typedef boost::heap::skew_heap, boost::heap::mutable_> Heap; //(17957ms) + // -- typedef typename Heap::value_type value_type; typedef typename Heap::size_type size_type; +private: + void reserve_impl(size_type r, std::true_type) + { + mHeap.reserve(r); + } + + void reserve_impl(size_type, std::false_type) + {} + public: Modifiable_priority_queue( size_type largest_ID, Compare const& c = Compare(), ID const& id = ID() ) : mHeap(Reverse_compare(c)) , mID(id) , mHandles(largest_ID) - {} + { + reserve(largest_ID); + } void push ( value_type const& v ) { mHandles[get(mID, v)]=mHeap.push(v) ; } void update ( value_type const& v ) { mHeap.update(mHandles[get(mID, v)]); } - void erase ( value_type const& v ) { + void erase ( value_type const& v ) { auto vid = get(mID, v); mHeap.erase(mHandles[vid]); mHandles[vid]=typename Heap::handle_type(); @@ -166,6 +190,12 @@ public: return v; } + void reserve(size_type r) + { + reserve_impl(r, std::integral_constant()); + } + + private: Heap mHeap ;