Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.04; 'from:addr:python': 0.09; 'hash': 0.09; 'integer,': 0.09; 'url:dev': 0.09; 'wrote:': 0.14; '(is': 0.16; 'eckhardt': 0.16; 'equal,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'furman': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply- to:addr:python-list': 0.16; 'stored.': 0.16; "wouldn't": 0.17; 'header:In-Reply-To:1': 0.21; 'objects': 0.23; 'somebody': 0.25; 'index': 0.25; 'received:84': 0.25; 'stored': 0.25; 'compare': 0.26; "i'm": 0.27; 'elements': 0.29; 'array': 0.30; 'looks': 0.31; 'equal': 0.31; 'to:addr:python-list': 0.33; 'familiar': 0.33; "isn't": 0.33; 'it?': 0.33; 'header:User-Agent:1': 0.35; 'reply- to:addr:python.org': 0.35; 'several': 0.36; 'url:docs': 0.37; 'two': 0.37; 'url:python': 0.38; 'could': 0.38; 'hoping': 0.38; 'url:org': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'said': 0.39; 'map': 0.39; 'to:addr:python.org': 0.39; 'happen': 0.60; 'header :Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'map.': 0.84; 'ask.': 0.91; 'spell': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlQGAHqN1k3Unw4S/2dsb2JhbACEXZNEjXt4shGQfIErg2eBBwSUQIpH Date: Fri, 20 May 2011 16:50:02 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: python-list@python.org Subject: Re: hash values and equality References: <4DD2C2A5.3080403@stoneleaf.us> <4DD2D89D.4000303@stoneleaf.us> <4DD2F661.2050005@stoneleaf.us> <0deha8-6u9.ln1@satorlaser.homedns.org> In-Reply-To: <0deha8-6u9.ln1@satorlaser.homedns.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305906606 news.xs4all.nl 49178 [::ffff:82.94.164.166]:33342 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5856 On 20/05/2011 07:33, Ulrich Eckhardt wrote: > Ethan Furman wrote: >> Several folk have said that objects that compare equal must hash equal, >> and the docs also state this >> http://docs.python.org/dev/reference/datamodel.html#object.__hash__ >> >> I'm hoping somebody can tell me what horrible thing will happen if this >> isn't the case? > > If you were familiar with what a hash map is, you wouldn't ask. The thing is > that the hash is used to look up the place in the map where the thing is > stored. If two equal objects have different hashes, they will be stored in > different places in the hash map. [snip] Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of array elements to give an index into the array, so different hashes could give the same index, and objects with different hashes could be stored in the same 'bucket'.