29 #ifndef NVBLASTFIXEDPRIORITYQUEUE_H 30 #define NVBLASTFIXEDPRIORITYQUEUE_H 72 template<
class Element,
class Comparator = Less<Element> >
90 const Element
top()
const 104 return (mHeapSize == 0);
114 void push(
const Element& value)
117 uint32_t parentIndex = parent(mHeapSize);
119 for (newIndex = mHeapSize; newIndex > 0 && compare(value, data()[parentIndex]); newIndex = parentIndex, parentIndex= parent(newIndex))
121 data()[ newIndex ] = data()[parentIndex];
123 data()[newIndex] = value;
134 uint32_t tempHs = mHeapSize-1;
136 Element min = data()[0];
137 Element last = data()[tempHs];
139 for (i = 0; (child = left(i)) < tempHs; i = child)
142 const uint32_t rightChild = child + 1;
144 child += ((rightChild < tempHs) & compare((data()[rightChild]), (data()[child]))) ? 1 : 0;
146 if(compare(last, data()[child]))
149 data()[i] = data()[child];
160 const Element& min = data()[0];
161 for(uint32_t i=1; i<mHeapSize; ++i)
163 if(compare(data()[i], min))
189 bool compare(
const Element& a,
const Element& b)
const 191 return Comparator::operator()(a,b);
194 static uint32_t left(uint32_t nodeIndex)
196 return (nodeIndex << 1) + 1;
199 static uint32_t parent(uint32_t nodeIndex)
201 return (nodeIndex - 1) >> 1;
210 #endif // ifndef NVBLASTFIXEDPRIORITYQUEUE_H Element top()
Get the element with the highest priority.
Definition: NvBlastFixedPriorityQueue.h:96
void push(const Element &value)
Insert a new element into the priority queue. Only valid when size() is less than Capacity...
Definition: NvBlastFixedPriorityQueue.h:114
Definition: NvBlastFixedPriorityQueue.h:73
void clear()
Empty the priority queue.
Definition: NvBlastFixedPriorityQueue.h:108
Element pop()
Delete the highest priority element. Only valid when non-empty.
Definition: NvBlastFixedPriorityQueue.h:129
bool valid() const
Make sure the priority queue sort all elements correctly.
Definition: NvBlastFixedPriorityQueue.h:158
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
static size_t requiredMemorySize(uint32_t capacity)
Definition: NvBlastFixedPriorityQueue.h:84
const Element top() const
Get the element with the highest priority.
Definition: NvBlastFixedPriorityQueue.h:90
bool operator()(const A &a, const A &b) const
Definition: NvBlastFixedPriorityQueue.h:65
~FixedPriorityQueue()
Definition: NvBlastFixedPriorityQueue.h:80
bool empty() const
Check to whether the priority queue is empty.
Definition: NvBlastFixedPriorityQueue.h:102
uint32_t size() const
Return number of elements in the priority queue.
Definition: NvBlastFixedPriorityQueue.h:171
NV_INLINE T align16(T value)
Definition: NvBlastMemory.h:46
FixedPriorityQueue(const Comparator &less=Comparator())
Definition: NvBlastFixedPriorityQueue.h:76
Definition: NvBlastArray.h:37
Definition: NvBlastFixedPriorityQueue.h:63
#define NV_FORCE_INLINE
Definition: NvPreprocessor.h:365