(svn r19236) -Codechange: move method code into class definition (skidd13)

pull/155/head
yexo 15 years ago
parent 82be024308
commit 9ed0a64d04

@ -69,34 +69,15 @@ public:
/** Find the smallest item in the priority queue.
* Return the smallest item, or throw assert if empty. */
FORCEINLINE Titem_& GetHead() {assert(!IsEmpty()); return *m_items[1];}
/** Insert new item into the priority queue, maintaining heap order. */
void Push(Titem_& new_item);
/** Remove and return the smallest item from the priority queue. */
FORCEINLINE Titem_& PopHead() {Titem_& ret = GetHead(); RemoveHead(); return ret;};
/** Remove the smallest item from the priority queue. */
void RemoveHead();
/** Remove item specified by index */
void RemoveByIdx(int idx);
/** return index of the item that matches (using &item1 == &item2) the given item. */
int FindLinear(const Titem_& item) const;
/** Make the priority queue empty.
* All remaining items will remain untouched. */
void Clear() {m_size = 0;};
/** verifies the heap consistency (added during first YAPF debug phase) */
void CheckConsistency();
};
FORCEINLINE Titem_& GetHead()
{
assert(!IsEmpty());
return *m_items[1];
}
template <class Titem_>
FORCEINLINE void CBinaryHeapT<Titem_>::Push(Titem_& new_item)
/** Insert new item into the priority queue, maintaining heap order.
* @return false if the queue is full. */
FORCEINLINE void Push(Titem_& new_item)
{
if (IsFull()) {
m_max_size *= 2;
@ -112,8 +93,16 @@ FORCEINLINE void CBinaryHeapT<Titem_>::Push(Titem_& new_item)
CheckConsistency();
}
template <class Titem_>
FORCEINLINE void CBinaryHeapT<Titem_>::RemoveHead()
/** Remove and return the smallest item from the priority queue. */
FORCEINLINE Titem_& PopHead()
{
Titem_& ret = GetHead();
RemoveHead();
return ret;
}
/** Remove the smallest item from the priority queue. */
FORCEINLINE void RemoveHead()
{
assert(!IsEmpty());
@ -150,8 +139,8 @@ FORCEINLINE void CBinaryHeapT<Titem_>::RemoveHead()
CheckConsistency();
}
template <class Titem_>
inline void CBinaryHeapT<Titem_>::RemoveByIdx(int idx)
/** Remove item specified by index */
FORCEINLINE void RemoveByIdx(int idx)
{
/* at position idx we have a gap now */
int gap = idx;
@ -200,8 +189,8 @@ inline void CBinaryHeapT<Titem_>::RemoveByIdx(int idx)
CheckConsistency();
}
template <class Titem_>
inline int CBinaryHeapT<Titem_>::FindLinear(const Titem_& item) const
/** return index of the item that matches (using &item1 == &item2) the given item. */
FORCEINLINE int FindLinear(const Titem_& item) const
{
if (IsEmpty()) return 0;
for (ItemPtr *ppI = m_items + 1, *ppLast = ppI + m_size; ppI <= ppLast; ppI++) {
@ -212,8 +201,12 @@ inline int CBinaryHeapT<Titem_>::FindLinear(const Titem_& item) const
return 0;
}
template <class Titem_>
FORCEINLINE void CBinaryHeapT<Titem_>::CheckConsistency()
/** Make the priority queue empty.
* All remaining items will remain untouched. */
FORCEINLINE void Clear() {m_size = 0;}
/** verifies the heap consistency (added during first YAPF debug phase) */
FORCEINLINE void CheckConsistency()
{
/* enable it if you suspect binary heap doesn't work well */
#if 0
@ -223,6 +216,6 @@ FORCEINLINE void CBinaryHeapT<Titem_>::CheckConsistency()
}
#endif
}
};
#endif /* BINARYHEAP_HPP */

Loading…
Cancel
Save