• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString inaccurate Hash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSString inaccurate Hash (From: d2kagw <email@hidden>)

  • Prev by Date: Finding Source of Apple Event
  • Next by Date: Re: No double click event available to an NSView?
  • Previous by thread: Re: NSString inaccurate Hash
  • Next by thread: Re: NSString inaccurate Hash
  • Index(es):
    • Date
    • Thread