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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to