Re: NSString inaccurate Hash
Re: NSString inaccurate Hash
- Subject: Re: NSString inaccurate Hash
- From: Ali Ozer <email@hidden>
- Date: Sun, 4 Feb 2007 17:26:13 -0800
In Tiger default CF/NSString hash considers the first 8 and last 16
characters, so your strings are falling victim to that. You can use
your own hash function here, which NSMapTable and NSHashTable let you
do.
Note that no hash will guarantee uniqueness for arbitrary data sets;
however, if you know your data set ahead of time, you can try to find
a perfect hash for it. Doesn't sound like that is the case here.
We're considering changes to hash more of the characters in Leopard.
Ali
On Feb 4, 2007, at 1:13 , d2kagw wrote:
Hi all,
I'm having an issue with some NSString Hashes...
Consider this Log entry:
NSLog ( @"%u - %u", [[NSString stringWithString:@"/Users/Azza/Music/
Various Artists - Top Hits/track.01.artist.02.03.mp4"] hash],
[[NSString stringWithString:@"/Users/Azza/Music/Various Artists -
Top Hits/track.02.artist.02.03.mp4"] hash] );
it should log the hash of two strings: "/Users/Azza/Music/Various
Artists - Top Hits/track.01.artist.02.03.mp4" and "/Users/Azza/
Music/Various Artists - Top Hits/track.02.artist.02.03.mp4"
the difference between them being "track.01" vs. "track.02"
If I execute this code I get the result "2040446062 - 2040446062"
meaning the two hashes are identical!?
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 )
cheers!!!
- Az
_______________________________________________
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