Re: Using CFHash to tell if a CFTypeRef has changed?
Re: Using CFHash to tell if a CFTypeRef has changed?
- Subject: Re: Using CFHash to tell if a CFTypeRef has changed?
- From: Dave <email@hidden>
- Date: Mon, 11 Jan 2016 18:18:33 +0000
Hi,
It’s actually an NSInteger so it’s 64 bits isn’t it? But I take your point, the hash isn’t going to change.
Any one have any other techniques for telling if a CFTypeRef has changed?
All the Best
Dave
> On 11 Jan 2016, at 18:08, Jens Alfke <email@hidden> wrote:
>
>
>> On Jan 11, 2016, at 9:57 AM, Jens Alfke <email@hidden <mailto:email@hidden>> wrote:
>>
>> No. If the object has changed, its hash isn’t guaranteed to change; there exist hash collisions where two different values have the same hash. (This is inevitable since there are only 2^32 hash values, but a nearly infinite number of different strings, arrays, etc.)
>
> FYI, since hash functions can be tricky, a useful technique I use to reason about them is to imagine a deliberately stupid hash function. For instance, imagine that the hash function for strings simply returns the first 4 bytes of the string. (Yes, this meets the criteria for a correct hash function, it’s just going to be inefficient in use.) If you used the ‘compare the old/new hashes’ trick, you would only detect changes to the string that altered the first four characters. That’s obviously not going to work.
>
> —Jens
_______________________________________________
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