Re: NSString inaccurate Hash
Re: NSString inaccurate Hash
- Subject: Re: NSString inaccurate Hash
- From: Azza <email@hidden>
- Date: Mon, 5 Feb 2007 09:23:23 +1100
Thanks for the insight Chris. I think in the end I may use something more
like a base64 cause it'd be handy to be able to decode the hash too :P
Cheers
On 2/5/07, Chris Suter <email@hidden> wrote:
On 05/02/2007, at 8:13 AM, 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
I read this just the other day:
From http://www.mulle-kybernetik.com/artikel/Optimization/opti-7.html
--
NSString/CFString/NSURL
The hash is a convolution of the first and last eight bytes plus the
length of the string basically the byte values are shifted and added
to the string length.
--
I don't know if it's up to date, but if it is, that would explain it.
I'm sure you can find plenty of information about good string hash
functions by searching on Google.
- Chris
_______________________________________________
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