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.