Esteban,
it is defined that #hash and #= always have to be implemented accordingly. What you are expecting seems to me be more appropriate for object identity considerations as already mentioned correctly in this thread.
One of the clearest explanations concerning this topic I know is:
http://www.javaranch.com/journal/2002/10/equalhash.html

In fact, it would not lead to a wrong behaviour if #hash had been implemented as you expected, but to unnecessary compares when searching within a hashed collection (meaning: the implementation would sometimes consider two collections wrongly to be equal due to their identical hash code, but when comparing them with #=, recognize the difference and check the next one with the same hash code).
More important is the opposite relation: Two objects considered as equal when compared with #= always MUST produce the same hash code, otherwise the system would behave badly in an unpredictable way.
Richard

> On 09 Oct 2015, at 16:21, Gabriel Cotelli <g.cotelli@gmail.com> wrote:
>
> If the collection implements = using the objects it holds then you need to consider at least some of them in the hash calculation. I can't conceive a hash calculation for this case independent of the contents (well,�� just hardcode a number but this will lead to always collide if used as a key in a hashed collection).

it is not :)

>
> I'm with Levente here, I think the hash implementation is reasonable. And I wouldn't use a mutable object as key in a hashed collection.

no idea? I?m not using it, just arrive to that method random and I cannot understand it.
I still believe is wrong.

Esteban

>
> On Fri, Oct 9, 2015 at 11:07 AM, Esteban Lorenzano <estebanlm@gmail.com <mailto:estebanlm@gmail.com>> wrote:
> but that?s an error, I think.
> a collection has to have always same hash? no matter its size (because is not an array) and no matter his elements.
>
>
> > On 09 Oct 2015, at 15:21, Levente Uzonyi <leves@elte.hu <mailto:leves@elte.hu>> wrote:
> >
> > You simply don't modify _objects_ which are used as keys in hashed collections. Or if you do so, you'll have to deal with the consequences yourself.
> >
> > Levente
> >
> > On Fri, 9 Oct 2015, Esteban Lorenzano wrote:
> >
> >> Hi,
> >>
> >> Can anyone explain me how this is correct?
> >>
> >> Collection>>#hash
> >>�� �� �� "Answer an integer hash value for the receiver such that,
> >>�� �� �� �� -- the hash value of an unchanged object is constant over time, and
> >>�� �� �� �� -- two equal objects have equal hash values"
> >>
> >>�� �� �� | hash |
> >>
> >>�� �� �� hash := self species hash.
> >>�� �� �� self size <= 10 ifTrue:
> >>�� �� �� �� �� �� �� [self do: [:elem | hash := hash bitXor: elem hash]].
> >>�� �� �� ^hash bitXor: self size hash
> >>
> >>
> >> I mean? a hash that changes when I add elements to the collection? how can this work?
> >>
> >> Esteban
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20151009/a843583b/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Pharo-dev mailing list
Pharo-dev@lists.pharo.org
http://lists.pharo.org/mailman/listinfo/pharo-dev_lists.pharo.org


------------------------------

End of Pharo-dev Digest, Vol 30, Issue 48
*****************************************