#include <binaryheap.hpp>
Public Types | |
typedef Titem_ * | ItemPtr |
Public Member Functions | |
CBinaryHeapT (int max_items=102400) | |
FORCEINLINE int | Size () const |
Return the number of items stored in the priority queue. | |
FORCEINLINE bool | IsEmpty () const |
Test if the priority queue is empty. | |
FORCEINLINE bool | IsFull () const |
Test if the priority queue is full. | |
FORCEINLINE Titem_ & | GetHead () |
Find the smallest item in the priority queue. | |
bool | Push (Titem_ &new_item) |
Insert new item into the priority queue, maintaining heap order. | |
FORCEINLINE Titem_ & | PopHead () |
Remove and return the smallest item from the priority queue. | |
void | RemoveHead () |
Remove the smallest item from the priority queue. | |
void | RemoveByIdx (int idx) |
Remove item specified by index. | |
int | FindLinear (const Titem_ &item) const |
return index of the item that matches (using &item1 == &item2) the given item. | |
void | Clear () |
Make the priority queue empty. | |
void | CheckConsistency () |
verifies the heap consistency (added during first YAPF debug phase) | |
Private Attributes | |
int | m_size |
Number of items in the heap. | |
int | m_max_size |
Maximum number of items the heap can hold. | |
ItemPtr * | m_items |
The heap item pointers. |
For information about Binary Heap algotithm, see: http://www.policyalmanac.org/games/binaryHeaps.htm
Implementation specific notes:
1) It allocates space for item pointers (array). Items are allocated elsewhere.
2) ItemPtr [0] is never used. Total array size is max_items + 1, because we use indices 1..max_items instead of zero based C indexing.
3) Item of the binary heap should support these public members:
Definition at line 27 of file binaryheap.hpp.
FORCEINLINE int CBinaryHeapT< Titem_ >::Size | ( | ) | const [inline] |
Return the number of items stored in the priority queue.
Definition at line 53 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::m_size.
FORCEINLINE bool CBinaryHeapT< Titem_ >::IsEmpty | ( | ) | const [inline] |
Test if the priority queue is empty.
Definition at line 57 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::m_size.
Referenced by CBinaryHeapT< Titem_ >::FindLinear(), CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::GetBestOpenNode(), CBinaryHeapT< Titem_ >::GetHead(), CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::PopBestOpenNode(), and CBinaryHeapT< Titem_ >::RemoveHead().
FORCEINLINE bool CBinaryHeapT< Titem_ >::IsFull | ( | ) | const [inline] |
Test if the priority queue is full.
Definition at line 61 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::m_max_size, and CBinaryHeapT< Titem_ >::m_size.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::InsertOpenNode(), and CBinaryHeapT< Titem_ >::Push().
FORCEINLINE Titem_& CBinaryHeapT< Titem_ >::GetHead | ( | ) | [inline] |
Find the smallest item in the priority queue.
Return the smallest item, or throw assert if empty.
Definition at line 65 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::IsEmpty(), and CBinaryHeapT< Titem_ >::m_items.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::GetBestOpenNode(), and CBinaryHeapT< Titem_ >::PopHead().
FORCEINLINE bool CBinaryHeapT< Titem_ >::Push | ( | Titem_ & | new_item | ) | [inline] |
Insert new item into the priority queue, maintaining heap order.
Definition at line 93 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::CheckConsistency(), CBinaryHeapT< Titem_ >::IsFull(), CBinaryHeapT< Titem_ >::m_items, and CBinaryHeapT< Titem_ >::m_size.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::InsertOpenNode().
FORCEINLINE Titem_& CBinaryHeapT< Titem_ >::PopHead | ( | ) | [inline] |
Remove and return the smallest item from the priority queue.
Definition at line 72 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::GetHead(), and CBinaryHeapT< Titem_ >::RemoveHead().
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::PopBestOpenNode().
FORCEINLINE void CBinaryHeapT< Titem_ >::RemoveHead | ( | ) | [inline] |
Remove the smallest item from the priority queue.
Definition at line 108 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::CheckConsistency(), CBinaryHeapT< Titem_ >::IsEmpty(), CBinaryHeapT< Titem_ >::m_items, and CBinaryHeapT< Titem_ >::m_size.
Referenced by CBinaryHeapT< Titem_ >::PopHead().
int CBinaryHeapT< Titem_ >::FindLinear | ( | const Titem_ & | item | ) | const [inline] |
return index of the item that matches (using &item1 == &item2) the given item.
Definition at line 197 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::IsEmpty(), CBinaryHeapT< Titem_ >::m_items, and CBinaryHeapT< Titem_ >::m_size.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::PopOpenNode().
void CBinaryHeapT< Titem_ >::Clear | ( | ) | [inline] |
Make the priority queue empty.
All remaining items will remain untouched.
Definition at line 85 of file binaryheap.hpp.
References CBinaryHeapT< Titem_ >::m_size.