Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2648791AC for ; Wed, 30 May 2012 09:23:28 +0000 (UTC) Received: (qmail 75534 invoked by uid 500); 30 May 2012 09:23:24 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 75198 invoked by uid 500); 30 May 2012 09:23:20 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 75173 invoked by uid 99); 30 May 2012 09:23:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2012 09:23:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2012 09:23:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C5ADE2388865 for ; Wed, 30 May 2012 09:22:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1344166 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/utilities/OrderedTuple.java Date: Wed, 30 May 2012 09:22:58 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120530092258.C5ADE2388865@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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.