diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pathfinder/npf/aystar.cpp | 2 | ||||
-rw-r--r-- | src/pathfinder/npf/queue.cpp | 28 | ||||
-rw-r--r-- | src/pathfinder/npf/queue.h | 10 |
3 files changed, 18 insertions, 22 deletions
diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index cfca30a75..8e02476a4 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -221,7 +221,7 @@ void AyStarMain_Clear(AyStar *aystar) { /* Clean the Queue, but not the elements within. That will be done by * the hash. */ - aystar->OpenListQueue.clear(&aystar->OpenListQueue, false); + aystar->OpenListQueue.Clear(false); /* Clean the hashes */ clear_Hash(&aystar->OpenListHash, true); clear_Hash(&aystar->ClosedListHash, true); diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index 8fa2fa41b..ea90bb5a5 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -30,14 +30,19 @@ /** Temporary duplicate of #BIN_HEAP_ARR, except it uses 'this' instead of 'q'. */ #define THISBIN_HEAP_ARR(i) this->elements[((i) - 1) >> BINARY_HEAP_BLOCKSIZE_BITS][((i) - 1) & BINARY_HEAP_BLOCKSIZE_MASK] -static void BinaryHeap_Clear(Queue *q, bool free_values) +/** + * Clears the queue, by removing all values from it. Its state is + * effectively reset. If free_items is true, each of the items cleared + * in this way are free()'d. + */ +void Queue::Clear(bool free_values) { /* Free all items if needed and free all but the first blocks of memory */ uint i; uint j; - for (i = 0; i < q->blocks; i++) { - if (q->elements[i] == NULL) { + for (i = 0; i < this->blocks; i++) { + if (this->elements[i] == NULL) { /* No more allocated blocks */ break; } @@ -45,21 +50,21 @@ static void BinaryHeap_Clear(Queue *q, bool free_values) if (free_values) { for (j = 0; j < (1 << BINARY_HEAP_BLOCKSIZE_BITS); j++) { /* For every element in the block */ - if ((q->size >> BINARY_HEAP_BLOCKSIZE_BITS) == i && - (q->size & BINARY_HEAP_BLOCKSIZE_MASK) == j) { + if ((this->size >> BINARY_HEAP_BLOCKSIZE_BITS) == i && + (this->size & BINARY_HEAP_BLOCKSIZE_MASK) == j) { break; // We're past the last element } - free(q->elements[i][j].item); + free(this->elements[i][j].item); } } if (i != 0) { /* Leave the first block of memory alone */ - free(q->elements[i]); - q->elements[i] = NULL; + free(this->elements[i]); + this->elements[i] = NULL; } } - q->size = 0; - q->blocks = 1; + this->size = 0; + this->blocks = 1; } /** @@ -71,7 +76,7 @@ void Queue::Free(bool free_values) { uint i; - this->clear(this, free_values); + this->Clear(free_values); for (i = 0; i < this->blocks; i++) { if (this->elements[i] == NULL) break; free(this->elements[i]); @@ -223,7 +228,6 @@ void *Queue::Pop() void init_BinaryHeap(Queue *q, uint max_size) { assert(q != NULL); - q->clear = BinaryHeap_Clear; q->max_size = max_size; q->size = 0; /* We malloc memory in block of BINARY_HEAP_BLOCKSIZE diff --git a/src/pathfinder/npf/queue.h b/src/pathfinder/npf/queue.h index 1d6831157..317ec1b71 100644 --- a/src/pathfinder/npf/queue.h +++ b/src/pathfinder/npf/queue.h @@ -18,9 +18,6 @@ //#define HASH_STATS -struct Queue; -typedef void Queue_ClearProc(Queue *q, bool free_values); - struct BinaryHeapNode { void *item; int priority; @@ -31,12 +28,7 @@ struct Queue { bool Push(void *item, int priority); void *Pop(); bool Delete(void *item, int priority); - - /* Clears the queue, by removing all values from it. Its state is - * effectively reset. If free_items is true, each of the items cleared - * in this way are free()'d. - */ - Queue_ClearProc *clear; + void Clear(bool free_values); void Free(bool free_values); uint max_size; |