On Aug 23, 2008, at 2:05 PM, Adam R. Maxwell wrote:

If I have

@interface Test : NSObject
{
  id ivar1;
  id ivar2;
}
@end

@implementation Test

- (BOOL)isEqual:(id)other
{
  if ([other isKindOfClass:[self class]] == NO) return NO;
return ([ivar1 isEqual:(Test *)other->ivar1] && [ivar2 isEqual: (Test *)other->ivar2]);
}

- (unsigned)hash { return [ivar1 hash]; }

@end

I believe it's sufficient to use [ivar1 hash], since the object is only equal if ivar1 is equal in both objects. I was just curious to know what you gain by using ([ivar1 hash] ^ [ivar2 hash]); is it possible to know in general if it reduces collisions? Presumably that depends on the hash table implementation as well.

--
Adam

Right, it depends on the hash table implementation, which we don't know. Theoretically, it seems likely to reduce collisions. This could only be confirmed by real-world performance tests, though.

-Jeff

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to