[BUG][FIX] WeakKeyDictionary>>keysAndValuesDo:

Martin Wirblat sql.mawi at t-link.de
Mon Jun 14 08:41:41 UTC 2004


Hi Richard,
very interesting, don't you consider it to be a bug that Squeak Sets 
change their hash values when their elements are changed? I just 
tested 

    | hash s |
    hash := ( s := #( 1 2 3 ) asSet ) hash.
    s add: 4.
    hash = s hash

in Dolphin, VSE and VW and it always evaluated to true. Only Squeak 
thinks it is false. For me it is totally nonintuitive not to be able 
to put any Set into another one. In fact every object that is 
explicitly designed to change its contents but which is not 
maintaining its hash value will give the programmer no intuitive clue 
that it can't be put in a Set. 

Regards
Martin

Richard A. O'Keefe wrote:
>
>Someone wrote:
>	> Seems to be a good idea to me. First I've thought of taking "self" 
>as 	> the placeholder, but then the Set couldn't contain itself...
>	
>A Set cannot contain itself anyway.  One of the fundamental things 
>about a Set is that you shouldn't put anything in it whose hash value 
>will change. Even if you add a Set to itself as the very last change, 
>the hash value *before* the change will be used to place it, but 
>afterwards its hash value will be different.
>
>    s := Set new.
>    s hash
>=>  2589
>    s add: s
>    s hash
>=> WHOOPS, INFINITE LOOP.
>
>In fact, a *lot* of Squeak collections assume they are trees, not 
>graphs. 
>    a := Array new: 1.
>    a at: 1 put: a.
>    a hashy
>=> WHOOPS, INFINITE LOOP.





More information about the Squeak-dev mailing list