self == anObject
ifTrue: [^ true]. "they're identical; no further comparisons"
self species == anObject species
ifFalse: [^ false]. "different kinds of objects; no further comparisons"
"...compare self's state with anObject's state"
Why #species instead of #class? Because it supports polymorphism. If someone creates a ClassB subclass of your ClassA class, but only changes the implementation slightly and wants instances of both to be #= when they share the same state, they just have to implement ClassB>>#species to return ClassA. Now ClassA>>#= will work polymorphically, since both classes return the same #species (ClassA).
For #hash, since it's non-cryptographic, collisions (two unequal objects reporting the same #hash) are permitted, but undesirable. The main requirement is that __whenever two objects are #=, their #hashes are #= too__.
In fact, it's not uncommon to see #hash implementations only use a proper subset of the state that their corresponding #= method does to make #hash faster, but at the cost of more collisions. Compare ZnUrl #hash with #=.
Sent: Thursday, March 15, 2018 at 6:28 AM
From: "Trussardi Dario Romano via Glass" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Subject: [Glass] Hash implementations
i have a seaside application development with Pharo ( 4.0 ) and deployment with Gemstone GLASS.
Now i have some doubts about collisions regarding the hashing and the equality implementation.
Where for collision i intend the same hashing value from two different object.
For example i have a class where redefine the methods : = and the relative hash .