• 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: Greg Parker <email@hidden>
  • Date: Thu, 20 Aug 2009 14:25:14 -0700

On Aug 20, 2009, at 12:00 PM, Seth Willits wrote:
From the docs:
If a mutable object is added to a collection that uses hash values to determine the object’s position in the collection, the value returned by thehash method of the object must not change while the object is in the collection. Therefore, either the hash method must not rely on any of the object’s internal state information or you must make sure the object’s internal state information does not change while the object is in the collection.

That's pretty hard to deal with.

Returning 0 is certainly simpler :p

Simpler, but slower. Performance of NSSet and NSDictionary in particular will drop dramatically if the -hash values of unequal keys are always the same.


If two objects are -isEqual: to each other, then they MUST have the same -hash value. NSSet and NSDictionary will behave incorrectly if you do this wrong for their keys.

If two objects are not -isEqual: to each other, then they SHOULD have different -hash values. They MAY have the same -hash value, but NSSet and NSDictionary will be slower if that happens too often.


-- Greg Parker email@hidden Runtime Wrangler


_______________________________________________

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: 
 >When do I need to override hash? (From: Gideon King <email@hidden>)
 >Re: When do I need to override hash? (From: Nathan Vander Wilt <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>)

  • Prev by Date: Re: When do I need to override hash?
  • Next by Date: Field editor for custom tableview cells contains wrong string
  • 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