Permalink
Browse files

Further >4x speedup by not copying/sorting the open list every iterat…

…ion.

Instead I just do an O(n) traversal over openSet.Values, rather than a... What is it -- O(n log n) operation to sort it all?

Not as good as a red-black tree, a splay tree, or the ever-mythical HOT-queue, but better.
  • Loading branch information...
Jon Frisby Jon Frisby
Jon Frisby authored and Jon Frisby committed Dec 18, 2009
1 parent 30c1945 commit d674cdef4aded0079ca2469af509247c63d10c70
Showing with 14 additions and 4 deletions.
  1. +14 −4 Source/Seeker.cs
View
@@ -406,7 +406,7 @@ private IEnumerator DoSeek()
{
Hashtable closedSet = new Hashtable();
Hashtable openSet = new Hashtable();
- ArrayList openSetValues = new ArrayList();
+// ArrayList openSetValues = new ArrayList();
PathData currentPath = null;
float endTime;
@@ -422,9 +422,19 @@ private IEnumerator DoSeek()
while( seeking && openSet.Count > 0 )
{
- openSetValues = new ArrayList( openSet.Values );
- openSetValues.Sort();
- currentPath = ( PathData )openSetValues[ 0 ];
+// openSetValues = new ArrayList( openSet.Values );
+// openSetValues.Sort();
+// currentPath = ( PathData )openSetValues[ 0 ];
+ PathData lowestValue = null;
+ IEnumerator e = openSet.Values.GetEnumerator();
+ e.MoveNext();
+ lowestValue = (PathData)e.Current;
+ while(e.MoveNext()) {
+ PathData p = (PathData)e.Current;
+ if(p.CompareTo(lowestValue) < 0)
+ lowestValue = p;
+ }
+ currentPath = lowestValue;
if( currentPath.Destination == End )
{

0 comments on commit d674cde

Please sign in to comment.