• 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: When do I need to override hash?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When do I need to override hash?


  • Subject: Re: When do I need to override hash?
  • From: Clark Cox <email@hidden>
  • Date: Thu, 20 Aug 2009 14:01:28 -0700

On Thu, Aug 20, 2009 at 1:47 PM, Shawn Erickson<email@hidden> wrote:
> On Thu, Aug 20, 2009 at 1:37 PM, Kyle Sluder<email@hidden> wrote:
>
>> P: Two objects are equal.
>> Q: They have the same hash.
>>
>> P -> Q.
>>
>> Note that Q does not imply P.
>
> Or said another way...
>
> If the hash of ObjectA is equal to the hash of ObjectB then ObjectA
> _could_ be equal to ObjectB. If their hash differ they cannot be
> equal. The use of a hash to do a quick reject of equality is common
> for stl collections, java collections, Cocoa collections, etc.

Yes, and two different objects will have different pointer values. If
the hash is based on the pointer values, then two different objects
cannot have the same hash, regardless of whether or not they are
equal. Hence, that implementation of hash is broken for any object
that does anything other than a pointer comparison in -isEqual:.

--
Clark S. Cox III
email@hidden
_______________________________________________

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

  • Follow-Ups:
    • Re: When do I need to override hash?
      • From: Kyle Sluder <email@hidden>
References: 
 >When do I need to override hash? (From: Gideon King <email@hidden>)
 >Re: When do I need to override hash? (From: Gideon King <email@hidden>)
 >Re: When do I need to override hash? (From: "Adam R. Maxwell" <email@hidden>)
 >Re: When do I need to override hash? (From: Seth Willits <email@hidden>)
 >Re: When do I need to override hash? (From: David Duncan <email@hidden>)
 >Re: When do I need to override hash? (From: Clark Cox <email@hidden>)
 >Re: When do I need to override hash? (From: Bryan Henry <email@hidden>)
 >Re: When do I need to override hash? (From: Clark Cox <email@hidden>)
 >Re: When do I need to override hash? (From: Kyle Sluder <email@hidden>)
 >Re: When do I need to override hash? (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: When do I need to override hash?
  • Next by Date: Re: When do I need to override hash?
  • Previous by thread: Re: When do I need to override hash?
  • Next by thread: Re: When do I need to override hash?
  • Index(es):
    • Date
    • Thread