41 #ifndef GRAPHLAB_MUTABLE_PRIORITY_QUEUE_HPP
42 #define GRAPHLAB_MUTABLE_PRIORITY_QUEUE_HPP
47 #include <boost/unordered_map.hpp>
49 #include <graphlab/macros_def.hpp>
84 template <
typename T,
typename Priority>
102 std::vector<heap_element>
heap;
124 return heap[i].second;
128 bool less(
size_t i,
size_t j) {
129 return heap[i].second <
heap[j].second;
133 void swap(
size_t i,
size_t j) {
145 if ((l <= s) &&
less(i, l))
147 if ((r <= s) &&
less(largest, r))
158 :
heap(1, std::make_pair(T(), Priority())) { }
171 return heap.size() - 1;
185 void push(T item, Priority priority) {
186 heap.push_back(std::make_pair(item, priority));
196 const std::pair<T, Priority>&
top()
const {
205 std::pair<T, Priority>
pop() {
216 Priority
get(T item)
const {
217 typename index_map_type::const_iterator iter =
index_map.find(item);
219 size_t i = iter->second;
220 return heap[i].second;
234 typename index_map_type::const_iterator iter =
index_map.find(item);
237 size_t i = iter->second;
238 heap[i].second = priority;
252 typename index_map_type::const_iterator iter =
index_map.find(item);
255 size_t i = iter->second;
256 heap[i].second = priority;
264 push(item, priority);
277 typename index_map_type::const_iterator iter =
index_map.find(item);
280 size_t i = iter->second;
281 heap[i].second = std::max(priority,
heap[i].second);
292 push(item, priority);
306 typename index_map_type::const_iterator iter =
index_map.find(item);
309 size_t i = iter->second;
310 heap[i].second = priority +
heap[i].second;
321 push(item, priority);
328 const std::vector<heap_element>&
values()
const {
335 heap.push_back(std::make_pair(T(), Priority()));
340 bool remove(T item) {
342 typename index_map_type::iterator iter =
index_map.find(item);
346 size_t i = iter->second;
584 #include <graphlab/macros_undef.hpp>
586 #endif // #ifndef GRAPHLAB_MUTABLE_PRIORITY_QUEUE_HPP