[squeak-dev] The Trunk: Collections-ul.668.mcz
Levente Uzonyi
leves at elte.hu
Tue Oct 13 01:37:17 UTC 2015
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.
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
> -
> - !
>
>
>
>
>
>
More information about the Squeak-dev
mailing list
|