mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r20885) -Codechange: Make delete_Hash a method.
This commit is contained in:
parent
0612dc2e86
commit
67f4b8ab83
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user