• 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: Quincey Morris <email@hidden>
  • Date: Thu, 20 Aug 2009 22:48:04 -0700

On Aug 20, 2009, at 22:05, Jeff Laing wrote:

Without wanting to keep the thread going forever, can I just ask why we would presume this?

In fact, if I were implementing NSDictionary I'd assume the reverse, that I was not allowed to assume that an objects hash would not change.

Is there some documentation on this restriction on the types of objects that can be put into an NSDictionary?

Seth explicitly quoted the documentation of this restriction in the post to which I replied:


(This is from the documentation for 'hash'.)

"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 the hash method of the object must not change while the object is in the collection."

It is absolutely possible that NSDictionary does not use hash values "to determine the object's position in the collection" and so would be exempt from the above restriction.


It's also possible (maybe even likely) that NSArray doesn't use hash values "to determine the object's position in the collection".

So, now that you mention it, I guess we don't know for sure which collections do and do not depend on hash values for this purpose. (It's certainly conceivable that both NSDictionary and NSArray do use object hash values to manage their internal storage, perhaps only for very large collections.) Sounds like something that ought to be documented explicitly somewhere.

In practice, it's not of general concern, because it doesn't seem generally useful to have objects that are safely collectable only in certain kinds of collections. For those specific cases where you had mutable objects with "unstable" hash values, you'd have to choose and bet on your interpretation of which collections it was safe to use.


_______________________________________________

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: Jeffrey Oleander <email@hidden>
    • Re: When do I need to override hash?
      • From: Alastair Houghton <email@hidden>
References: 
 >When do I need to override hash? (From: Gideon King <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>)
 >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: Clark Cox <email@hidden>)
 >Re: When do I need to override hash? (From: Alastair Houghton <email@hidden>)
 >Re: When do I need to override hash? (From: Seth Willits <email@hidden>)
 >Re: When do I need to override hash? (From: Quincey Morris <email@hidden>)
 >RE: When do I need to override hash? (From: Jeff Laing <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