diff options
author | alberth <alberth@openttd.org> | 2010-08-29 13:38:27 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-08-29 13:38:27 +0000 |
commit | b06cedc905fbc1c8917f45cadfd78b246e4924f0 (patch) | |
tree | f6873a69a568e7a26a3ac5506e1b55fc46d729c9 /src/pathfinder/npf/queue.cpp | |
parent | 3f0cd8c9f0e3b1da2383f09fac1e4a18e782968e (diff) | |
download | openttd-b06cedc905fbc1c8917f45cadfd78b246e4924f0.tar.xz |
(svn r20684) -Codechange: Make BinaryHeap_Free() a method.
Diffstat (limited to 'src/pathfinder/npf/queue.cpp')
-rw-r--r-- | src/pathfinder/npf/queue.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index a9fdadcb6..8fa2fa41b 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -62,16 +62,21 @@ static void BinaryHeap_Clear(Queue *q, bool free_values) 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; - q->clear(q, free_values); - for (i = 0; i < q->blocks; i++) { - if (q->elements[i] == NULL) break; - free(q->elements[i]); + this->clear(this, free_values); + for (i = 0; i < this->blocks; i++) { + if (this->elements[i] == NULL) break; + 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); q->clear = BinaryHeap_Clear; - q->free = BinaryHeap_Free; q->max_size = max_size; q->size = 0; /* We malloc memory in block of BINARY_HEAP_BLOCKSIZE |