<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-10-13 3:37 GMT+02:00 Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Exactly. It can happen with other kind of dictionaries as well. And class checks would not enough:<br>
<br>
d1 := PluggableDictionary new.<br>
d2 := PluggableDictionary new equalBlock: #==.<br>
d1 at: 'test' copy put: 4.<br>
d2 at: 'test' put: 4.<br>
{d1 = d2.<br>
d2 = d1}<br>
<br>
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.<span class=""><font color="#888888"><br></font></span></blockquote><div><br></div><div>But #hash still uses species, that means, we can have a Dictionary and an IdentityDictionary to be equal, but with different hash.<br><br>s := 'a'<br>ed := Dictionary with: s -> $a.<br>id := IdentityDictionary with: s -> $a.<br>{ ed = id. id = ed. ed hash = id hash } "-> #(true true false)"<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><font color="#888888">
<br>
Levente</font></span><div class=""><div class="h5"><br>
<br>
On Mon, 12 Oct 2015, Eliot Miranda wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I'm guessing<br>
<br>
| ed id |<br>
ed := Dictionary with: 'a' -> $a.<br>
id := IdentityDictionary with: 'a' copy -> $a.<br>
{ ed = id. id = ed }<br>
<br>
_,,,^..^,,,_ (phone)<br>
<br>
On Oct 12, 2015, at 5:14 PM, Chris Muller <<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>> wrote:<br>
<br>
This extra check halves the speed of Dictionary>>= when they are equal, for all cases which consider equivalence symmetrical. If a=b,<br>
then it should be able to be assumed that b=a. What case is it not?<br>
<br>
On Mon, Oct 12, 2015 at 7:02 PM, <<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>> wrote:<br>
Levente Uzonyi uploaded a new version of Collections to project The Trunk:<br>
<a href="http://source.squeak.org/trunk/Collections-ul.668.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/trunk/Collections-ul.668.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Collections-ul.668<br>
Author: ul<br>
Time: 13 October 2015, 1:07:48.216 am<br>
UUID: 8abfa05a-70c6-4e38-bc00-7d665183106c<br>
Ancestors: Collections-ul.667<br>
<br>
In Dictionary >> #=, make sure that the dictionaries agree on what the common keys are. This way the behaviour of #= will be<br>
symmetric when the two dictionaries implement key equality differently.<br>
<br>
=============== Diff against Collections-ul.667 ===============<br>
<br>
Item was changed:<br>
----- Method: Dictionary>>= (in category 'comparing') -----<br>
+ = anObject<br>
- = aDictionary<br>
"Two dictionaries are equal if<br>
(a) they are the same 'kind' of thing.<br>
(b) they have the same set of keys.<br>
(c) for each (common) key, they have the same value"<br>
<br>
+ self == anObject ifTrue: [ ^true ].<br>
+ anObject isDictionary ifFalse: [ ^false ].<br>
+ self size = anObject size ifFalse: [ ^false ].<br>
+ self associationsDo: [ :association |<br>
+ (anObject at: association key ifAbsent: [ ^false ]) = association value<br>
+ ifFalse: [ ^false ] ].<br>
+ "The two dictionaries may have different ideas about equal keys, so check both ways to avoid any inconsistency."<br>
+ anObject associationsDo: [ :association |<br>
+ (self at: association key ifAbsent: [ ^false ]) = association value<br>
+ ifFalse: [ ^false ] ].<br>
+ ^true!<br>
- self == aDictionary ifTrue: [ ^ true ].<br>
- aDictionary isDictionary ifFalse: [^false].<br>
- self size = aDictionary size ifFalse: [^false].<br>
- self associationsDo: [:assoc|<br>
- (aDictionary at: assoc key ifAbsent: [^false]) = assoc value<br>
- ifFalse: [^false]].<br>
- ^true<br>
-<br>
- !<br>
<br>
<br>
<br>
<br>
<br>
</blockquote>
</div></div><br><br>
<br></blockquote></div><br></div></div>