<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>script/perf_polaris.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,12 @@
-require 'sorted_list'
+
+require 'algorithms'
+include Containers
+
+class PriorityQueue
+  def each(&amp;block)
+    @heap.instance_variable_get(&quot;@stored&quot;).values.each &amp;block
+  end
+end
 
 # Polaris is a star that guides, aka &quot;The North Star&quot;.  It implements the A* algorithm.
 class Polaris
@@ -13,14 +21,15 @@ class Polaris
     return nil if @map.blocked?(from, unit_type) || @map.blocked?(to, unit_type)
     from_element = PathElement.new(from)
     from_element.dist_from = @map.distance(from,to)
-    open = SortedList.new [from_element]
-    closed = SortedList.new
+    open = PriorityQueue.new { |x, y| (x &lt;=&gt; y) == -1 }
+    open.push from_element, from_element.rating
+    closed = SplayTreeMap.new
     step = 0
     
     until open.empty? || step &gt; max_depth
       step += 1
       
-      current_element = open.shift
+      current_element = open.pop
       @nodes_considered += 1
       
       loc = current_element.location
@@ -33,21 +42,27 @@ class Polaris
 
         return path
       else
-        closed.add current_element
+        closed.push current_element.location, current_element
         @map.neighbors(loc).each do |next_door|
           el = PathElement.new(next_door,current_element)
-          closed_el = closed.find(el)
-          next unless closed_el.nil?
+          next if closed.has_key? next_door
           
-          unless @map.blocked? next_door, unit_type
-            next_door_element = open.find el
+          if @map.blocked? next_door, unit_type
+            
+            #closed.push el.location, el
+          else
+            next_door_element = nil
+            open.each do |n|
+              next_door_element = el if n == el
+            end
+
             current_rating = current_element.cost_to + @map.cost(loc, next_door)
             if next_door_element.nil?
               # add to open
               el.cost_to = current_rating
               el.dist_from = @map.distance(next_door,to)
               
-              open &lt;&lt; el
+              open.push el, el.rating
             elsif next_door_element.cost_to &gt; current_rating
               # update the parent and cost
               next_door_element.parent = current_element
@@ -102,6 +117,7 @@ class PathElement
       0
     end
   end
+  
   def ==(other)
     return false if other.nil?
     @location == other.location</diff>
      <filename>lib/gamebox/ai/polaris.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,16 @@ class TwoDGridLocation
   def ==(other)
     @x == other.x and @y == other.y
   end
+  
+  def &lt;=&gt;(b)
+    ret = 1
+    if @x == b.x &amp;&amp; @y == b.y  
+      ret = 0
+    end
+    ret = -1 if @x &lt;= b.x &amp;&amp; @y &lt; b.y
+    return ret
+  end
+  
   def to_s
     &quot;#{@x},#{@y}&quot;
   end</diff>
      <filename>lib/gamebox/ai/two_d_grid_map.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d9cec624a4f5b089159a9afb717b1522df565246</id>
    </parent>
  </parents>
  <author>
    <name>Shawn Anderson</name>
    <email>shawn42@gmail.com</email>
  </author>
  <url>http://github.com/shawn42/gamebox/commit/8327ece4565a644d5ae4b17e53a534e59a8c3e4a</url>
  <id>8327ece4565a644d5ae4b17e53a534e59a8c3e4a</id>
  <committed-date>2009-05-31T14:10:52-07:00</committed-date>
  <authored-date>2009-05-31T14:10:52-07:00</authored-date>
  <message>took worst case perf of Polaris from 8.3 secs to 0.77; algorithms gem required for Polaris usage</message>
  <tree>103e4a2b46aec58b9c120eb13942807895b27241</tree>
  <committer>
    <name>Shawn Anderson</name>
    <email>shawn42@gmail.com</email>
  </committer>
</commit>
