Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
Modifiable_priority_queue.h
1 // Copyright (c) 2006-2011 GeometryFactory (France). All rights reserved.
2 //
3 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public License as
5 // published by the Free Software Foundation; either version 3 of the License,
6 // or (at your option) any later version.
7 //
8 // Licensees holding a valid commercial license may use this file in
9 // accordance with the commercial license agreement provided with the software.
10 //
11 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 //
14 // $URL$
15 // $Id$
16 //
17 // Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
18 //
19 #ifndef CGAL_MODIFIABLE_PRIORITY_QUEUE_H
20 #define CGAL_MODIFIABLE_PRIORITY_QUEUE_H
21 
22 #define CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
23 
24 #include <climits> // Neeeded by the following Boost header for CHAR_BIT.
25 #include <boost/optional.hpp>
26 #include <boost/pending/relaxed_heap.hpp>
27 
28 namespace CGAL {
29 
30 template <class IndexedType_
31  ,class Compare_ = std::less<IndexedType_>
32  ,class ID_ = boost::identity_property_map
33  >
34 class Modifiable_priority_queue
35 {
36 public:
37 
38  typedef Modifiable_priority_queue Self;
39 
40  typedef IndexedType_ IndexedType ;
41  typedef Compare_ Compare;
42  typedef ID_ ID ;
43 
44  typedef boost::relaxed_heap<IndexedType,Compare,ID> Heap;
45  typedef typename Heap::value_type value_type;
46  typedef typename Heap::size_type size_type;
47 
48  typedef bool handle ;
49 
50 public:
51 
52  Modifiable_priority_queue( size_type largest_ID, Compare const& c, ID const& id ) : mHeap(largest_ID,c,id) {}
53 
54  handle push ( value_type const& v ) { mHeap.push(v) ; return handle(true) ; }
55 
56  handle update ( value_type const& v, handle h ) { mHeap.update(v); return h ; }
57 
58  handle erase ( value_type const& v, handle ) { mHeap.remove(v); return null_handle() ; }
59 
60  value_type top() const { return mHeap.top() ; }
61 
62  void pop() { mHeap.pop(); }
63 
64  bool empty() const { return mHeap.empty() ; }
65 
66  bool contains ( value_type const& v ) { return mHeap.contains(v) ; }
67 
68  boost::optional<value_type> extract_top()
69  {
70  boost::optional<value_type> r ;
71  if ( !empty() )
72  {
73  value_type v = top();
74  pop();
75  r = boost::optional<value_type>(v) ;
76  }
77  return r ;
78  }
79 
80  static handle null_handle() { return handle(false); }
81 
82 private:
83 
84  Heap mHeap ;
85 
86 } ;
87 
88 } //namespace CGAL
89 
90 #endif
91