commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1140542 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph: DirectedGraph.java Graph.java model/DirectedMutableGraph.java model/UndirectedMutableGraph.java
Date Tue, 28 Jun 2011 11:47:23 GMT
Author: simonetripodi
Date: Tue Jun 28 11:47:22 2011
New Revision: 1140542

URL: http://svn.apache.org/viewvc?rev=1140542&view=rev
Log:
added missing Vertex (in|out)degree support

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/DirectedMutableGraph.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableGraph.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=1140542&r1=1140541&r2=1140542&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
Tue Jun 28 11:47:22 2011
@@ -34,6 +34,14 @@ public interface DirectedGraph<V extends
 {
 
     /**
+     * For a {@link Vertex}, the number of head endpoints adjacent to a node is called the
indegree.
+     *
+     * @param v the {@link Vertex} which indegree has to be returned.
+     * @return the number of head endpoints adjacent to a {@link Vertex}.
+     */
+    int getInDegree( V v );
+
+    /**
      * Returns the set of {@link Edge}s which are inbound to the {@link Vertex}.
      *
      * @param v the {@link Vertex} which inbound {@link Vertex}s have to be returned
@@ -42,6 +50,14 @@ public interface DirectedGraph<V extends
     Iterable<V> getInbound( V v );
 
     /**
+     * For a {@link Vertex}, the number of tail endpoints adjacent to a node is called the
outdegree.
+     *
+     * @param v the {@link Vertex} which indegree has to be returned.
+     * @return the number of head endpoints adjacent to a {@link Vertex}.
+     */
+    int getOutDegree( V v );
+
+    /**
      * Returns the set of {@link Vertex}s which lead away from the {@link Vertex}.
      *
      * @param v the {@link Vertex} which outbound {@link Vertex}s have to be returned

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=1140542&r1=1140541&r2=1140542&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 Tue Jun
28 11:47:22 2011
@@ -59,6 +59,15 @@ public interface Graph<V extends Vertex,
     int getSize();
 
     /**
+     * The degree (or valency) of a {@link Vertex} of a {@link Graph}
+     * is the number of {@link Edge}s incident to the {@link Vertex}.
+     *
+     * @param v the {@link Vertex} which degree has to be returned.
+     * @return the number of {@link Edge}s incident to the {@link Vertex}.
+     */
+    int getDegree( V v );
+
+    /**
      * Returns all vertices which touch this vertex.
      * 
      * @return all vertices which touch this vertex.

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=1140542&r1=1140541&r2=1140542&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
Tue Jun 28 11:47:22 2011
@@ -46,7 +46,23 @@ public class DirectedMutableGraph<V exte
     /**
      * {@inheritDoc}
      */
-    public Iterable<V> getInbound( V v )
+    public final int getDegree( V v )
+    {
+        return getInDegree( v ) + getOutDegree( v );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public final int getInDegree( V v )
+    {
+        return inbound.get( v ).size();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public final Iterable<V> getInbound( V v )
     {
         return inbound.get( v );
     }
@@ -54,7 +70,15 @@ public class DirectedMutableGraph<V exte
     /**
      * {@inheritDoc}
      */
-    public Iterable<V> getOutbound( V v )
+    public final int getOutDegree( V v )
+    {
+        return outbound.get( v ).size();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public final Iterable<V> getOutbound( V v )
     {
         return outbound.get( v );
     }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableGraph.java?rev=1140542&r1=1140541&r2=1140542&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableGraph.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/UndirectedMutableGraph.java
Tue Jun 28 11:47:22 2011
@@ -37,6 +37,14 @@ public class UndirectedMutableGraph<V ex
     /**
      * {@inheritDoc}
      */
+    public final int getDegree( V v )
+    {
+        return getAdjacencyList().get( v ).size() * 2;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void decorateAddVertex( V v )
     {



Mime
View raw message