Re: Hash Values in Custom Classes
Re: Hash Values in Custom Classes
- Subject: Re: Hash Values in Custom Classes
- From: Peter Lübke <email@hidden>
- Date: Sun, 27 Mar 2011 12:59:52 +0200
Am 26.03.2011 um 14:57 schrieb Mike Abdullah:
To be more detailed: my custom class and its subclasses are
wrapper classes containing file informations. They are based on
FSRef rather than using paths - I do a lot of lengthy iterations
so paths are much too fragile. I also heavily use NSSet to store
instances, and I wanted -isEqual: to be as fast as possible. So I
thought I could just return a unique hash value for each custom
class and return (FSCompareFSRefs (&ownRef, &otherRef) == noErr)
for -isEqual:, thus avoiding the need to *first* compare the
objects' classes.
This is pretty much what NSSet will be doing for you. It uses -hash
to narrow down possible matches, before calling -isEqual: only on
those that share a hash.
This was about the only point that was evident to me :-)
You should find this plenty enough fast enough if your hash values
actually are unique.
This was the reason for my silly question. I know my app will only
add instances of appropriate classes to the sets, but nevertheless I
want to do it the right way.
If not, about the only optimization from there is a NSHashTable or
CFSet setup to test equality on -hash.
Could you point me to a documentation that could help me understand
NSHashTable?
Thanks again, Mike.
Cheers,
Peter
_______________________________________________
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