• 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: Implementing isEqual: and hash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing isEqual: and hash


  • Subject: Re: Implementing isEqual: and hash
  • From: Jeff Johnson <email@hidden>
  • Date: Sat, 23 Aug 2008 12:32:16 -0500

On Aug 23, 2008, at 12:26 PM, Jeff Johnson wrote:

If you compare primitives in -isEqual:, you should combine them (using
xor or the like) in -hash. If you compare objects by calling - isEqual:
on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all.

What's the motivation for combining hashes in this case? I've wondered what is the best thing to do when isEqual: is based on comparing multiple ivars; I typically just use one of them for the hash.

It's a documented requirement of the isEqual: and hash methods that the hash must be the same when isEqual: returns YES. Thus, whatever logic that returns YES in isEqual: must have some kind of match in hash.


-Jeff

Also, you're probably less likely to have collisions by combining.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


References: 
 >Implementing isEqual: and hash (From: Graham Cox <email@hidden>)
 >Re: Implementing isEqual: and hash (From: "Michael Ash" <email@hidden>)
 >Re: Implementing isEqual: and hash (From: "Adam R. Maxwell" <email@hidden>)
 >Re: Implementing isEqual: and hash (From: Jeff Johnson <email@hidden>)

  • Prev by Date: Re: Implementing isEqual: and hash
  • Next by Date: error codes
  • Previous by thread: Re: Implementing isEqual: and hash
  • Next by thread: Re: Implementing isEqual: and hash
  • Index(es):
    • Date
    • Thread