I redefine the '=:' and 'hash' methods of the elements contained in an ordered collection. My aim is to check if anOrderedCollection contains any duplicate object. So I try the following code: (anOrderedCollection size ~~ anOrderedCollection asSet size)
I would be grateful if you might suggest another solution without using the redefinition of the twin methods.
I think that identity related issues is one of the most complex in OO Design.
I'll be interested in documents discussing these issues if any.
Thanks, Houssam ____ "Le paradis touche les pieds des mères..."
-----Message d'origine----- De : squeak-dev-bounces@lists.squeakfoundation.org [mailto:squeak-dev- bounces@lists.squeakfoundation.org] De la part de stéphane ducasse Envoyé : vendredi 1 juillet 2005 12:27 À : The general-purpose Squeak developers list Objet : Re: hash method
Generally
I use
iv hash bitXor: iv2 hash
Following Kent beck best practices
But now I learned that I want to avoid as much as possible to redefine = and hash and if this is just to sorted objects I used SortedCollection sortBlock: [:a :b| a iv > b iv] for example.
I think that identity related issues is one of the most complex in OO Design.
Stef
Le 1 juil. 05 à 11:04, Houssam Fakih a écrit :
Hi,
When I redefine the = operation for a class I should redefine its hash method.
My question is about the definition of the hash method. I read that the method must return a SmallInteger whose value is related to the receiver. I would like to know if there is a general pattern adopted in Squeak for that. I get a look in the Squeak classes but it doesnt help.
Thanks,
Houssam
"Le paradis touche les pieds des mères..."