Re: Implementing isEqual: and hash
Re: Implementing isEqual: and hash
- Subject: Re: Implementing isEqual: and hash
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sat, 23 Aug 2008 13:52:43 +0200
Le 23 août 08 à 13:41, Graham Cox a écrit :
I have a class for which equality can be defined as having the same
internal string value (which happens to be a UUID-turned-string). I
can easily implement isEqual: based on that but the docs say I also
need to implement -hash. Any pointers on what is a good way to do
that? Could I just safely defer to the -hash returned by the string
in question?
Yes, that the way to do it.
To understand what an hash is and how it is used, I suggest you read
the hash table article in wikipedia.
http://en.wikipedia.org/wiki/Hash_table
Hash tables are used in Cocoa in NSDictionary, NSSet, NSHashTable,
NSHashMap and maybe more. When you understand how it works, choosing
the implementation should be obvious.
_______________________________________________
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