[Newbies] reimplementing #= and #hash

Ching de la Serna ching.dls at gmail.com
Mon Sep 24 00:38:20 UTC 2007


Hi Oscar,

Thanks for the help. I tried bitAnd: and it seems to work. I will try
bitXor: too. Thanks

Ching

On 9/23/07, Oscar Nierstrasz <oscar.nierstrasz at gmail.com> wrote:
>
>
> 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 at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20070924/f4912113/attachment.htm


More information about the Beginners mailing list