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 (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to