Re: Fast hash of NSData?
Re: Fast hash of NSData?
- Subject: Re: Fast hash of NSData?
- From: Roland King <email@hidden>
- Date: Mon, 02 Dec 2013 22:43:19 +0800
It helps to read the original post
"Does anyone have a quick-and-dirty (but functional) way to hash NSData? I’m currently using SHA-1 but it’s quite slow."
If SHA-1 was slow, SHA-512 ain't gonna help.
I keep not seeing the problem here .. you have two NSData's, you want to know if they are the same, at the time you store them you store the data and some fast-but-not-necessarily-very-good hash. So 'are they the same' becomes
is the underlying data the the same length? - no - not the same
do they have the same rapid hash? - no - not the same
actually compare the data byte by byte if the length and hash are the same to work out if they are the same. rare case.
You always get the right answer and even a fairly cruddy hash collides rarely enough to make a full data test unlikely.
reductio ad absurdum leads to not even bothering to hash them at all, comparing the length and if it's the same, just comparing the data. Reductio to even more absurdum says if two chunks of data are the same length, just store the both of 'em.
On 2 Dec, 2013, at 10:25 pm, ChanMaxthon <email@hidden> wrote:
> What is wrong with a good ol' SHA-512?
>
> Sent from my iPhone
>
>> On 2013年12月2日, at 21:50, "Gerriet M. Denkmann" <email@hidden> wrote:
>>
>> Assuming that a typical image has 243.3 k Bytes, or 1 993 221 bits. And that a hash has 64 bits.
>>
>> Then there are 2^1 993 221 different images, and 2^64 hash values.
>> One hash value is thus shared on average by 2^1 993 157 images. = (2^10)^199 315.7 = 10^600 000
>>
>> So it does not look so very unlikely that two different images might share a hash value.
>>
>> Or did I make some mistake?
>>
>> Gerriet.
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden