|
From: | Richard Frith-Macdonald |
Subject: | Re: isEqual: and hash in NSDate |
Date: | Fri, 22 Jul 2005 17:44:14 +0100 |
On 2005-07-22 15:57:03 +0100 Adrian Robert <address@hidden> wrote:
This really seems like a hack (not that it's any worse than the current state :). Couldn't the implementations of -hash and -isEqual be aligned without this loss of information? E.g. something like [warning, sloppy first-attempt code here]:-isEqual:other return abs(selfVal - other->selfVal) < epsilon; -hash return selfVal / epsilon; (or maybe (selfVal + epsilon/2.0) / epsilon)
No ... each NSDate has to have its own independent hash ... but (following the OpenStep spec) dates are equal if they are within a second of each other.
That means that with dates d1, d2, d3 which have offsets from the reference date of 0.0, 0.7 and 1.4 seconds, d1 is eqal to d2 and d2 is equal to d3 but d1 is not equal to d3 ... a rather counterintuitive behavior!
So ... as long as we stick to the OpenStep spec, we can't use dates as dictionary keys.
I think we should move with MacOS-X here rather than sticking to OpenStep.
[Prev in Thread] | Current Thread | [Next in Thread] |