The identityHash should stay the same for any number of changes to the array..
| c1 c2 |
c1 := { #a . #b } asOrderedCollection.
c2 := { #a . #b } asOrderedCollection.
{
c1 hash.
c1 identityHash.
c2 hash.
c2 identityHash .
(c2 add: #c; yourself) identityHash.
} "inspect"
Best regards,
Henrik
-----Original Message-----
From: Pharo-dev [mailto:[email protected]] On Behalf Of Esteban
Lorenzano
Sent: Friday, October 9, 2015 4:08 PM
To: Pharo Development List <[email protected]>
Subject: Re: [Pharo-dev] hash and Collections
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 <[email protected]> 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