36#include "foundation/PxSortInternals.h"
37#include "foundation/PxAlloca.h"
39#define PX_SORT_PARANOIA PX_DEBUG
50#pragma warning(disable : 4706)
58template <
class T,
class Predicate,
class PxAllocator>
59void PxSort(T* elements, uint32_t count,
const Predicate& compare,
const PxAllocator& inAllocator,
60 const uint32_t initialStackSize = 32)
62 static const uint32_t SMALL_SORT_CUTOFF = 5;
64 PX_ALLOCA(stackMem, int32_t, initialStackSize);
65 PxStack<PxAllocator> stack(stackMem, initialStackSize, inAllocator);
74 PX_ASSERT(first >= 0 && last <
int32_t(count));
75 if(
uint32_t(last - first) < SMALL_SORT_CUTOFF)
77 PxSmallSort(elements, first, last, compare);
82 const int32_t partIndex = PxPartition(elements, first, last, compare);
85 if((partIndex - first) < (last - partIndex))
87 stack.push(first, partIndex - 1);
88 first = partIndex + 1;
92 stack.push(partIndex + 1, last);
101 stack.pop(first, last);
105 for(uint32_t i = 1; i < count; i++)
106 PX_ASSERT(!compare(elements[i], elements[i - 1]));
110template <
class T,
class Predicate>
111void PxSort(T* elements, uint32_t count,
const Predicate& compare)
113 PxSort(elements, count, compare,
typename PxAllocatorTraits<T>::Type());
117void PxSort(T* elements, uint32_t count)
119 PxSort(elements, count, PxLess<T>(),
typename PxAllocatorTraits<T>::Type());
uint32 uint32_t
Definition fwd.hpp:131
int32 int32_t
Definition fwd.hpp:71
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39