• 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: 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


References: 
 >Re: NSString inaccurate Hash (From: Gregory Weston <email@hidden>)

  • Prev by Date: [Solved] AppleScript support - 10.3/10.4
  • Next by Date: Re: No double click event available to an NSView?
  • Previous by thread: Re: NSString inaccurate Hash
  • Next by thread: AppleScript support - 10.3/10.4
  • Index(es):
    • Date
    • Thread