commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1135959 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath: Dijkstra.java ShortestDistanceComparator.java ShortestDistances.java
Date Wed, 15 Jun 2011 08:49:24 GMT
Author: simonetripodi
Date: Wed Jun 15 08:49:24 2011
New Revision: 1135959

URL: http://svn.apache.org/viewvc?rev=1135959&view=rev
Log:
simplified ShortesDistance design; it maintains Vertices distances and is able to determine
which Vertex has the shortest distance between 2 Vertices

Removed:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestDistanceComparator.java
Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestDistances.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java?rev=1135959&r1=1135958&r2=1135959&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
Wed Jun 15 08:49:24 2011
@@ -63,7 +63,7 @@ public final class Dijkstra
         final ShortestDistances<V> shortestDistances = new ShortestDistances<V>();
 
         final PriorityQueue<V> unsettledNodes =
-            new PriorityQueue<V>( graph.getVertices().size(), new ShortestDistanceComparator<V>(
shortestDistances ) );
+            new PriorityQueue<V>( graph.getVertices().size(), shortestDistances );
         unsettledNodes.add( source );
 
         final Set<V> settledNodes = new HashSet<V>();

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestDistances.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestDistances.java?rev=1135959&r1=1135958&r2=1135959&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestDistances.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/ShortestDistances.java
Wed Jun 15 08:49:24 2011
@@ -19,12 +19,14 @@ package org.apache.commons.graph.shortes
  * under the License.
  */
 
+import java.util.Comparator;
 import java.util.HashMap;
 
 import org.apache.commons.graph.Vertex;
 
 final class ShortestDistances<V extends Vertex>
     extends HashMap<V, Double>
+    implements Comparator<V>
 {
 
     private static final long serialVersionUID = 568538689459177637L;
@@ -39,4 +41,12 @@ final class ShortestDistances<V extends 
         return (distance == null) ? Double.POSITIVE_INFINITY : distance;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public int compare( V left, V right )
+    {
+        return get( left ).compareTo( get( right ) );
+    }
+
 }



Mime
View raw message