Added method "sort(bool)" to sort the element of the queue in ascending or descending order
This commit is contained in:
parent
65336cfe7b
commit
0491ceedeb
vcg/space/index/kdtree
|
@ -21,21 +21,45 @@
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef _PriorityQueue_h_
|
#ifndef _PRIORITYQUEUE_H_
|
||||||
#define _PriorityQueue_h_
|
#define _PRIORITYQUEUE_H_
|
||||||
|
|
||||||
/** Implements a bounded-size max priority queue using a heap
|
#include <algorithm>
|
||||||
*/
|
|
||||||
template <typename Index, typename Weight>
|
namespace vcg {
|
||||||
class HeapMaxPriorityQueue
|
|
||||||
{
|
/** Implements a bounded-size max priority queue using a heap
|
||||||
|
*/
|
||||||
|
template <typename Index, typename Weight>
|
||||||
|
class HeapMaxPriorityQueue
|
||||||
|
{
|
||||||
struct Element
|
struct Element
|
||||||
{
|
{
|
||||||
Weight weight;
|
Weight weight;
|
||||||
Index index;
|
Index index;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool operator()(const Element& a, const Element& b) const
|
||||||
|
{
|
||||||
|
return a.weight < b.weight;
|
||||||
|
}
|
||||||
|
} lessElement;
|
||||||
|
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool operator()(const Element& a, const Element& b) const
|
||||||
|
{
|
||||||
|
return a.weight > b.weight;
|
||||||
|
}
|
||||||
|
} greaterElement;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
HeapMaxPriorityQueue(void)
|
HeapMaxPriorityQueue(void)
|
||||||
{
|
{
|
||||||
|
@ -118,12 +142,21 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
inline void sort(bool ascending = true)
|
||||||
|
{
|
||||||
|
if (ascending)
|
||||||
|
std::sort(mElements, mElements + mCount, lessElement);
|
||||||
|
else
|
||||||
|
std::sort(mElements, mElements + mCount, greaterElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
int mCount;
|
int mCount;
|
||||||
int mMaxSize;
|
int mMaxSize;
|
||||||
Element* mElements;
|
Element* mElements;
|
||||||
Element* mpOffsetedElements;
|
Element* mpOffsetedElements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue