> On Nov 21, 2016, at 3:05 PM, Didier <didi...@gmail.com> wrote: > > I experimented with this a lot, and took everyone's advice, and this is the > fastest I got, even faster then Michael Gardner's answer. > > (deftype point5 [^long i ^long j] > Object > (equals [this that] (and (= (.i this) (.i ^point5 that)) > (= (.j this) (.j ^point5 that)))) > (hashCode [this] (+ (.i this) (* 4000 (.j this)))))
Java equals and hashCode are notoriously tricky to get right. Equals should handle any kind of “that” so you typically need to test instance? (basically, instanceOf in Java). Here are a couple of reference links: http://stackoverflow.com/questions/27581/what-issues-should-be-considered-when-overriding-equals-and-hashcode-in-java http://www.angelikalanger.com/Articles/JavaSolutions/SecretsOfEquals/Equals.html In this case, I suggest you try something like this: (equals [this that] (or (identical? this that) (and (instance? point5 that) (= (.i this) (.i ^point5 that)) (= (.j this) (.j ^point5 that))))) It might be a little slower but it should be safer. If you’re out for speed, you could also try unchecked-add, unchecked-multiply, unchecked-inc, and unchecked-dec where it's safe to ignore the chance of overflows. I mention these only because you’re trying to compete on benchmarks. Most of the time, you shouldn’t use them. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.