summaryrefslogtreecommitdiff
path: root/src/pathfinder/npf/queue.h
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-08-29 13:46:34 +0000
committeralberth <alberth@openttd.org>2010-08-29 13:46:34 +0000
commited723385133413160d56694f17165a216123f958 (patch)
treeff3218dda2e36ac1023e03521526c401a508edc7 /src/pathfinder/npf/queue.h
parentbc6a5a5e645ac44415e5c94bb12fa24cfa0724cd (diff)
downloadopenttd-ed723385133413160d56694f17165a216123f958.tar.xz
(svn r20687) -Codechange: Replace the THISBIN_HEAP_ARR macro by a GetElement() method.
Diffstat (limited to 'src/pathfinder/npf/queue.h')
-rw-r--r--src/pathfinder/npf/queue.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/pathfinder/npf/queue.h b/src/pathfinder/npf/queue.h
index 4a939b61d..2dc075b93 100644
--- a/src/pathfinder/npf/queue.h
+++ b/src/pathfinder/npf/queue.h
@@ -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