namespace simgrid {
namespace xbt {
+/** @brief Comparator class for using with std::priority_queue or boost::heap.
+ *
+ * Compare two std::pair by their first element (of type double), and return true when the first is greater than the
+ * second. Useful to have priority queues with the smallest element on top.
+ */
+template <class Pair> class HeapComparator {
+public:
+ bool operator()(const Pair& a, const Pair& b) const { return a.first > b.first; }
+};
+
/** @brief Sorts the elements of the sequence [first, last) according to their color assuming elements can have only
* three colors. Since there are only three colors, it is linear and much faster than a classical sort. See for
* example http://en.wikipedia.org/wiki/Dutch_national_flag_problem
namespace {
typedef std::pair<double, smx_timer_t> TimerQelt;
-std::priority_queue<TimerQelt, std::vector<TimerQelt>, std::greater<TimerQelt>> simix_timers;
+std::priority_queue<TimerQelt, std::vector<TimerQelt>, simgrid::xbt::HeapComparator<TimerQelt>> simix_timers;
void SIMIX_timer_flush()
{
while (not simix_timers.empty() && simix_timers.top().second->isDisabled()) {
#ifndef SURF_MODEL_H_
#define SURF_MODEL_H_
+#include "xbt/algorithm.hpp"
#include "xbt/signal.hpp"
#include "src/surf/surf_private.hpp"
namespace surf {
typedef std::pair<double, simgrid::surf::Action*> heap_element_type;
-class heap_element_compare {
-public:
- bool operator()(const heap_element_type& a, const heap_element_type& b) const { return a.first > b.first; }
-};
typedef boost::heap::pairing_heap<heap_element_type, boost::heap::constant_time_size<false>, boost::heap::stable<true>,
- boost::heap::compare<heap_element_compare>>
+ boost::heap::compare<simgrid::xbt::HeapComparator<heap_element_type>>>
heap_type;
/** @ingroup SURF_interface