(svn r20687) -Codechange: Replace the THISBIN_HEAP_ARR macro by a GetElement() method.

This commit is contained in:
alberth
2010-08-29 13:46:34 +00:00
parent 5d56c9eaea
commit 2711482534
2 changed files with 34 additions and 29 deletions

View File

@@ -30,6 +30,10 @@ struct BinaryHeapNode {
* http://www.policyalmanac.org/games/binaryHeaps.htm
*/
struct Queue {
static const int BINARY_HEAP_BLOCKSIZE;
static const int BINARY_HEAP_BLOCKSIZE_BITS;
static const int BINARY_HEAP_BLOCKSIZE_MASK;
void Init(uint max_size);
bool Push(void *item, int priority);
@@ -38,15 +42,23 @@ struct Queue {
void Clear(bool free_values);
void Free(bool free_values);
/**
* Get an element from the #elements.
* @param i Element to access (starts at offset \c 1).
* @return Value of the element.
*/
FORCEINLINE BinaryHeapNode &GetElement(uint i)
{
assert(i > 0);
return this->elements[(i - 1) >> BINARY_HEAP_BLOCKSIZE_BITS][(i - 1) & BINARY_HEAP_BLOCKSIZE_MASK];
}
uint max_size;
uint size;
uint blocks; ///< The amount of blocks for which space is reserved in elements
BinaryHeapNode **elements;
};
/* The amount of elements that will be malloc'd at a time */
#define BINARY_HEAP_BLOCKSIZE_BITS 10
/*
* Hash