diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pathfinder/npf/aystar.cpp | 4 | ||||
-rw-r--r-- | src/pathfinder/npf/queue.cpp | 20 | ||||
-rw-r--r-- | src/pathfinder/npf/queue.h | 7 |
3 files changed, 15 insertions, 16 deletions
diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index 9eda4a3a7..3a1a5c057 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -199,8 +199,8 @@ void AyStar::Free() this->OpenListQueue.Free(false); /* 2nd argument above is false, below is true, to free the values only * once */ - delete_Hash(&this->OpenListHash, true); - delete_Hash(&this->ClosedListHash, true); + this->OpenListHash.Delete(true); + this->ClosedListHash.Delete(true); #ifdef AYSTAR_DEBUG printf("[AyStar] Memory free'd\n"); #endif diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index 0c8573e36..5b0e9a0ec 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -263,19 +263,23 @@ void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets) for (i = 0; i < num_buckets; i++) h->buckets_in_use[i] = false; } - -void delete_Hash(Hash *h, bool free_values) +/** + * Deletes the hash and cleans up. Only cleans up memory allocated by new_Hash + * & friends. If free is true, it will call free() on all the values that + * are left in the hash. + */ +void Hash::Delete(bool free_values) { uint i; /* Iterate all buckets */ - for (i = 0; i < h->num_buckets; i++) { - if (h->buckets_in_use[i]) { + for (i = 0; i < this->num_buckets; i++) { + if (this->buckets_in_use[i]) { HashNode *node; /* Free the first value */ - if (free_values) free(h->buckets[i].value); - node = h->buckets[i].next; + if (free_values) free(this->buckets[i].value); + node = this->buckets[i].next; while (node != NULL) { HashNode *prev = node; @@ -287,11 +291,11 @@ void delete_Hash(Hash *h, bool free_values) } } } - free(h->buckets); + free(this->buckets); /* No need to free buckets_in_use, it is always allocated in one * malloc with buckets */ #ifdef HASH_DEBUG - debug("Freeing Hash: %p", h); + debug("Freeing Hash: %p", this); #endif } diff --git a/src/pathfinder/npf/queue.h b/src/pathfinder/npf/queue.h index f6f04e6bb..6059c54b1 100644 --- a/src/pathfinder/npf/queue.h +++ b/src/pathfinder/npf/queue.h @@ -92,6 +92,7 @@ struct Hash { void *DeleteValue(uint key1, uint key2); void Clear(bool free_values); + void Delete(bool free_values); /** * Gets the current size of the hash. @@ -112,11 +113,5 @@ struct Hash { * returns a hash less than num_buckets! Call delete_hash after use */ void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets); -/** - * Deletes the hash and cleans up. Only cleans up memory allocated by new_Hash - * & friends. If free is true, it will call free() on all the values that - * are left in the hash. - */ -void delete_Hash(Hash *h, bool free_values); #endif /* QUEUE_H */ |