logo       

Re: reimplementing #= and #hash: msg#00121

lang.smalltalk.squeak.beginners

Subject: Re: reimplementing #= and #hash


Hi Ching,

#hash should be reimplemented to make sure that objects considered to be equal will end up in the same hash bucket.

The usual trick is to take a bitXor of the hashes of the instance variables:

PoolQueue>>hash
^ member hash bitXor: processor hash

Hope that helps.
Oscar

On Sep 23, 2007, at 9:52, Ching de la Serna wrote:

Hi List,

I have a Class PoolQueue which has instvars 'member' and 'processor'. I find that an instance of PoolQueue when placed in an OrderedCollection can no longer be considered equal. I suppose I have to reimplement #= and #hash to allow PoolQueue instances to be compared.

My problem: how do I implement #hash? Or stated another way, what does #hash accomplish?

Thanks in advance.

Ching.
_______________________________________________
Beginners mailing list
Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx
http://lists.squeakfoundation.org/mailman/listinfo/beginners


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise