From 827ae81806714d824512ed5165e7327e02564432 Mon Sep 17 00:00:00 2001 From: cirdan Date: Sat, 25 Jan 2014 17:01:06 +0100 Subject: [PATCH] Add new method Astar::ReplaceNode Add a new method Astar::ReplaceNode to encapsulate replacement of an open node by a better alternative. --- src/pathfinder/yapf/astar.hpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pathfinder/yapf/astar.hpp b/src/pathfinder/yapf/astar.hpp index 788bf2835..65793fded 100644 --- a/src/pathfinder/yapf/astar.hpp +++ b/src/pathfinder/yapf/astar.hpp @@ -198,6 +198,17 @@ public: m_closed.Push(item); } + /** Replace an existing (open) node. */ + inline void ReplaceNode (const Key &key, Node *n1, const Node *n2) + { + /* pop old node from open list and queue */ + PopOpenNode (key); + /* update old node with new data */ + *n1 = *n2; + /* add updated node to open list and queue */ + InsertOpenNode (*n1); + } + /** Insert a new initial node. */ inline void InsertInitialNode (Node *n) { @@ -216,11 +227,7 @@ public: /* two initial nodes with same key; * pick the one with the lowest cost */ if (n->GetCostEstimate() < m->GetCostEstimate()) { - /* update the old node with value from new one */ - PopOpenNode(key); - *m = *n; - /* add the updated old node back to open list */ - InsertOpenNode(*m); + ReplaceNode (key, m, n); } } } @@ -239,11 +246,7 @@ public: /* another node exists with the same key in the open list * is it better than new one? */ if (n->GetCostEstimate() < m->GetCostEstimate()) { - /* update the old node with value from new one */ - PopOpenNode(key); - *m = *n; - /* add the updated old node back to open list */ - InsertOpenNode(*m); + ReplaceNode (key, m, n); } return; } -- 2.11.4.GIT