<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">&lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt;</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: &#39;test&#39; copy put: 4.<br>
d2 at: &#39;test&#39; 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 := &#39;a&#39;<br>ed := Dictionary with: s -&gt; $a.<br>id := IdentityDictionary with: s -&gt; $a.<br>{ ed = id. id = ed. ed hash = id hash } &quot;-&gt;  #(true true false)&quot;<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&#39;m guessing<br>
<br>
| ed id |<br>
ed := Dictionary with: &#39;a&#39; -&gt; $a.<br>
id := IdentityDictionary with: &#39;a&#39; copy -&gt; $a.<br>
{ ed = id. id = ed }<br>
<br>
_,,,^..^,,,_ (phone)<br>
<br>
On Oct 12, 2015, at 5:14 PM, Chris Muller &lt;<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>&gt; wrote:<br>
<br>
      This extra check halves the speed of Dictionary&gt;&gt;= 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, &lt;<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>&gt; 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 &gt;&gt; #=, 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&gt;&gt;= (in category &#39;comparing&#39;) -----<br>
      + = anObject<br>
      - = aDictionary<br>
              &quot;Two dictionaries are equal if<br>
               (a) they are the same &#39;kind&#39; of thing.<br>
               (b) they have the same set of keys.<br>
               (c) for each (common) key, they have the same value&quot;<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>
      +       &quot;The two dictionaries may have different ideas about equal keys, so check both ways to avoid any inconsistency.&quot;<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>