18 #ifndef INCLUDED_PRIORITYQUEUE 19 #define INCLUDED_PRIORITYQUEUE 27 #define PRIORITYQUEUE_DEBUG 0 29 #define PRIORITYQUEUE_DEBUG 1 32 template <
typename Item,
typename CMP>
37 if (
CMP()(b.rank, a.rank))
39 if (
CMP()(a.rank, b.rank))
50 #if PRIORITYQUEUE_DEBUG 63 template <
typename ID,
typename R,
typename H,
typename CMP = std::less<R> >
74 void push(
const Item& item)
76 m_Heap.push_back(item);
83 for (
ssize_t n = m_Heap.size() - 1; n >= 0; --n)
85 if (m_Heap[n].
id ==
id)
87 #if PRIORITYQUEUE_DEBUG 88 ENSURE(m_Heap[n].rank > newrank);
90 m_Heap[n].rank = newrank;
100 #if PRIORITYQUEUE_DEBUG 111 return m_Heap.empty();
116 return m_Heap.size();
134 template <
typename ID,
typename R,
typename H,
typename CMP = std::less<R> >
147 m_List.push_back(item);
152 for (
size_t n = 0; n < m_List.size(); ++n)
154 if (m_List[n].
id ==
id)
162 find(
id)->rank = newrank;
168 #if PRIORITYQUEUE_DEBUG 173 Item best = m_List.back();
174 size_t bestidx = m_List.size()-1;
184 m_List[bestidx] = m_List[m_List.size()-1];
191 return m_List.empty();
196 return m_List.size();
208 #endif // INCLUDED_PRIORITYQUEUE #define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
H h
Definition: PriorityQueue.h:142
std::vector< Item > m_List
Definition: PriorityQueue.h:205
bool empty()
Definition: PriorityQueue.h:189
void clear()
Definition: PriorityQueue.h:200
void push(const Item &item)
Definition: PriorityQueue.h:145
Priority queue implemented as a binary heap.
Definition: PriorityQueue.h:64
Definition: PriorityQueue.h:138
ID id
Definition: PriorityQueue.h:69
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:287
size_t size()
Definition: PriorityQueue.h:194
void push(const Item &item)
Definition: PriorityQueue.h:74
bool empty()
Definition: PriorityQueue.h:109
R rank
Definition: PriorityQueue.h:141
Definition: PriorityQueue.h:33
bool operator()(const Item &a, const Item &b) const
Definition: PriorityQueue.h:35
R rank
Definition: PriorityQueue.h:70
intptr_t ssize_t
Definition: wposix_types.h:82
Priority queue implemented as an unsorted array.
Definition: PriorityQueue.h:135
Item * find(ID id)
Definition: PriorityQueue.h:150
size_t size()
Definition: PriorityQueue.h:114
Item pop()
Definition: PriorityQueue.h:98
H h
Definition: PriorityQueue.h:71
void promote(ID id, R oldrank, R newrank, H newh)
Definition: PriorityQueue.h:80
#define debug_warn(expr)
display the error dialog with the given text.
Definition: debug.h:329
Definition: PriorityQueue.h:67
std::vector< Item > m_Heap
Definition: PriorityQueue.h:124
void promote(ID id, R oldrank, R newrank, H newh)
Definition: PriorityQueue.h:160
ID id
Definition: PriorityQueue.h:140
Item pop()
Definition: PriorityQueue.h:166
void clear()
Definition: PriorityQueue.h:119