mirror of https://github.com/OpenTTD/OpenTTD
(svn r20883) -Codechange: Make Hash_Delete a method.
parent
15b784471e
commit
f185a35269
|
@ -61,7 +61,7 @@ OpenListNode *AyStar::OpenListPop()
|
||||||
/* Return the item the Queue returns.. the best next OpenList item. */
|
/* Return the item the Queue returns.. the best next OpenList item. */
|
||||||
OpenListNode *res = (OpenListNode*)this->OpenListQueue.Pop();
|
OpenListNode *res = (OpenListNode*)this->OpenListQueue.Pop();
|
||||||
if (res != NULL) {
|
if (res != NULL) {
|
||||||
Hash_Delete(&this->OpenListHash, res->path.node.tile, res->path.node.direction);
|
this->OpenListHash.DeleteValue(res->path.node.tile, res->path.node.direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -427,11 +427,16 @@ static HashNode *Hash_FindNode(const Hash *h, uint key1, uint key2, HashNode** p
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Hash_Delete(Hash *h, uint key1, uint key2)
|
/**
|
||||||
|
* Deletes the value with the specified key pair from the hash and returns
|
||||||
|
* that value. Returns NULL when the value was not present. The value returned
|
||||||
|
* is _not_ free()'d!
|
||||||
|
*/
|
||||||
|
void *Hash::DeleteValue(uint key1, uint key2)
|
||||||
{
|
{
|
||||||
void *result;
|
void *result;
|
||||||
HashNode *prev; // Used as output var for below function call
|
HashNode *prev; // Used as output var for below function call
|
||||||
HashNode *node = Hash_FindNode(h, key1, key2, &prev);
|
HashNode *node = Hash_FindNode(this, key1, key2, &prev);
|
||||||
|
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
/* not found */
|
/* not found */
|
||||||
|
@ -452,8 +457,8 @@ void *Hash_Delete(Hash *h, uint key1, uint key2)
|
||||||
} else {
|
} else {
|
||||||
/* This was the last in this bucket
|
/* This was the last in this bucket
|
||||||
* Mark it as empty */
|
* Mark it as empty */
|
||||||
uint hash = h->hash(key1, key2);
|
uint hash = this->hash(key1, key2);
|
||||||
h->buckets_in_use[hash] = false;
|
this->buckets_in_use[hash] = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* It is in another node
|
/* It is in another node
|
||||||
|
@ -466,7 +471,7 @@ void *Hash_Delete(Hash *h, uint key1, uint key2)
|
||||||
free(node);
|
free(node);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (result != NULL) h->size--;
|
if (result != NULL) this->size--;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,8 @@ struct Hash {
|
||||||
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);
|
||||||
|
|
||||||
|
void *DeleteValue(uint key1, uint key2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current size of the hash.
|
* Gets the current size of the hash.
|
||||||
*/
|
*/
|
||||||
|
@ -100,12 +102,6 @@ struct Hash {
|
||||||
|
|
||||||
/* Call these function to manipulate a hash */
|
/* Call these function to manipulate a hash */
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the value with the specified key pair from the hash and returns
|
|
||||||
* that value. Returns NULL when the value was not present. The value returned
|
|
||||||
* is _not_ free()'d!
|
|
||||||
*/
|
|
||||||
void *Hash_Delete(Hash *h, uint key1, uint key2);
|
|
||||||
|
|
||||||
/* Call these function to create/destroy a hash */
|
/* Call these function to create/destroy a hash */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue