You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2012/05/30 11:22:58 UTC

svn commit: r1344166 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java

Author: luc
Date: Wed May 30 09:22:58 2012
New Revision: 1344166

URL: http://svn.apache.org/viewvc?rev=1344166&view=rev
Log:
Yet another attempt at computing hash for OrederedTuple.

JIRA: MATH-793

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java?rev=1344166&r1=1344165&r2=1344166&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java Wed May 30 09:22:58 2012
@@ -301,10 +301,23 @@ public class OrderedTuple implements Com
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
-        return Arrays.hashCode(components) * offset * (lsb << 7) +
-               ((posInf ?  43422 : 875342) *
-                (negInf ? 86535631 : 632442767) *
-                (nan ? 51108941 : 64234));
+        // the following constants are arbitrary small primes
+        final int multiplier = 37;
+        final int trueHash   = 97;
+        final int falseHash  = 71;
+
+        // hash fields and combine them
+        // (we rely on the multiplier to have different combined weights
+        //  for all int fields and all boolean fields)
+        int hash = Arrays.hashCode(components);
+        hash = hash * multiplier + offset;
+        hash = hash * multiplier + lsb;
+        hash = hash * multiplier + (posInf ? trueHash : falseHash);
+        hash = hash * multiplier + (negInf ? trueHash : falseHash);
+        hash = hash * multiplier + (nan    ? trueHash : falseHash);
+
+        return hash;
+
     }
 
     /** Get the components array.