Re: When do I need to override hash?
Re: When do I need to override hash?
- Subject: Re: When do I need to override hash?
- From: Clark Cox <email@hidden>
- Date: Thu, 20 Aug 2009 14:16:14 -0700
On Thu, Aug 20, 2009 at 2:14 PM, Kyle Sluder<email@hidden> wrote:
> On Thu, Aug 20, 2009 at 2:01 PM, Clark Cox<email@hidden> wrote:
>> Yes, and two different objects will have different pointer values. If
>> the hash is based on the pointer values, then two different objects
>> cannot have the same hash, regardless of whether or not they are
>> equal. Hence, that implementation of hash is broken for any object
>> that does anything other than a pointer comparison in -isEqual:.
>
> I thought we were talking about -hash just returning zero?
>
> --Kyle Sluder
>
No, we were talking about:
> 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);
> }
--
Clark S. Cox III
email@hidden
_______________________________________________
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