[squeak-dev] The Trunk: Collections-ul.668.mcz
Nicolai Hess
nicolaihess at web.de
Tue Oct 13 08:41:08 UTC 2015
2015-10-13 3:37 GMT+02:00 Levente Uzonyi <leves at elte.hu>:
> Exactly. It can happen with other kind of dictionaries as well. And class
> checks would not enough:
>
> d1 := PluggableDictionary new.
> d2 := PluggableDictionary new equalBlock: #==.
> d1 at: 'test' copy put: 4.
> d2 at: 'test' put: 4.
> {d1 = d2.
> d2 = d1}
>
> So, performance goes down in some cases, but I guess we agree on #= has to
> be symmetric. We can speed up some cases if the dictionaries can tell if #=
> is guaranteed to be symmetric when they have the same class.
>
But #hash still uses species, that means, we can have a Dictionary and an
IdentityDictionary to be equal, but with different hash.
s := 'a'
ed := Dictionary with: s -> $a.
id := IdentityDictionary with: s -> $a.
{ ed = id. id = ed. ed hash = id hash } "-> #(true true false)"
>
> Levente
>
>
> On Mon, 12 Oct 2015, Eliot Miranda wrote:
>
> I'm guessing
>>
>> | ed id |
>> ed := Dictionary with: 'a' -> $a.
>> id := IdentityDictionary with: 'a' copy -> $a.
>> { ed = id. id = ed }
>>
>> _,,,^..^,,,_ (phone)
>>
>> On Oct 12, 2015, at 5:14 PM, Chris Muller <asqueaker at gmail.com> wrote:
>>
>> This extra check halves the speed of Dictionary>>= when they are
>> equal, for all cases which consider equivalence symmetrical. If a=b,
>> then it should be able to be assumed that b=a. What case is it not?
>>
>> On Mon, Oct 12, 2015 at 7:02 PM, <commits at source.squeak.org> wrote:
>> Levente Uzonyi uploaded a new version of Collections to project The
>> Trunk:
>> http://source.squeak.org/trunk/Collections-ul.668.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Collections-ul.668
>> Author: ul
>> Time: 13 October 2015, 1:07:48.216 am
>> UUID: 8abfa05a-70c6-4e38-bc00-7d665183106c
>> Ancestors: Collections-ul.667
>>
>> In Dictionary >> #=, make sure that the dictionaries agree on what
>> the common keys are. This way the behaviour of #= will be
>> symmetric when the two dictionaries implement key equality
>> differently.
>>
>> =============== Diff against Collections-ul.667 ===============
>>
>> Item was changed:
>> ----- Method: Dictionary>>= (in category 'comparing') -----
>> + = anObject
>> - = aDictionary
>> "Two dictionaries are equal if
>> (a) they are the same 'kind' of thing.
>> (b) they have the same set of keys.
>> (c) for each (common) key, they have the same value"
>>
>> + self == anObject ifTrue: [ ^true ].
>> + anObject isDictionary ifFalse: [ ^false ].
>> + self size = anObject size ifFalse: [ ^false ].
>> + self associationsDo: [ :association |
>> + (anObject at: association key ifAbsent: [ ^false ])
>> = association value
>> + ifFalse: [ ^false ] ].
>> + "The two dictionaries may have different ideas about equal
>> keys, so check both ways to avoid any inconsistency."
>> + anObject associationsDo: [ :association |
>> + (self at: association key ifAbsent: [ ^false ]) =
>> association value
>> + ifFalse: [ ^false ] ].
>> + ^true!
>> - self == aDictionary ifTrue: [ ^ true ].
>> - aDictionary isDictionary ifFalse: [^false].
>> - self size = aDictionary size ifFalse: [^false].
>> - self associationsDo: [:assoc|
>> - (aDictionary at: assoc key ifAbsent: [^false]) =
>> assoc value
>> - ifFalse: [^false]].
>> - ^true
>> -
>> - !
>>
>>
>>
>>
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20151013/b8dc6d0a/attachment.htm
More information about the Squeak-dev
mailing list
|