mirror of https://github.com/CGAL/cgal
add version using boost::heap::fibonacci_heap
This commit is contained in:
parent
b9e2dc625a
commit
49b530461e
|
|
@ -17,11 +17,13 @@
|
||||||
#include <CGAL/STL_Extension/internal/boost/relaxed_heap.hpp>
|
#include <CGAL/STL_Extension/internal/boost/relaxed_heap.hpp>
|
||||||
#include <CGAL/STL_Extension/internal/boost/mutable_queue.hpp>
|
#include <CGAL/STL_Extension/internal/boost/mutable_queue.hpp>
|
||||||
|
|
||||||
|
#include <boost/heap/fibonacci_heap.hpp>
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
enum Heap_type { CGAL_BOOST_PENDING_MUTABLE_QUEUE, CGAL_BOOST_PENDING_RELAXED_HEAP };
|
enum Heap_type { CGAL_BOOST_FIBONACCI_HEAP, CGAL_BOOST_PENDING_MUTABLE_QUEUE, CGAL_BOOST_PENDING_RELAXED_HEAP };
|
||||||
|
|
||||||
template <class IndexedType_
|
template <class IndexedType_
|
||||||
,class Compare_ = std::less<IndexedType_>
|
,class Compare_ = std::less<IndexedType_>
|
||||||
|
|
@ -89,6 +91,88 @@ private:
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
template <class IndexedType_
|
||||||
|
,class Compare_
|
||||||
|
,class ID_>
|
||||||
|
class Modifiable_priority_queue<IndexedType_, Compare_, ID_, CGAL_BOOST_FIBONACCI_HEAP>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef Modifiable_priority_queue Self;
|
||||||
|
|
||||||
|
typedef IndexedType_ IndexedType ;
|
||||||
|
typedef Compare_ Compare;
|
||||||
|
typedef ID_ ID ;
|
||||||
|
|
||||||
|
struct Reverse_compare{
|
||||||
|
const Compare c;
|
||||||
|
Reverse_compare(){}
|
||||||
|
Reverse_compare(Compare const& c):c(c){}
|
||||||
|
template<typename T>
|
||||||
|
bool operator() (T const& a, T const& b) const
|
||||||
|
{
|
||||||
|
return !c(a,b);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::heap::fibonacci_heap<IndexedType,boost::heap::compare<Reverse_compare> > Heap;
|
||||||
|
|
||||||
|
typedef typename Heap::value_type value_type;
|
||||||
|
typedef typename Heap::size_type size_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)
|
||||||
|
{}
|
||||||
|
|
||||||
|
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 ) {
|
||||||
|
auto vid = get(mID, v);
|
||||||
|
mHeap.erase(mHandles[vid]);
|
||||||
|
mHandles[vid]=typename Heap::handle_type();
|
||||||
|
}
|
||||||
|
|
||||||
|
value_type top() const { return mHeap.top(); }
|
||||||
|
|
||||||
|
void pop() { mHeap.pop(); }
|
||||||
|
|
||||||
|
bool empty() const { return mHeap.empty() ; }
|
||||||
|
|
||||||
|
bool contains ( value_type const& v ) { return mHandles[get(mID, v)] != typename Heap::handle_type(); }
|
||||||
|
|
||||||
|
boost::optional<value_type> extract_top()
|
||||||
|
{
|
||||||
|
boost::optional<value_type> r ;
|
||||||
|
if ( !empty() )
|
||||||
|
{
|
||||||
|
value_type v = top();
|
||||||
|
pop();
|
||||||
|
r = boost::optional<value_type>(v) ;
|
||||||
|
}
|
||||||
|
return r ;
|
||||||
|
}
|
||||||
|
|
||||||
|
value_type top_and_pop()
|
||||||
|
{
|
||||||
|
CGAL_precondition(!empty());
|
||||||
|
value_type v = top();
|
||||||
|
pop();
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Heap mHeap ;
|
||||||
|
ID mID;
|
||||||
|
std::vector<typename Heap::handle_type> mHandles;
|
||||||
|
} ;
|
||||||
|
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue