Re: [Pharo-dev] hash and Collections. A solution for some.

2015-10-11 Thread Ralph Boland
I haven't followed this thread closely so I apologize in advance if I am somewhat off topic but I think what I have to say may be of interest to some of you. I think the current method of determining a hash value for a collection is fine in the general case and if it is inadequate for your particu

Re: [Pharo-dev] hash and Collections

2015-10-11 Thread monty
The issue: https://pharo.fogbugz.com/f/cases/16760/Dictionary-breaks-when-comparing-identity-and-non-identity-dictionaries > Sent: Sunday, October 11, 2015 at 7:23 AM > From: monty > To: pharo-dev@lists.pharo.org > Subject: Re: [Pharo-dev] hash and Collections > > Resending be

Re: [Pharo-dev] hash and Collections

2015-10-11 Thread monty
Resending because the last was HTML'd: Never use #newFrom: with associations from another dictonary if you reuse the first after.   The bug is actually deeper than you know: dic1 := Dictionary newFrom:{'test' -> 4}. dic2 := IdentityDictionary newFrom: {'test' copy -> 4}. dic1 = dic2. dic2 = dic1.

Re: [Pharo-dev] hash and Collections

2015-10-11 Thread monty
 "Henrik Johansen" To: "Pharo Development List" Subject: Re: [Pharo-dev] hash and Collections   On 09 Oct 2015, at 4:33 , Esteban Lorenzano <esteba...@gmail.com> wrote:     On 09 Oct 2015, at 16:21, Gabriel Cotelli <g.cote...@gmail.com> wrote:   If the colle

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Eliot Miranda
> On Oct 9, 2015, at 7:51 AM, Henrik Johansen > wrote: > > >>> On 09 Oct 2015, at 4:33 , Esteban Lorenzano wrote: >>> >>> >>> On 09 Oct 2015, at 16:21, Gabriel Cotelli wrote: >>> >>> If the collection implements = using the objects it holds then you need to >>> consider at least some of

Re: [Pharo-dev] hash and collections

2015-10-09 Thread Richard Uttner
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.j

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Alexandre Bergel
Hi Esteban, I understand your surprise, but it has to be like that. Two objects that are equals have to have the same hash value. This is part of the contract. And to comply with this rule with collections, the hash value has to reflect the content of the collection. Java has the same behavio

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Henrik Johansen
> On 09 Oct 2015, at 4:33 , Esteban Lorenzano wrote: > > >> On 09 Oct 2015, at 16:21, Gabriel Cotelli > > 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 conc

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Esteban Lorenzano
> On 09 Oct 2015, at 16:21, Gabriel Cotelli 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

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Gabriel Cotelli
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

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Henrik Nergaard
) identityHash. } "inspect" Best regards, Henrik -Original Message- From: Pharo-dev [mailto:pharo-dev-boun...@lists.pharo.org] On Behalf Of Esteban Lorenzano Sent: Friday, October 9, 2015 4:08 PM To: Pharo Development List Subject: Re: [Pharo-dev] hash and Collections but that’s an erro

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Esteban Lorenzano
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 wrote: > > You simply don't modify _objects_ which are used as keys in hashed > collections. Or if you

Re: [Pharo-dev] hash and Collections

2015-10-09 Thread Levente Uzonyi
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 inte

[Pharo-dev] hash and Collections

2015-10-09 Thread Esteban Lorenzano
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