26 #ifndef SAGA2_PRIQUEUE_H 27 #define SAGA2_PRIQUEUE_H 31 template <
class ITEM,
int size>
34 ITEM _queue[size + 1];
36 static int16 parentIndex(int16 index) {
39 static int16 child1Index(int16 index) {
42 static int16 child2Index(int16 index) {
43 return (index >> 1) + 1;
51 bool insert(ITEM &newItem);
52 bool remove(ITEM &result);
63 template <
class ITEM,
int size>
67 newVal = (int)newItem;
71 if (_tail >= size + 1)
return false;
73 for (index = _tail, qi = &_queue[index];
75 index = parentIndex, qi = parentItem) {
76 parentIndex = PriorityQueue::parentIndex(index);
77 parentItem = &_queue[parentIndex];
79 if ((
int)*parentItem <= newVal)
break;
90 template <
class ITEM,
int size>
92 ITEM *item = &_queue[1],
98 if (_tail <= 1)
return false;
102 tailVal = (int)_queue[_tail];
105 childNum = child1Index(itemNum);
106 if (childNum >= _tail)
break;
108 child = &_queue[childNum];
111 if (childNum + 1 < _tail
112 && (
int)child[0] > (
int)child[1]) {
117 if ((
int)*child >= tailVal)
break;
123 if (itemNum != _tail) {
124 *item = _queue[_tail];
Definition: priqueue.h:32