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: Wim Lewis <email@hidden>
- Date: Mon, 11 Jan 2016 12:18:47 -0800
On Jan 11, 2016, at 10:18 AM, Dave <email@hidden> wrote:
> 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?
Does CFEqual() do what you need?
It depends a lot on what you mean by "has changed". If you have an immutable array containing a mutable object, do you want to detect that? If you have a CFFileDescriptorRef, do you care about the whole contents and metadata of the file, 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.)
Amusingly, -[NSString hash] used to depend only on the first four bytes and the length of the string. It was inefficient in use, especially if you were hashing a lot of strings that all started with "http". :)
_______________________________________________
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