mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r20886) -Codechange: Make init_Hash a method.
This commit is contained in:
parent
67f4b8ab83
commit
6c31c357d6
@ -285,8 +285,8 @@ void AyStar::AddStartNode(AyStarNode *start_node, uint g)
|
|||||||
void AyStar::Init(Hash_HashProc hash, uint num_buckets)
|
void AyStar::Init(Hash_HashProc hash, uint num_buckets)
|
||||||
{
|
{
|
||||||
/* Allocated the Hash for the OpenList and ClosedList */
|
/* Allocated the Hash for the OpenList and ClosedList */
|
||||||
init_Hash(&this->OpenListHash, hash, num_buckets);
|
this->OpenListHash.Init(hash, num_buckets);
|
||||||
init_Hash(&this->ClosedListHash, hash, num_buckets);
|
this->ClosedListHash.Init(hash, num_buckets);
|
||||||
|
|
||||||
/* Set up our sorting queue
|
/* Set up our sorting queue
|
||||||
* BinaryHeap allocates a block of 1024 nodes
|
* BinaryHeap allocates a block of 1024 nodes
|
||||||
|
@ -243,24 +243,27 @@ void BinaryHeap::Init(uint max_size)
|
|||||||
* Hash
|
* 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 */
|
/* Allocate space for the Hash, the buckets and the bucket flags */
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
assert(h != NULL);
|
|
||||||
#ifdef HASH_DEBUG
|
#ifdef HASH_DEBUG
|
||||||
debug("Allocated hash: %p", h);
|
debug("Allocated hash: %p", this);
|
||||||
#endif
|
#endif
|
||||||
h->hash = hash;
|
this->hash = hash;
|
||||||
h->size = 0;
|
this->size = 0;
|
||||||
h->num_buckets = num_buckets;
|
this->num_buckets = num_buckets;
|
||||||
h->buckets = (HashNode*)MallocT<byte>(num_buckets * (sizeof(*h->buckets) + sizeof(*h->buckets_in_use)));
|
this->buckets = (HashNode*)MallocT<byte>(num_buckets * (sizeof(*this->buckets) + sizeof(*this->buckets_in_use)));
|
||||||
#ifdef HASH_DEBUG
|
#ifdef HASH_DEBUG
|
||||||
debug("Buckets = %p", h->buckets);
|
debug("Buckets = %p", this->buckets);
|
||||||
#endif
|
#endif
|
||||||
h->buckets_in_use = (bool*)(h->buckets + num_buckets);
|
this->buckets_in_use = (bool*)(this->buckets + num_buckets);
|
||||||
for (i = 0; i < num_buckets; i++) h->buckets_in_use[i] = false;
|
for (i = 0; i < num_buckets; i++) this->buckets_in_use[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,6 +86,8 @@ struct Hash {
|
|||||||
* there are any Nodes in the bucket */
|
* there are any Nodes in the bucket */
|
||||||
bool *buckets_in_use;
|
bool *buckets_in_use;
|
||||||
|
|
||||||
|
void Init(Hash_HashProc *hash, uint num_buckets);
|
||||||
|
|
||||||
void *Get(uint key1, uint key2) const;
|
void *Get(uint key1, uint key2) const;
|
||||||
void *Set(uint key1, uint key2, void *value);
|
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 */
|
#endif /* QUEUE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user