Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'assumed': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'hash': 0.09; 'message- id:@stoneleaf.us': 0.09; "object's": 0.09; 'received:gator410.hostgator.com': 0.09; 'url:dev': 0.09; 'wrong,': 0.09; '~ethan~': 0.09; 'wrote:': 0.14; 'eckhardt': 0.16; 'equal,': 0.16; 'equal.': 0.16; 'furman': 0.16; 'instances,': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'stored.': 0.16; "wouldn't": 0.17; 'cc:addr:python-list': 0.17; 'work,': 0.20; 'header:In-Reply- To:1': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'objects': 0.23; 'code': 0.24; 'somebody': 0.25; 'stored': 0.25; 'do,': 0.25; '(and': 0.25; 'compare': 0.26; "i'm": 0.27; 'bit': 0.30; "won't": 0.30; 'cc:addr:python.org': 0.30; 'equal': 0.31; 'change.': 0.32; 'does': 0.33; 'familiar': 0.33; "isn't": 0.33; 'header:User-Agent:1': 0.35; 'instances': 0.35; 'several': 0.36; 'something': 0.37; 'change': 0.37; 'url:docs': 0.37; 'case': 0.37; 'another': 0.37; 'two': 0.37; 'url:python': 0.38; 'hoping': 0.38; 'url:org': 0.38; 'though': 0.38; 'docs': 0.38; 'too,': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'said': 0.39; "i'd": 0.39; 'map': 0.39; 'happen': 0.60; 'your': 0.60; 'property': 0.64; 'received:websitewelcome.com': 0.67; 'received:69.93': 0.67; 'care': 0.72; 'derive': 0.84; 'map.': 0.84; 'about,': 0.91; 'ask.': 0.91 Date: Fri, 20 May 2011 11:38:41 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Ulrich Eckhardt 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-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1793 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list 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: 32 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305915987 news.xs4all.nl 49045 [::ffff:82.94.164.166]:34575 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5868 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. Looking for object1 will then not turn up > with object2, even though they are equal. In this case this is the behavior I want. > If this is something you don't > care about, and all you care about is identity, then I'd derive the hash > from each object's ID. This won't work, as objects of the same type that compare equal should (and do, in my code) hash equal. > This ID has another property which is something that is assumed for hashes, > and your code seems a bit to get that wrong, too, and that is that the hash > must not change. The hash does not change on the instances, and is the same for all instances of my type that compare equal. ~Ethan~