mirror of https://github.com/OpenTTD/OpenTTD
(svn r20684) -Codechange: Make BinaryHeap_Free() a method.
parent
3f0cd8c9f0
commit
b06cedc905
|
@ -203,7 +203,7 @@ static int AyStarMain_Loop(AyStar *aystar)
|
||||||
*/
|
*/
|
||||||
static void AyStarMain_Free(AyStar *aystar)
|
static void AyStarMain_Free(AyStar *aystar)
|
||||||
{
|
{
|
||||||
aystar->OpenListQueue.free(&aystar->OpenListQueue, false);
|
aystar->OpenListQueue.Free(false);
|
||||||
/* 2nd argument above is false, below is true, to free the values only
|
/* 2nd argument above is false, below is true, to free the values only
|
||||||
* once */
|
* once */
|
||||||
delete_Hash(&aystar->OpenListHash, true);
|
delete_Hash(&aystar->OpenListHash, true);
|
||||||
|
|
|
@ -62,16 +62,21 @@ static void BinaryHeap_Clear(Queue *q, bool free_values)
|
||||||
q->blocks = 1;
|
q->blocks = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BinaryHeap_Free(Queue *q, 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.
|
||||||
|
*/
|
||||||
|
void Queue::Free(bool free_values)
|
||||||
{
|
{
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
q->clear(q, free_values);
|
this->clear(this, free_values);
|
||||||
for (i = 0; i < q->blocks; i++) {
|
for (i = 0; i < this->blocks; i++) {
|
||||||
if (q->elements[i] == NULL) break;
|
if (this->elements[i] == NULL) break;
|
||||||
free(q->elements[i]);
|
free(this->elements[i]);
|
||||||
}
|
}
|
||||||
free(q->elements);
|
free(this->elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -219,7 +224,6 @@ void init_BinaryHeap(Queue *q, uint max_size)
|
||||||
{
|
{
|
||||||
assert(q != NULL);
|
assert(q != NULL);
|
||||||
q->clear = BinaryHeap_Clear;
|
q->clear = BinaryHeap_Clear;
|
||||||
q->free = BinaryHeap_Free;
|
|
||||||
q->max_size = max_size;
|
q->max_size = max_size;
|
||||||
q->size = 0;
|
q->size = 0;
|
||||||
/* We malloc memory in block of BINARY_HEAP_BLOCKSIZE
|
/* We malloc memory in block of BINARY_HEAP_BLOCKSIZE
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
struct Queue;
|
struct Queue;
|
||||||
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);
|
|
||||||
|
|
||||||
struct BinaryHeapNode {
|
struct BinaryHeapNode {
|
||||||
void *item;
|
void *item;
|
||||||
|
@ -38,11 +37,7 @@ struct Queue {
|
||||||
* in this way are free()'d.
|
* in this way are free()'d.
|
||||||
*/
|
*/
|
||||||
Queue_ClearProc *clear;
|
Queue_ClearProc *clear;
|
||||||
/* Frees the queue, by reclaiming all memory allocated by it. After
|
void Free(bool free_values);
|
||||||
* this it is no longer usable. If free_items is true, any remaining
|
|
||||||
* items are free()'d too.
|
|
||||||
*/
|
|
||||||
Queue_FreeProc *free;
|
|
||||||
|
|
||||||
uint max_size;
|
uint max_size;
|
||||||
uint size;
|
uint size;
|
||||||
|
|
Loading…
Reference in New Issue