summaryrefslogtreecommitdiff
path: root/src/pathfinder/npf/queue.h
diff options
context:
space:
mode:
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