From d86f781ca54faf13bab50b2817cbce82546b0760 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 2 Oct 2010 19:43:29 +0000 Subject: (svn r20884) -Codechange: Make clear_Hash a method. --- src/pathfinder/npf/aystar.cpp | 4 ++-- src/pathfinder/npf/queue.cpp | 19 +++++++++++-------- src/pathfinder/npf/queue.h | 6 ++---- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index 4ef8cbfbe..9eda4a3a7 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -216,8 +216,8 @@ void AyStar::Clear() * the hash. */ this->OpenListQueue.Clear(false); /* Clean the hashes */ - clear_Hash(&this->OpenListHash, true); - clear_Hash(&this->ClosedListHash, true); + this->OpenListHash.Clear(true); + this->ClosedListHash.Clear(true); #ifdef AYSTAR_DEBUG printf("[AyStar] Cleared AyStar\n"); diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index eac77145b..0c8573e36 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -346,23 +346,26 @@ static void stat_Hash(const Hash *h) } #endif -void clear_Hash(Hash *h, bool free_values) +/** + * Cleans the hash, but keeps the memory allocated + */ +void Hash::Clear(bool free_values) { uint i; #ifdef HASH_STATS - if (h->size > 2000) stat_Hash(h); + if (this->size > 2000) stat_Hash(this); #endif /* 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; - h->buckets_in_use[i] = false; + this->buckets_in_use[i] = false; /* 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; @@ -372,7 +375,7 @@ void clear_Hash(Hash *h, bool free_values) } } } - h->size = 0; + this->size = 0; } /** diff --git a/src/pathfinder/npf/queue.h b/src/pathfinder/npf/queue.h index efe5301a9..f6f04e6bb 100644 --- a/src/pathfinder/npf/queue.h +++ b/src/pathfinder/npf/queue.h @@ -91,6 +91,8 @@ struct Hash { void *DeleteValue(uint key1, uint key2); + void Clear(bool free_values); + /** * Gets the current size of the hash. */ @@ -116,9 +118,5 @@ void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets); * are left in the hash. */ void delete_Hash(Hash *h, bool free_values); -/** - * Cleans the hash, but keeps the memory allocated - */ -void clear_Hash(Hash *h, bool free_values); #endif /* QUEUE_H */ -- cgit v1.2.3-54-g00ecf