>From ><http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/hash>
"If two objects are equal (as determined by the isEqual: method), they must have the same hash value. This last point is particularly important if you define hash in a subclass and intend to put instances of that subclass into a collection." On Thu, Aug 20, 2009 at 1:30 PM, Bryan Henry<bryanhe...@mac.com> wrote: > Why do you say that? I haven't noticed any documented requirement that ties > the implementation details of -hash and -isEqual together. > > - Bryan > > Sent from my iPhone > > On Aug 20, 2009, at 4:27 PM, Clark Cox <clarkc...@gmail.com> wrote: > >> On Thu, Aug 20, 2009 at 12:33 PM, David Duncan<david.dun...@apple.com> >> wrote: >>> >>> On Aug 20, 2009, at 12:00 PM, Seth Willits wrote: >>> >>>> Returning 0 is certainly simpler :p >>> >>> >>> It is, but you can generally do better than just returning 0, usually by >>> just extracting some bits from 'self', ala >>> >>> -(NSUInteger)hash >>> { >>> uintptr_t hash = (uintptr_t)self; >>> return (hash >> 4); >>> } >>> >>> This satisfies the condition of hash (two equal objects will have the >>> same >>> hash code) >> >> No it doesn't. Writing the hash method like that basically prevents >> you from having an isEqual that does anything other than a pointer >> comparison. >> >> -- >> Clark S. Cox III >> clarkc...@gmail.com >> _______________________________________________ >> >> 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/bryanhenry%40mac.com >> >> This email sent to bryanhe...@mac.com > -- Clark S. Cox III clarkc...@gmail.com _______________________________________________ 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