mirror of https://github.com/OpenTTD/OpenTTD
(svn r20682) -Codechange: Make BinaryHeap_Pop() a method.
parent
92801ac718
commit
10b182482e
|
@ -62,7 +62,7 @@ static OpenListNode *AyStarMain_OpenList_IsInList(AyStar *aystar, const AyStarNo
|
||||||
static OpenListNode *AyStarMain_OpenList_Pop(AyStar *aystar)
|
static OpenListNode *AyStarMain_OpenList_Pop(AyStar *aystar)
|
||||||
{
|
{
|
||||||
/* Return the item the Queue returns.. the best next OpenList item. */
|
/* Return the item the Queue returns.. the best next OpenList item. */
|
||||||
OpenListNode *res = (OpenListNode*)aystar->OpenListQueue.pop(&aystar->OpenListQueue);
|
OpenListNode *res = (OpenListNode*)aystar->OpenListQueue.Pop();
|
||||||
if (res != NULL) {
|
if (res != NULL) {
|
||||||
Hash_Delete(&aystar->OpenListHash, res->path.node.tile, res->path.node.direction);
|
Hash_Delete(&aystar->OpenListHash, res->path.node.tile, res->path.node.direction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,20 +188,24 @@ static bool BinaryHeap_Delete(Queue *q, void *item, int priority)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *BinaryHeap_Pop(Queue *q)
|
/**
|
||||||
|
* Pops the first element from the queue. What exactly is the first element,
|
||||||
|
* is defined by the exact type of queue.
|
||||||
|
*/
|
||||||
|
void *Queue::Pop()
|
||||||
{
|
{
|
||||||
void *result;
|
void *result;
|
||||||
|
|
||||||
#ifdef QUEUE_DEBUG
|
#ifdef QUEUE_DEBUG
|
||||||
printf("[BinaryHeap] Popping an element. There are %d elements left\n", q->size);
|
printf("[BinaryHeap] Popping an element. There are %d elements left\n", this->size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (q->size == 0) return NULL;
|
if (this->size == 0) return NULL;
|
||||||
|
|
||||||
/* The best item is always on top, so give that as result */
|
/* The best item is always on top, so give that as result */
|
||||||
result = BIN_HEAP_ARR(1).item;
|
result = THISBIN_HEAP_ARR(1).item;
|
||||||
/* And now we should get rid of this item... */
|
/* And now we should get rid of this item... */
|
||||||
BinaryHeap_Delete(q, BIN_HEAP_ARR(1).item, BIN_HEAP_ARR(1).priority);
|
BinaryHeap_Delete(this, THISBIN_HEAP_ARR(1).item, THISBIN_HEAP_ARR(1).priority);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +213,6 @@ static void *BinaryHeap_Pop(Queue *q)
|
||||||
void init_BinaryHeap(Queue *q, uint max_size)
|
void init_BinaryHeap(Queue *q, uint max_size)
|
||||||
{
|
{
|
||||||
assert(q != NULL);
|
assert(q != NULL);
|
||||||
q->pop = BinaryHeap_Pop;
|
|
||||||
q->del = BinaryHeap_Delete;
|
q->del = BinaryHeap_Delete;
|
||||||
q->clear = BinaryHeap_Clear;
|
q->clear = BinaryHeap_Clear;
|
||||||
q->free = BinaryHeap_Free;
|
q->free = BinaryHeap_Free;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
|
|
||||||
struct Queue;
|
struct Queue;
|
||||||
typedef void *Queue_PopProc(Queue *q);
|
|
||||||
typedef bool Queue_DeleteProc(Queue *q, void *item, int priority);
|
typedef bool Queue_DeleteProc(Queue *q, void *item, int priority);
|
||||||
typedef void Queue_ClearProc(Queue *q, bool free_values);
|
typedef void Queue_ClearProc(Queue *q, bool free_values);
|
||||||
typedef void Queue_FreeProc(Queue *q, bool free_values);
|
typedef void Queue_FreeProc(Queue *q, bool free_values);
|
||||||
|
@ -32,11 +31,7 @@ struct BinaryHeapNode {
|
||||||
|
|
||||||
struct Queue {
|
struct Queue {
|
||||||
bool Push(void *item, int priority);
|
bool Push(void *item, int priority);
|
||||||
/*
|
void *Pop();
|
||||||
* Pops the first element from the queue. What exactly is the first element,
|
|
||||||
* is defined by the exact type of queue.
|
|
||||||
*/
|
|
||||||
Queue_PopProc *pop;
|
|
||||||
/*
|
/*
|
||||||
* Deletes the item from the queue. priority should be specified if
|
* Deletes the item from the queue. priority should be specified if
|
||||||
* known, which speeds up the deleting for some queue's. Should be -1
|
* known, which speeds up the deleting for some queue's. Should be -1
|
||||||
|
|
Loading…
Reference in New Issue