Binary Heap as C++ template. More...
#include <binaryheap.hpp>
Public Member Functions | |
CBinaryHeapT (uint max_items) | |
Create a binary heap. | |
FORCEINLINE uint | Length () const |
Get 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 T * | Begin () |
Get the smallest item in the binary tree. | |
FORCEINLINE T * | End () |
Get the LAST item in the binary tree. | |
FORCEINLINE void | Include (T *new_item) |
Insert new item into the priority queue, maintaining heap order. | |
FORCEINLINE T * | Shift () |
Remove and return the smallest (and also first) item from the priority queue. | |
FORCEINLINE void | Remove (uint index) |
Remove item at given index from the priority queue. | |
FORCEINLINE uint | FindIndex (const T &item) const |
Search for an item in the priority queue. | |
FORCEINLINE void | Clear () |
Make the priority queue empty. | |
Protected Member Functions | |
FORCEINLINE uint | HeapifyDown (uint gap, T *item) |
Get position for fixing a gap (downwards). | |
FORCEINLINE uint | HeapifyUp (uint gap, T *item) |
Get position for fixing a gap (upwards). | |
Private Attributes | |
uint | items |
Number of items in the heap. | |
uint | capacity |
Maximum number of items the heap can hold. | |
T ** | data |
The pointer to the heap item pointers. |
Binary Heap as C++ template.
A carrier which keeps its items automatically holds the smallest item at the first position. The order of items is maintained by using a binary tree. The implementation is used for priority queue's.
T | Type of the items stored in the binary heap |
Definition at line 53 of file binaryheap.hpp.
CBinaryHeapT< T >::CBinaryHeapT | ( | uint | max_items | ) | [inline, explicit] |
Create a binary heap.
max_items | The limit of the heap |
Definition at line 64 of file binaryheap.hpp.
FORCEINLINE T* CBinaryHeapT< T >::Begin | ( | ) | [inline] |
Get the smallest item in the binary tree.
Definition at line 181 of file binaryheap.hpp.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::GetBestOpenNode(), and CBinaryHeapT< Titem_ >::Shift().
FORCEINLINE void CBinaryHeapT< T >::Clear | ( | ) | [inline] |
Make the priority queue empty.
All remaining items will remain untouched.
Definition at line 288 of file binaryheap.hpp.
FORCEINLINE T* CBinaryHeapT< T >::End | ( | ) | [inline] |
Get the LAST item in the binary tree.
Definition at line 194 of file binaryheap.hpp.
Referenced by CBinaryHeapT< Titem_ >::Remove(), and CBinaryHeapT< Titem_ >::Shift().
FORCEINLINE uint CBinaryHeapT< T >::FindIndex | ( | const T & | item | ) | const [inline] |
Search for an item in the priority queue.
Matching is done by comparing adress of the item.
item | The reference to the item |
Definition at line 273 of file binaryheap.hpp.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::PopOpenNode().
FORCEINLINE uint CBinaryHeapT< T >::HeapifyDown | ( | uint | gap, | |
T * | item | |||
) | [inline, protected] |
Get position for fixing a gap (downwards).
The gap is moved downwards in the binary tree until it is in order again.
gap | The position of the gap | |
item | The proposed item for filling the gap |
Definition at line 88 of file binaryheap.hpp.
Referenced by CBinaryHeapT< Titem_ >::Remove(), and CBinaryHeapT< Titem_ >::Shift().
FORCEINLINE uint CBinaryHeapT< T >::HeapifyUp | ( | uint | gap, | |
T * | item | |||
) | [inline, protected] |
Get position for fixing a gap (upwards).
The gap is moved upwards in the binary tree until the is in order again.
gap | The position of the gap | |
item | The proposed item for filling the gap |
Definition at line 124 of file binaryheap.hpp.
Referenced by CBinaryHeapT< Titem_ >::Include(), and CBinaryHeapT< Titem_ >::Remove().
FORCEINLINE void CBinaryHeapT< T >::Include | ( | T * | new_item | ) | [inline] |
Insert new item into the priority queue, maintaining heap order.
new_item | The pointer to the new item |
Definition at line 204 of file binaryheap.hpp.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::InsertOpenNode().
FORCEINLINE bool CBinaryHeapT< T >::IsEmpty | ( | ) | const [inline] |
Test if the priority queue is empty.
Definition at line 167 of file binaryheap.hpp.
Referenced by CBinaryHeapT< Titem_ >::Begin(), CBinaryHeapT< Titem_ >::FindIndex(), CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::GetBestOpenNode(), CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::PopBestOpenNode(), CBinaryHeapT< Titem_ >::Remove(), and CBinaryHeapT< Titem_ >::Shift().
FORCEINLINE bool CBinaryHeapT< T >::IsFull | ( | ) | const [inline] |
Test if the priority queue is full.
Definition at line 174 of file binaryheap.hpp.
Referenced by CBinaryHeapT< Titem_ >::Include().
FORCEINLINE uint CBinaryHeapT< T >::Length | ( | ) | const [inline] |
Get the number of items stored in the priority queue.
Definition at line 160 of file binaryheap.hpp.
FORCEINLINE void CBinaryHeapT< T >::Remove | ( | uint | index | ) | [inline] |
Remove item at given index from the priority queue.
index | The position of the item in the heap |
Definition at line 245 of file binaryheap.hpp.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::PopOpenNode().
FORCEINLINE T* CBinaryHeapT< T >::Shift | ( | ) | [inline] |
Remove and return the smallest (and also first) item from the priority queue.
Definition at line 223 of file binaryheap.hpp.
Referenced by CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_, Tnum_array_items_ >::PopBestOpenNode().