• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Relationship between -isEqual and -hash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Relationship between -isEqual and -hash


  • Subject: Re: Relationship between -isEqual and -hash
  • From: "Jeffrey J. Early" <email@hidden>
  • Date: Sat, 20 Jan 2007 16:15:38 -0800
  • Thread-topic: Relationship between -isEqual and -hash

on 1/19/07 1:52 PM, John Stiles at email@hidden wrote:

> On Jan 19, 2007, at 1:46 PM, Jeffrey J. Early wrote:
>
>> In my code I have a dictionary that I want to behave in a
>> particular way. I'm using objects as keys where if two objects are
>> 'close enough', they will return the same value from the
>> dictionary, even if these objects aren't equal in the -isEqual:
>> sense. So when objects are 'close enough', I have them return the
>> same hash value.
>
> This should be all right. If any outside code is assuming that equal
> hashes means perfect equality, that code is broken.

It turns out that while it is true that equal hashes doesn't imply -isEqual:
must be true (thanks for your answer), my attempted application of this was
flawed.

NSDictionary is too clever -- after it finds the keyed-object in its hash
table using the hash value, it *then* runs an -isEqual on the two objects. I
probably should have realized this... Usage of -hash is just an optimization
in this case, -isEqual is really what it's trying to get at.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Relationship between -isEqual and -hash
      • From: John Stiles <email@hidden>
References: 
 >Re: Relationship between -isEqual and -hash (From: John Stiles <email@hidden>)

  • Prev by Date: Re: [NSApp mainMenu] = null!!!
  • Next by Date: Re: Relationship between -isEqual and -hash
  • Previous by thread: Re: Relationship between -isEqual and -hash
  • Next by thread: Re: Relationship between -isEqual and -hash
  • Index(es):
    • Date
    • Thread