mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smar...@apache.org
Subject svn commit: r1546379 - in /mahout/trunk: CHANGELOG core/src/main/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtils.java core/src/test/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtilsTest.java
Date Thu, 28 Nov 2013 14:46:54 GMT
Author: smarthi
Date: Thu Nov 28 14:46:54 2013
New Revision: 1546379

URL: http://svn.apache.org/r1546379
Log:
MAHOUT-1261: TasteHadoopUtils.idToIndex can return an int that has size Integer.MAX_VALUE

Added:
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtilsTest.java
Modified:
    mahout/trunk/CHANGELOG
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtils.java

Modified: mahout/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/mahout/trunk/CHANGELOG?rev=1546379&r1=1546378&r2=1546379&view=diff
==============================================================================
--- mahout/trunk/CHANGELOG (original)
+++ mahout/trunk/CHANGELOG Thu Nov 28 14:46:54 2013
@@ -50,6 +50,8 @@ Release 0.9 - unreleased
 
   MAHOUT-1275: Dropped bz2 distribution format for source and binaries (sslavic)
 
+  MAHOUT-1261: TasteHadoopUtils.idToIndex can return an int that has size Integer.MAX_VALUE
(Carl Clark, smarthi)
+
 Release 0.8 - 2013-07-25
 
   MAHOUT-1272: Parallel SGD matrix factorizer for SVDrecommender (Peng Cheng via ssc)

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtils.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtils.java?rev=1546379&r1=1546378&r2=1546379&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtils.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtils.java
Thu Nov 28 14:46:54 2013
@@ -51,10 +51,10 @@ public final class TasteHadoopUtils {
   }
 
   /**
-   * Maps a long to an int
+   * Maps a long to an int with range of 0 to Integer.MAX_VALUE-1
    */
   public static int idToIndex(long id) {
-    return 0x7FFFFFFF & Longs.hashCode(id);
+    return 0x7FFFFFFF & Longs.hashCode(id) % 0x7FFFFFFE;
   }
 
   public static int readID(String token, boolean usesLongIDs) {

Added: mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtilsTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtilsTest.java?rev=1546379&view=auto
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtilsTest.java
(added)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TasteHadoopUtilsTest.java
Thu Nov 28 14:46:54 2013
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.hadoop;
+
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.junit.Test;
+
+/** <p>Tests {@link TasteHadoopUtils}.</p> */
+public class TasteHadoopUtilsTest extends TasteTestCase {
+	
+  @Test
+  public void testWithinRange() {
+    assertTrue(TasteHadoopUtils.idToIndex(0) >= 0);
+    assertTrue(TasteHadoopUtils.idToIndex(0) < Integer.MAX_VALUE);
+
+    assertTrue(TasteHadoopUtils.idToIndex(1) >= 0);
+    assertTrue(TasteHadoopUtils.idToIndex(1) < Integer.MAX_VALUE);
+		
+    assertTrue(TasteHadoopUtils.idToIndex(Long.MAX_VALUE) >= 0);
+    assertTrue(TasteHadoopUtils.idToIndex(Long.MAX_VALUE) < Integer.MAX_VALUE);
+		
+    assertTrue(TasteHadoopUtils.idToIndex(Integer.MAX_VALUE) >= 0);
+    assertTrue(TasteHadoopUtils.idToIndex(Integer.MAX_VALUE) < Integer.MAX_VALUE);
+  }
+}



Mime
View raw message