Comment #3 on issue 5858 by
[hidden email]: DateAndTime >>#hash
http://code.google.com/p/pharo/issues/detail?id=5858Nicholas Ceiler pointed out that my hash would fail this test on Squeak:
| date1 date2 |
date1 := DateAndTime new ticks: (DateAndTime unixEpoch + 1 hours)
ticks offset: 0 hours.
date2 := DateAndTime new ticks: (DateAndTime unixEpoch - 2 hours)
ticks offset: -3 hours.
self assert: (date1 = date2) ==> [date1 hash = date2 hash]
which it does fail on Squeak but it passes on Pharo.
He proposes using this instead:
DateAndTime>>#hash
| totalSeconds |
totalSeconds := seconds - offset asSeconds.
^ ((totalSeconds // 86400 + jdn) hashMultiply bitXor: totalSeconds \\
86400) bitXor: nanos
Which works better than what I proposed from a collision point of view
(0.01% or 1 per 10,000) and is a bit slower than my proposal. Its still
100x faster than the original I proposed to replace. So 11,000,000/sec
rather than 110,000/sec.
Attachments:
DateAndTime-hash-2.st 326 bytes
_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker