hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjungb...@apache.org
Subject svn commit: r1340796 - in /incubator/hama/trunk: core/src/main/java/org/apache/hama/bsp/HashPartitioner.java graph/src/main/java/org/apache/hama/graph/Vertex.java
Date Sun, 20 May 2012 18:42:47 GMT
Author: tjungblut
Date: Sun May 20 18:42:26 2012
New Revision: 1340796

URL: http://svn.apache.org/viewvc?rev=1340796&view=rev
Log:
vertex should override hashcode to work correctly

Modified:
    incubator/hama/trunk/core/src/main/java/org/apache/hama/bsp/HashPartitioner.java
    incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java

Modified: incubator/hama/trunk/core/src/main/java/org/apache/hama/bsp/HashPartitioner.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/core/src/main/java/org/apache/hama/bsp/HashPartitioner.java?rev=1340796&r1=1340795&r2=1340796&view=diff
==============================================================================
--- incubator/hama/trunk/core/src/main/java/org/apache/hama/bsp/HashPartitioner.java (original)
+++ incubator/hama/trunk/core/src/main/java/org/apache/hama/bsp/HashPartitioner.java Sun May
20 18:42:26 2012
@@ -25,7 +25,7 @@ public class HashPartitioner<K, V> imple
 
   @Override
   public int getPartition(K key, V value, int numTasks) {
-    return key.hashCode() % numTasks;
+    return Math.abs(key.hashCode() % numTasks);
   }
 
 }

Modified: incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java?rev=1340796&r1=1340795&r2=1340796&view=diff
==============================================================================
--- incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java (original)
+++ incubator/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java Sun May 20
18:42:26 2012
@@ -28,8 +28,8 @@ import org.apache.hama.bsp.BSPPeer;
 public abstract class Vertex<ID_TYPE extends Writable, MSG_TYPE extends Writable, EDGE_VALUE_TYPE
extends Writable>
     implements VertexInterface<ID_TYPE, MSG_TYPE, EDGE_VALUE_TYPE> {
 
-  private MSG_TYPE value;
   private ID_TYPE vertexID;
+  private MSG_TYPE value;
   protected GraphJobRunner<ID_TYPE, MSG_TYPE, EDGE_VALUE_TYPE> runner;
   protected BSPPeer<VertexWritable<ID_TYPE, MSG_TYPE>, VertexArrayWritable, Writable,
Writable, GraphJobMessage> peer;
   public List<Edge<ID_TYPE, EDGE_VALUE_TYPE>> edges;
@@ -117,6 +117,31 @@ public abstract class Vertex<ID_TYPE ext
   }
 
   @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((vertexID == null) ? 0 : vertexID.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Vertex<?, ?, ?> other = (Vertex<?, ?, ?>) obj;
+    if (vertexID == null) {
+      if (other.vertexID != null)
+        return false;
+    } else if (!vertexID.equals(other.vertexID))
+      return false;
+    return true;
+  }
+
+  @Override
   public String toString() {
     return getVertexID() + (getValue() != null ? " = " + getValue() : "")
         + " // " + edges;



Mime
View raw message