summaryrefslogtreecommitdiff
path: root/src/pathfinder/npf
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-10-02 19:41:25 +0000
committeralberth <alberth@openttd.org>2010-10-02 19:41:25 +0000
commit15b784471e3fc0aa210399668294481fa7ceb99d (patch)
tree7a36abfbb28ebd3ba42e7f9c6226ba53d6dc5f81 /src/pathfinder/npf
parent4ed94825b2b149cc7da7d1827c4bc26988e72f03 (diff)
downloadopenttd-15b784471e3fc0aa210399668294481fa7ceb99d.tar.xz
(svn r20882) -Codechange: Make Hash_Set a method.
Diffstat (limited to 'src/pathfinder/npf')
-rw-r--r--src/pathfinder/npf/aystar.cpp4
-rw-r--r--src/pathfinder/npf/queue.cpp17
-rw-r--r--src/pathfinder/npf/queue.h6
3 files changed, 13 insertions, 14 deletions
diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp
index 571754002..f8f939894 100644
--- a/src/pathfinder/npf/aystar.cpp
+++ b/src/pathfinder/npf/aystar.cpp
@@ -43,7 +43,7 @@ void AyStar::ClosedListAdd(const PathNode *node)
/* Add a node to the ClosedList */
PathNode *new_node = MallocT<PathNode>(1);
*new_node = *node;
- Hash_Set(&this->ClosedListHash, node->node.tile, node->node.direction, new_node);
+ this->ClosedListHash.Set(node->node.tile, node->node.direction, new_node);
}
/* Checks if a node is in the OpenList
@@ -76,7 +76,7 @@ void AyStar::OpenListAdd(PathNode *parent, const AyStarNode *node, int f, int g)
new_node->g = g;
new_node->path.parent = parent;
new_node->path.node = *node;
- Hash_Set(&this->OpenListHash, node->tile, node->direction, new_node);
+ this->OpenListHash.Set(node->tile, node->direction, new_node);
/* Add it to the queue */
this->OpenListQueue.Push(new_node, f);
diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp
index 473f50c70..b9110d6d9 100644
--- a/src/pathfinder/npf/queue.cpp
+++ b/src/pathfinder/npf/queue.cpp
@@ -470,11 +470,14 @@ void *Hash_Delete(Hash *h, uint key1, uint key2)
return result;
}
-
-void *Hash_Set(Hash *h, uint key1, uint key2, void *value)
+/**
+ * Sets the value associated with the given key pair to the given value.
+ * Returns the old value if the value was replaced, NULL when it was not yet present.
+ */
+void *Hash::Set(uint key1, uint key2, void *value)
{
HashNode *prev;
- HashNode *node = Hash_FindNode(h, key1, key2, &prev);
+ HashNode *node = Hash_FindNode(this, key1, key2, &prev);
if (node != NULL) {
/* Found it */
@@ -486,9 +489,9 @@ void *Hash_Set(Hash *h, uint key1, uint key2, void *value)
/* It is not yet present, let's add it */
if (prev == NULL) {
/* The bucket is still empty */
- uint hash = h->hash(key1, key2);
- h->buckets_in_use[hash] = true;
- node = h->buckets + hash;
+ uint hash = this->hash(key1, key2);
+ this->buckets_in_use[hash] = true;
+ node = this->buckets + hash;
} else {
/* Add it after prev */
node = MallocT<HashNode>(1);
@@ -498,7 +501,7 @@ void *Hash_Set(Hash *h, uint key1, uint key2, void *value)
node->key1 = key1;
node->key2 = key2;
node->value = value;
- h->size++;
+ this->size++;
return NULL;
}
diff --git a/src/pathfinder/npf/queue.h b/src/pathfinder/npf/queue.h
index 6d42bae92..6ee5675c4 100644
--- a/src/pathfinder/npf/queue.h
+++ b/src/pathfinder/npf/queue.h
@@ -87,6 +87,7 @@ struct Hash {
bool *buckets_in_use;
void *Get(uint key1, uint key2) const;
+ void *Set(uint key1, uint key2, void *value);
/**
* Gets the current size of the hash.
@@ -105,11 +106,6 @@ struct Hash {
* is _not_ free()'d!
*/
void *Hash_Delete(Hash *h, uint key1, uint key2);
-/**
- * Sets the value associated with the given key pair to the given value.
- * Returns the old value if the value was replaced, NULL when it was not yet present.
- */
-void *Hash_Set(Hash *h, uint key1, uint key2, void *value);
/* Call these function to create/destroy a hash */