n-Dimensional Fast Methods  0.7
 All Classes Functions Variables Typedefs Pages
fmfibheap.hpp
1 
20 #ifndef FMFIBHEAP_H_
21 #define FMFIBHEAP_H_
22 
23 #include <boost/heap/fibonacci_heap.hpp>
24 
25 #include <fast_methods/datastructures/fmcompare.hpp>
26 
28 template <class cell_t = FMCell> class FMFibHeap {
29 
31  typedef boost::heap::fibonacci_heap<const cell_t *, boost::heap::compare<FMCompare<cell_t> > > fib_heap_t;
32 
34  typedef typename fib_heap_t::handle_type handle_t;
35 
36  public:
37  FMFibHeap () {}
38 
40  FMFibHeap (const size_t & n) { handles_.resize(n);}
41  virtual ~ FMFibHeap() {}
42 
44  void setMaxSize
45  (const size_t & n) {
46  handles_.resize(n);
47  }
48 
50  void push
51  (const cell_t * c) {
52  handles_[c->getIndex()] = heap_.push(c);
53  }
54 
56  unsigned int popMinIdx
57  () {
58  const unsigned int idx = heap_.top()->getIndex();
59  heap_.pop();
60  return idx;
61  }
62 
64  size_t size
65  () const {
66  return heap_.size();
67  }
68 
70  void update
71  (const cell_t * c) {
72  heap_.update(handles_[c->getIndex()], c);
73  }
74 
78  void increase
79  (const cell_t * c) {
80  heap_.increase(handles_[c->getIndex()],c);
81  }
82 
84  void clear
85  () {
86  heap_.clear();
87  handles_.clear();
88  }
89 
91  bool empty
92  () const {
93  return heap_.empty();
94  }
95 
96  protected:
102  std::vector<handle_t> handles_;
103 };
104 
105 
106 #endif /* FMFIBHEAP_H_ */
107 
void setMaxSize(const size_t &n)
Sets the maximum number of cells the heap will contain.
Definition: fmfibheap.hpp:45
void update(const cell_t *c)
Updates the position of the cell in the heap. Its priority can increase or decrease.
Definition: fmfibheap.hpp:71
fib_heap_t heap_
The actual heap for cell_t.
Definition: fmfibheap.hpp:98
size_t size() const
Returns current size of the heap.
Definition: fmfibheap.hpp:65
void increase(const cell_t *c)
Updates the position of the cell in the heap. Its priority can only increase. It is more efficient th...
Definition: fmfibheap.hpp:79
void clear()
Deallocates heap memory.
Definition: fmfibheap.hpp:85
fib_heap_t::handle_type handle_t
Shorthand for heap element handle type.
Definition: fmfibheap.hpp:34
std::vector< handle_t > handles_
Stores the handles of each cell by keeping the indices: handles_(0) is the handle for the cell with i...
Definition: fmfibheap.hpp:102
FMFibHeap(const size_t &n)
Creates a heap with n maximum elements.
Definition: fmfibheap.hpp:40
boost::heap::fibonacci_heap< const cell_t *, boost::heap::compare< FMCompare< cell_t > > > fib_heap_t
Shorthand for heap type.
Definition: fmfibheap.hpp:31
void push(const cell_t *c)
Pushes a new element into the heap.
Definition: fmfibheap.hpp:51
bool empty() const
Returns true if the heap is empty.
Definition: fmfibheap.hpp:92
unsigned int popMinIdx()
Pops index of the element with lowest value and removes it from the heap.
Definition: fmfibheap.hpp:57