Permalink
Browse files

Make pathfinding more than 2x faster by using a Hashtable for the clo…

…sed list, reducing lookups from O(n) to O(1).
  • Loading branch information...
Jon Frisby Jon Frisby
Jon Frisby authored and Jon Frisby committed Dec 18, 2009
1 parent af98833 commit 30c194504cfd527b3cee98391c2e08ab622058ca
Showing with 4 additions and 3 deletions.
  1. +4 −3 Source/Seeker.cs
View
@@ -404,8 +404,9 @@ public int CompareTo( object obj )
private IEnumerator DoSeek()
{
- ArrayList closedSet = new ArrayList(), openSetValues = new ArrayList();
+ Hashtable closedSet = new Hashtable();
Hashtable openSet = new Hashtable();
+ ArrayList openSetValues = new ArrayList();
PathData currentPath = null;
float endTime;
@@ -432,11 +433,11 @@ private IEnumerator DoSeek()
}
openSet.Remove( currentPath.Connection );
- closedSet.Add( currentPath.Connection );
+ closedSet[ currentPath.Connection ] = 1;
foreach( ConnectionAsset connection in currentPath.Connections )
{
- if( closedSet.Contains( connection ) || !ValidConnection( connection ) )
+ if( closedSet.ContainsKey( connection ) || !ValidConnection( connection ) )
{
continue;
}

0 comments on commit 30c1945

Please sign in to comment.