OpenTTD
|
Binary Heap. More...
#include <queue.h>
Public Member Functions | |
void | Init (uint max_size) |
Initializes a binary heap and allocates internal memory for maximum of max_size elements. | |
bool | Push (void *item, int priority) |
Pushes an element into the queue, at the appropriate place for the queue. | |
void * | Pop () |
Pops the first element from the queue. | |
bool | Delete (void *item, int priority) |
Deletes the item from the queue. | |
void | Clear (bool free_values) |
Clears the queue, by removing all values from it. | |
void | Free (bool free_values) |
Frees the queue, by reclaiming all memory allocated by it. | |
BinaryHeapNode & | GetElement (uint i) |
Get an element from the #elements. |
Data Fields | |
uint | max_size |
uint | size |
uint | blocks |
The amount of blocks for which space is reserved in elements. | |
BinaryHeapNode ** | elements |
Static Public Attributes | |
static const int | BINARY_HEAP_BLOCKSIZE = 1 << BinaryHeap::BINARY_HEAP_BLOCKSIZE_BITS |
static const int | BINARY_HEAP_BLOCKSIZE_BITS = 10 |
The number of elements that will be malloc'd at a time. | |
static const int | BINARY_HEAP_BLOCKSIZE_MASK = BinaryHeap::BINARY_HEAP_BLOCKSIZE - 1 |
Binary Heap.
For information, see: http://www.policyalmanac.org/games/binaryHeaps.htm
void BinaryHeap::Clear | ( | bool | free_values | ) |
Clears the queue, by removing all values from it.
Its state is effectively reset. If free_items is true, each of the items cleared in this way are free()'d.
Definition at line 33 of file queue.cpp.
References BINARY_HEAP_BLOCKSIZE_BITS, blocks, and free().
Referenced by AyStar::Clear(), and Free().
bool BinaryHeap::Delete | ( | void * | item, |
int | priority | ||
) |
Deletes the item from the queue.
priority should be specified if known, which speeds up the deleting for some queue's. Should be -1 if not known.
Definition at line 135 of file queue.cpp.
References GetElement().
Referenced by AyStar::CheckTile(), and Pop().
void BinaryHeap::Free | ( | bool | free_values | ) |
|
inline |
void * BinaryHeap::Pop | ( | ) |
Pops the first element from the queue.
What exactly is the first element, is defined by the exact type of queue.
Definition at line 194 of file queue.cpp.
References Delete(), and GetElement().
Referenced by AyStar::OpenListPop().
bool BinaryHeap::Push | ( | void * | item, |
int | priority | ||
) |
Pushes an element into the queue, at the appropriate place for the queue.
Requires the queue pointer to be of an appropriate type, of course.
Definition at line 86 of file queue.cpp.
References BINARY_HEAP_BLOCKSIZE_BITS, blocks, and GetElement().
Referenced by AyStar::CheckTile(), and AyStar::OpenListAdd().