• 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: Alastair Houghton <email@hidden>
  • Date: Fri, 21 Aug 2009 10:07:18 +0100

On 21 Aug 2009, at 06:48, Quincey Morris wrote:

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

"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.

You're conflating keys and values here.

NSDictionary *does* use hash values to determine the object's position in the collection for its keys. It does not do so for its values.

Likewise with NSSet (which I think is best thought of as only having keys).

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

Of course not :-) It uses the array index.

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.

We do, because we have the source code (most of it, anyway). It's in the CF project in the Darwin sources.


(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.)

Well, leaving aside the fact that we have the code, it isn't really conceivable that NSArray would work this way (since it has to maintain an ordering, and you can't really do that with a hash table); in fact, for very large collections I think NSArray will use a 2-3 tree representation internally. In any case I can't see why it would ever depend on -hash.


It doesn't make much sense in NSDictionary's case either, since the operation NSDictionary is optimised for is looking up a value given a key. How exactly would the *value*'s -hash help when doing that? I can't think how it could ever be useful.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

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: 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>)
 >Re: When do I need to override hash? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: When do I need to override hash?
  • Next by Date: Re: When to 'release' in Cocoa management?
  • 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