Hello, If memory serves well, CRC-32 is quite fast. How large are the BLOBs you're trying to compare? If they're not too large, the following may work for you:
#include <zlib.h> @implementation NSData (CRC32) - (uint32_t)CRC32 { uLong crc = crc32(0L, NULL, 0); crc = crc32(crc, [self bytes], [self length]); return crc; } @end --Tito On Nov 29, 2013, at 12:36 PM, Kyle Sluder <k...@ksluder.com> wrote: >> On Nov 29, 2013, at 11:58 AM, Graham Cox <graham....@bigpond.com> wrote: > >> >> Another general question. >> >> Does anyone have a quick-and-dirty (but functional) way to hash NSData? I’m >> currently using SHA-1 but it’s quite slow. All I need is a way to determine >> whether one block of data is identical to another or not - but every bit >> counts. > > Just for the sake of the list, though I'm certain you're aware of this > yourself: you can't use a hash function to check for equality unless it is a > perfect hash function. You can use it to reduce the number of comparisons per > candidate, but you'll always wind up doing at least O(M+N) comparisons (where > M is the size of your input and N is the length of your hash output). > > Often, it's better to improve the data structure before trying a different > hash function. It's much easier to reason about how to improve a solution in > terms of algorithm analysis of your data structure rather than it is to > perform an empirical analysis of a specific hash function's > collision-to-speed tradeoffs. > > Long way of saying: what's the actual problem you're trying to solve? Maybe a > hash table is a poor fit. > > --Kyle Sluder > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please 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: > https://lists.apple.com/mailman/options/cocoa-dev/tciuro%40mac.com > > This email sent to tci...@mac.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com