BinaryHeap Struct Reference

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.
FORCEINLINE BinaryHeapNodeGetElement (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

Detailed Description

Binary Heap.

For information, see: http://www.policyalmanac.org/games/binaryHeaps.htm

Definition at line 28 of file queue.h.


Member Function Documentation

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 31 of file queue.cpp.

References BINARY_HEAP_BLOCKSIZE_BITS, and blocks.

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 133 of file queue.cpp.

References GetElement().

Referenced by AyStar::CheckTile(), and Pop().

void BinaryHeap::Free ( bool  free_values  ) 

Frees the queue, by reclaiming all memory allocated by it.

After this it is no longer usable. If free_items is true, any remaining items are free()'d too.

Definition at line 68 of file queue.cpp.

References blocks, and Clear().

Referenced by AyStar::Free().

FORCEINLINE BinaryHeapNode& BinaryHeap::GetElement ( uint  i  )  [inline]

Get an element from the elements.

Parameters:
i Element to access (starts at offset 1).
Returns:
Value of the element.

Definition at line 46 of file queue.h.

References BINARY_HEAP_BLOCKSIZE_BITS.

Referenced by Delete(), Pop(), and Push().

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 192 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 84 of file queue.cpp.

References BINARY_HEAP_BLOCKSIZE_BITS, blocks, and GetElement().

Referenced by AyStar::CheckTile(), and AyStar::OpenListAdd().


The documentation for this struct was generated from the following files:

Generated on Thu Jan 20 22:58:16 2011 for OpenTTD by  doxygen 1.6.1