(svn r20886) -Codechange: Make init_Hash a method.

This commit is contained in:
alberth 2010-10-02 19:46:24 +00:00
parent 6f85b46eeb
commit 4af4d268d8
3 changed files with 17 additions and 23 deletions

View File

@ -285,8 +285,8 @@ void AyStar::AddStartNode(AyStarNode *start_node, uint g)
void AyStar::Init(Hash_HashProc hash, uint num_buckets)
{
/* Allocated the Hash for the OpenList and ClosedList */
init_Hash(&this->OpenListHash, hash, num_buckets);
init_Hash(&this->ClosedListHash, hash, num_buckets);
this->OpenListHash.Init(hash, num_buckets);
this->ClosedListHash.Init(hash, num_buckets);
/* Set up our sorting queue
* BinaryHeap allocates a block of 1024 nodes

View File

@ -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;
}
/**

View File

@ -86,6 +86,8 @@ struct Hash {
* there are any Nodes in the bucket */
bool *buckets_in_use;
void Init(Hash_HashProc *hash, uint num_buckets);
void *Get(uint key1, uint key2) const;
void *Set(uint key1, uint key2, void *value);
@ -103,15 +105,4 @@ struct Hash {
}
};
/* Call these function to manipulate a hash */
/* Call these function to create/destroy a hash */
/**
* 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 init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets);
#endif /* QUEUE_H */