Fast map matching  0.1.0
heap.hpp
1 
11 #ifndef FMM_HEAP_HPP
12 #define FMM_HEAP_HPP
13 
14 #include "network/type.hpp"
15 #include "fiboheap/fiboheap.h"
16 
17 namespace FMM {
18 namespace NETWORK{
22 struct HeapNode
23 {
25  double value;
31  bool operator<(const HeapNode &rhs) const {
32  if (value == rhs.value) return (index < rhs.index);
33  return value < rhs.value;
34  };
35 };
36 
40 class Heap{
41 public:
47  inline void push(NodeIndex index, double value){
48  HeapNodeHandle handle = heap.push({index,value});
49  handle_data.insert({index,handle});
50  };
54  inline void pop(){
55  HeapNode &node = heap.top();
56  handle_data.erase(node.index);
57  heap.pop();
58  };
63  inline HeapNode top(){
64  return heap.top();
65  };
70  inline bool empty(){
71  return heap.empty();
72  };
77  inline unsigned int size(){
78  return heap.size();
79  };
85  inline bool contain_node(NodeIndex index){
86  return handle_data.find(index)!=handle_data.end();
87  };
93  inline void decrease_key(NodeIndex index,double value){
94  HeapNodeHandle handle = handle_data[index];
95  heap.decrease_key(handle,{index,value});
96  };
97 
98 private:
99  typedef FibHeap<HeapNode>::FibNode *HeapNodeHandle;
100  FibHeap<HeapNode> heap;
101  std::unordered_map<NodeIndex,HeapNodeHandle> handle_data;
102 }; // Heap
103 }; // NETWORK
104 }; //FMM
105 
106 #endif
FMM::NETWORK::Heap
Heap data structure used in the routing query
Definition: heap.hpp:40
FMM::NETWORK::HeapNode::operator<
bool operator<(const HeapNode &rhs) const
Compare two nodes in the heap.
Definition: heap.hpp:31
FMM::NETWORK::Heap::decrease_key
void decrease_key(NodeIndex index, double value)
Decrease a node in the heap.
Definition: heap.hpp:93
FMM::NETWORK::Heap::top
HeapNode top()
Get a copy of the top node in the heap.
Definition: heap.hpp:63
FMM::NETWORK::Heap::push
void push(NodeIndex index, double value)
Push a node into the heap.
Definition: heap.hpp:47
FMM::NETWORK::HeapNode
Node in the heap structure.
Definition: heap.hpp:22
FMM::NETWORK::HeapNode::index
NodeIndex index
Index of a node in the heap.
Definition: heap.hpp:24
FMM
Fast map matching.
Definition: geom_algorithm.hpp:17
FMM::NETWORK::Heap::pop
void pop()
Pop a node from the heap.
Definition: heap.hpp:54
FMM::NETWORK::Heap::empty
bool empty()
Check if the heap is empty.
Definition: heap.hpp:70
FMM::NETWORK::Heap::contain_node
bool contain_node(NodeIndex index)
Check if the heap contains a node.
Definition: heap.hpp:85
FMM::NETWORK::Heap::size
unsigned int size()
Get the size of the heap.
Definition: heap.hpp:77
FMM::NETWORK::NodeIndex
unsigned int NodeIndex
Node Index in the network, range from [0,num_vertices-1 ].
Definition: type.hpp:24
FMM::NETWORK::HeapNode::value
double value
Value of a node in the heap.
Definition: heap.hpp:25