Return-Path: Delivered-To: apmail-lucene-mahout-dev-archive@minotaur.apache.org Received: (qmail 45081 invoked from network); 21 Jan 2010 20:16:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jan 2010 20:16:18 -0000 Received: (qmail 32104 invoked by uid 500); 21 Jan 2010 20:16:17 -0000 Delivered-To: apmail-lucene-mahout-dev-archive@lucene.apache.org Received: (qmail 32057 invoked by uid 500); 21 Jan 2010 20:16:17 -0000 Mailing-List: contact mahout-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mahout-dev@lucene.apache.org Delivered-To: mailing list mahout-dev@lucene.apache.org Received: (qmail 32047 invoked by uid 99); 21 Jan 2010 20:16:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2010 20:16:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2010 20:16:15 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 97A07234C4B3 for ; Thu, 21 Jan 2010 12:15:54 -0800 (PST) Message-ID: <1122081423.402841264104954619.JavaMail.jira@brutus.apache.org> Date: Thu, 21 Jan 2010 20:15:54 +0000 (UTC) From: "Sean Owen (JIRA)" To: mahout-dev@lucene.apache.org Subject: [jira] Commented: (MAHOUT-207) AbstractVector.hashCode() should not care about the order of iteration over elements In-Reply-To: <2064892669.1259004099682.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MAHOUT-207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803468#action_12803468 ] Sean Owen commented on MAHOUT-207: ---------------------------------- Was this committed in some way? it doesn't seem like the patch was. Shall I? I agree it's a bug and would rather have it fixed, then continue discussing better ways to do it, if desired. > AbstractVector.hashCode() should not care about the order of iteration over elements > ------------------------------------------------------------------------------------ > > Key: MAHOUT-207 > URL: https://issues.apache.org/jira/browse/MAHOUT-207 > Project: Mahout > Issue Type: Bug > Components: Math > Affects Versions: 0.2 > Environment: all > Reporter: Jake Mannix > Assignee: Grant Ingersoll > Fix For: 0.3 > > Attachments: MAHOUT-207.patch > > > As was discussed in MAHOUT-165, hashCode can be implemented simply like this: > {code} > public int hashCode() { > final int prime = 31; > int result = prime + ((name == null) ? 0 : name.hashCode()); > result = prime * result + size(); > Iterator iter = iterateNonZero(); > while (iter.hasNext()) { > Element ele = iter.next(); > long v = Double.doubleToLongBits(ele.get()); > result += (ele.index() * (int)(v^(v>>32))); > } > return result; > } > {code} > which obviates the need to sort the elements in the case of a random access hash-based implementation. Also, (ele.index() * (int)(v^(v>>32)) ) == 0 when v = Double.doubleToLongBits(0d), which avoids the wrong hashCode() for sparse vectors which have zero elements returned from the iterateNonZero() iterator. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.