Re: NSString inaccurate Hash
Re: NSString inaccurate Hash
- Subject: Re: NSString inaccurate Hash
- From: Andrew Farmer <email@hidden>
- Date: Sun, 4 Feb 2007 16:47:14 -0800
On 04 Feb 07, at 15:14, Gregory Weston wrote:
d2kagw wrote:
I knew NSString hash wasn't exactly unique, but I would have expected
a little more than this :P
are there any other good hash methods/classes avaliable that I can
use to generate hashes ( my app creates cache files of accessed data
and the hash was meant to be the unique filename for the cache )
If you know they're not guaranteed to be unique then hoping they're
"unique enough" to be usable as sibling file names isn't really a
sensible plan IMO.
If you want unique, I'd use a UUID.
Or use a munged version of the original name. Replacing all slashes
with backslashes, and all backslashes with double backslashes (to
make the process reversible), is probably a reasonable enough
technique, as long as you can be guaranteed that you're running on a
volume that supports long filenames, and the input paths are
reasonably short.
Hashes are never guaranteed to be unique. (That's provably
impossible, anyway.) The only guarantee that a hash function makes is
that it'll always return the same value for the same object. Good
hash functions will usually return different values for different
objects; it just looks like you've found a particular case where the
NSString hash function falls down a bit.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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