diff options
author | alberth <alberth@openttd.org> | 2010-10-02 19:46:24 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-10-02 19:46:24 +0000 |
commit | 4af4d268d875c0dc09b5e1cea77d52b07dc3ec6e (patch) | |
tree | 11d2f6e3e391f769185dd7d60297b6b4d62438f6 /src/pathfinder/npf/queue.cpp | |
parent | 6f85b46eebf674b223df137a67c60b0b74953b97 (diff) | |
download | openttd-4af4d268d875c0dc09b5e1cea77d52b07dc3ec6e.tar.xz |
(svn r20886) -Codechange: Make init_Hash a method.
Diffstat (limited to 'src/pathfinder/npf/queue.cpp')
-rw-r--r-- | src/pathfinder/npf/queue.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index 5b0e9a0ec..3075ebf73 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -243,24 +243,27 @@ void BinaryHeap::Init(uint max_size) * Hash */ -void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets) +/** + * Builds a new hash in an existing struct. Make sure that hash() always + * returns a hash less than num_buckets! Call delete_hash after use + */ +void Hash::Init(Hash_HashProc *hash, uint num_buckets) { /* Allocate space for the Hash, the buckets and the bucket flags */ uint i; - assert(h != NULL); #ifdef HASH_DEBUG - debug("Allocated hash: %p", h); + debug("Allocated hash: %p", this); #endif - h->hash = hash; - h->size = 0; - h->num_buckets = num_buckets; - h->buckets = (HashNode*)MallocT<byte>(num_buckets * (sizeof(*h->buckets) + sizeof(*h->buckets_in_use))); + this->hash = hash; + this->size = 0; + this->num_buckets = num_buckets; + this->buckets = (HashNode*)MallocT<byte>(num_buckets * (sizeof(*this->buckets) + sizeof(*this->buckets_in_use))); #ifdef HASH_DEBUG - debug("Buckets = %p", h->buckets); + debug("Buckets = %p", this->buckets); #endif - h->buckets_in_use = (bool*)(h->buckets + num_buckets); - for (i = 0; i < num_buckets; i++) h->buckets_in_use[i] = false; + this->buckets_in_use = (bool*)(this->buckets + num_buckets); + for (i = 0; i < num_buckets; i++) this->buckets_in_use[i] = false; } /** |