You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/06/24 15:16:28 UTC
svn commit: r1139293 - in
/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph:
DirectedGraph.java Graph.java model/BaseGraph.java
model/DirectedMutableGraph.java shortestpath/AStar.java
shortestpath/Dijkstra.java visit/Visit.java
Author: simonetripodi
Date: Fri Jun 24 13:16:28 2011
New Revision: 1139293
URL: http://svn.apache.org/viewvc?rev=1139293&view=rev
Log:
much better exposing Iterable instead of the whole Set of Vertex/Edge
that would fit much better in scenarios where lazyloading is required because Vertex/Edge come from the network or from a BigData storage...
Modified:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/DirectedGraph.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Graph.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableGraph.java
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
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/visit/Visit.java
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/DirectedGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/DirectedGraph.java?rev=1139293&r1=1139292&r2=1139293&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/DirectedGraph.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/DirectedGraph.java Fri Jun 24 13:16:28 2011
@@ -19,8 +19,6 @@ package org.apache.commons.graph;
* under the License.
*/
-import java.util.Set;
-
/**
* A {@code DirectedGraph} or <i>digraph</i> is an ordered pair {@code D = ( V, E )} with
* <ul>
@@ -41,7 +39,7 @@ public interface DirectedGraph<V extends
* @param v the {@link Vertex} which inbound {@link Edge}s have to be returned
* @return the set of {@link Edge}s which are inbound to the {@link Vertex}.
*/
- Set<E> getInbound( V v );
+ Iterable<E> getInbound( V v );
/**
* Returns the set of {@link Edge}s which lead away from the {@link Vertex}.
@@ -49,6 +47,6 @@ public interface DirectedGraph<V extends
* @param v the {@link Vertex} which outbound {@link Edge}s have to be returned
* @return the set of {@link Edge}s which lead away from the {@link Vertex}.
*/
- Set<E> getOutbound( V v );
+ Iterable<E> getOutbound( V v );
}
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Graph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Graph.java?rev=1139293&r1=1139292&r2=1139293&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Graph.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/Graph.java Fri Jun 24 13:16:28 2011
@@ -19,8 +19,6 @@ package org.apache.commons.graph;
* under the License.
*/
-import java.util.Set;
-
/**
* A Graph data structure consists of a finite (and possibly mutable) set of ordered pairs, called {@link Edge}s or
* arcs, of certain entities called {@link Vertex} or node. As in mathematics, an {@link Edge} {@code (x,y)} is said to
@@ -37,7 +35,7 @@ public interface Graph<V extends Vertex,
*
* @return the total set of Vertices in the graph.
*/
- Set<V> getVertices();
+ Iterable<V> getVertices();
/**
* Returns the <i>order</i> of a Graph (the number of Vertices);
@@ -51,7 +49,7 @@ public interface Graph<V extends Vertex,
*
* @return the total set of Edges in the graph.
*/
- Set<E> getEdges();
+ Iterable<E> getEdges();
/**
* Returns the <i>size</i> of a Graph (the number of Edges)
@@ -65,7 +63,7 @@ public interface Graph<V extends Vertex,
*
* @return all edges which touch this vertex, where the input vertex is in the edge head.
*/
- Set<E> getEdges( V v );
+ Iterable<E> getEdges( V v );
/**
* Returns the edge with vertex source and target.
@@ -81,6 +79,6 @@ public interface Graph<V extends Vertex,
*
* @return the set of {@link Vertex} on this Edge.
*/
- Set<V> getVertices( E e );
+ Iterable<V> getVertices( E e );
}
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java?rev=1139293&r1=1139292&r2=1139293&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java Fri Jun 24 13:16:28 2011
@@ -19,6 +19,7 @@ package org.apache.commons.graph.model;
* under the License.
*/
+import static java.util.Collections.unmodifiableCollection;
import static java.util.Collections.unmodifiableSet;
import java.util.HashMap;
@@ -49,7 +50,7 @@ public abstract class BaseGraph<V extend
/**
* {@inheritDoc}
*/
- public final Set<V> getVertices()
+ public final Iterable<V> getVertices()
{
return unmodifiableSet( adjacencyList.keySet() );
}
@@ -65,9 +66,9 @@ public abstract class BaseGraph<V extend
/**
* {@inheritDoc}
*/
- public final Set<E> getEdges()
+ public final Iterable<E> getEdges()
{
- return unmodifiableSet( new HashSet<E>( indexedEdges.values() ) );
+ return unmodifiableCollection( indexedEdges.values() );
}
/**
@@ -81,7 +82,7 @@ public abstract class BaseGraph<V extend
/**
* {@inheritDoc}
*/
- public final Set<E> getEdges( V v )
+ public final Iterable<E> getEdges( V v )
{
return unmodifiableSet( adjacencyList.get( v ) );
}
@@ -97,7 +98,7 @@ public abstract class BaseGraph<V extend
/**
* {@inheritDoc}
*/
- public final Set<V> getVertices( E e )
+ public final Iterable<V> getVertices( E e )
{
Set<V> vertices = new LinkedHashSet<V>();
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableGraph.java?rev=1139293&r1=1139292&r2=1139293&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableGraph.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/DirectedMutableGraph.java Fri Jun 24 13:16:28 2011
@@ -46,7 +46,7 @@ public class DirectedMutableGraph<V exte
/**
* {@inheritDoc}
*/
- public Set<E> getInbound( V v )
+ public Iterable<E> getInbound( V v )
{
return inbound.get( v );
}
@@ -54,7 +54,7 @@ public class DirectedMutableGraph<V exte
/**
* {@inheritDoc}
*/
- public Set<E> getOutbound( V v )
+ public Iterable<E> getOutbound( V v )
{
return outbound.get( v );
}
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java?rev=1139293&r1=1139292&r2=1139293&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java Fri Jun 24 13:16:28 2011
@@ -74,7 +74,7 @@ public final class AStar
final Set<V> closedSet = new HashSet<V>();
// The set of tentative nodes to be evaluated.
- final PriorityQueue<V> openSet = new PriorityQueue<V>( graph.getVertices().size(), fScores );
+ final PriorityQueue<V> openSet = new PriorityQueue<V>( graph.getOrder(), fScores );
openSet.add( start );
// The of navigated nodes
@@ -95,8 +95,8 @@ public final class AStar
closedSet.add( current );
@SuppressWarnings( "unchecked" )
- Set<WE> edges = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, WE>) graph ).getOutbound( current )
- : graph.getEdges( current );
+ Iterable<WE> edges = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, WE>) graph ).getOutbound( current )
+ : graph.getEdges( current );
for ( WE edge : edges )
{
V v = edge.getTail();
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=1139293&r1=1139292&r2=1139293&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 Fri Jun 24 13:16:28 2011
@@ -63,7 +63,7 @@ public final class Dijkstra
final ShortestDistances<V> shortestDistances = new ShortestDistances<V>();
shortestDistances.setWeight( source, 0D );
- final PriorityQueue<V> unsettledNodes = new PriorityQueue<V>( graph.getVertices().size(), shortestDistances );
+ final PriorityQueue<V> unsettledNodes = new PriorityQueue<V>( graph.getOrder(), shortestDistances );
unsettledNodes.add( source );
final Set<V> settledNodes = new HashSet<V>();
Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/Visit.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/Visit.java?rev=1139293&r1=1139292&r2=1139293&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/Visit.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/Visit.java Fri Jun 24 13:16:28 2011
@@ -91,8 +91,8 @@ public final class Visit
handler.discoverVertex( v );
- Set<E> edges = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, E>) graph ).getOutbound( v )
- : graph.getEdges( v );
+ Iterable<E> edges = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, E>) graph ).getOutbound( v )
+ : graph.getEdges( v );
for ( E e : edges )
{
V w = e.getTail();
@@ -168,8 +168,8 @@ public final class Visit
handler.discoverVertex( v );
- Set<E> edges = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, E>) graph ).getOutbound( v )
- : graph.getEdges( v );
+ Iterable<E> edges = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, E>) graph ).getOutbound( v )
+ : graph.getEdges( v );
for ( E e : edges )
{
V w = e.getTail();