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: Gideon King <email@hidden>
- Date: Thu, 20 Aug 2009 11:17:28 +1000
Excellent, thanks for that - in my case I only have up to about a
dozen objects in my array, so I'll just return 0 for the hash and let
it fall back to isEqual:. I see that some of the Omni classes do that
too...
In other cases where I make few changes but do lots of comparisons, I
might use the string hash idea and cache the return value in the
object, triggering an update whenever the relevant data changes. This
would be easy for me because the objects in question can archive
themselves to XML and I could use the XML string.
Gideon
On 20/08/2009, at 10:58 AM, Nathan Vander Wilt wrote:
On Aug 19, 2009, at 4:28 PM, Gideon King wrote:
So do I need to override hash too? If so, are there any
recommendations as to how to determine the hash easily?
Sorry, just came across this thread that has some more tips:
http://www.omnigroup.com/mailman/archive/macosx-dev/2003-December/049844.html
If you need better performance from your hash function than my
previous suggestion, you can just pick a somewhat unique property
and return its -hash. This works because, while equal object have
equal hashes, equal hashes don't guarantee equality.
-nvw
_______________________________________________
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