Changeset - r16178:ec3cf64c17e2
[Not reviewed]
master
0 2 0
alberth - 14 years ago 2010-10-02 19:48:45
alberth@openttd.org
(svn r20888) -Codechange: Make Hash_FindNode a method.
2 files changed with 10 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/pathfinder/npf/queue.cpp
Show inline comments
 
@@ -393,29 +393,29 @@ void Hash::Clear(bool free_values)
 
 * bucket, or NULL if it is empty. prev can also be NULL, in which case it is
 
 * not used for output.
 
 */
 
static HashNode *Hash_FindNode(const Hash *h, uint key1, uint key2, HashNode** prev_out)
 
HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const
 
{
 
	uint hash = h->hash(key1, key2);
 
	uint hash = this->hash(key1, key2);
 
	HashNode *result = NULL;
 

	
 
#ifdef HASH_DEBUG
 
	debug("Looking for %u, %u", key1, key2);
 
#endif
 
	/* Check if the bucket is empty */
 
	if (!h->buckets_in_use[hash]) {
 
	if (!this->buckets_in_use[hash]) {
 
		if (prev_out != NULL) *prev_out = NULL;
 
		result = NULL;
 
	/* Check the first node specially */
 
	} else if (h->buckets[hash].key1 == key1 && h->buckets[hash].key2 == key2) {
 
	} else if (this->buckets[hash].key1 == key1 && this->buckets[hash].key2 == key2) {
 
		/* Save the value */
 
		result = h->buckets + hash;
 
		result = this->buckets + hash;
 
		if (prev_out != NULL) *prev_out = NULL;
 
#ifdef HASH_DEBUG
 
		debug("Found in first node: %p", result);
 
#endif
 
	/* Check all other nodes */
 
	} else {
 
		HashNode *prev = h->buckets + hash;
 
		HashNode *prev = this->buckets + hash;
 
		HashNode *node;
 

	
 
		for (node = prev->next; node != NULL; node = node->next) {
 
@@ -446,7 +446,7 @@ void *Hash::DeleteValue(uint key1, uint 
 
{
 
	void *result;
 
	HashNode *prev; // Used as output var for below function call
 
	HashNode *node = Hash_FindNode(this, key1, key2, &prev);
 
	HashNode *node = this->FindNode(key1, key2, &prev);
 

	
 
	if (node == NULL) {
 
		/* not found */
 
@@ -492,7 +492,7 @@ void *Hash::DeleteValue(uint key1, uint 
 
void *Hash::Set(uint key1, uint key2, void *value)
 
{
 
	HashNode *prev;
 
	HashNode *node = Hash_FindNode(this, key1, key2, &prev);
 
	HashNode *node = this->FindNode(key1, key2, &prev);
 

	
 
	if (node != NULL) {
 
		/* Found it */
 
@@ -526,7 +526,7 @@ void *Hash::Set(uint key1, uint key2, vo
 
 */
 
void *Hash::Get(uint key1, uint key2) const
 
{
 
	HashNode *node = Hash_FindNode(this, key1, key2, NULL);
 
	HashNode *node = this->FindNode(key1, key2, NULL);
 

	
 
#ifdef HASH_DEBUG
 
	debug("Found node: %p", node);
src/pathfinder/npf/queue.h
Show inline comments
 
@@ -108,6 +108,7 @@ protected:
 
#ifdef HASH_STATS
 
	void PrintStatistics() const;
 
#endif
 
	HashNode *FindNode(uint key1, uint key2, HashNode** prev_out) const;
 
};
 

	
 
#endif /* QUEUE_H */
0 comments (0 inline, 0 general)