Hello, Item "disappears" in Bag after contents of the item changes. Item is container with equality and hash is overridden. Is this a Bug? bag:= Bag with: (val := AKContainer value: 'a').
val value: 'b'. bag valuesAndCounts includesKey: val. "false in Trunk," set:= Set with: (val := AKContainer value: 'a'). val value: 'b'.
set includes: val. "true" dictionary:= Dictionary newFromPairs: {val := AKContainer value: 'a'. 1}. val value: 'b'. dictionary includesKey: val. "true"
All tests fails in Squeak 3.6 and in Dolphin ST. In Trunk fails only the Bag. If this is not a bug, how can I escape this Anomaly of disappearing element [1] Thank you
Vaidotas _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners AKContainer.st (1K) Download Attachment |
On Fri, 30 Jul 2010, Vaidotas Didžbalis wrote:
> Hello, > > Item "disappears" in Bag after contents of the item changes. Item is > container with equality and hash is overridden. Is this a Bug? No it's not. Since the return value of AKContainer >> #hash and AKContainer >> #= depend on 'value', they will change if you change the 'value'. Hashed collections assume that the hash and equality of the contained objects don't change. > > bag:= Bag with: (val := AKContainer value: 'a'). > val value: 'b'. > bag valuesAndCounts includesKey: val. "false in Trunk," > > set:= Set with: (val := AKContainer value: 'a'). > val value: 'b'. > set includes: val. "true" That happens, because String >> #hash doesn't work well with 5: ($a to: $z) collect: [ :each | each asString hash \\ 5 ] as: Set "===> a Set(4)" Most of the time it's expected to return false. > > dictionary:= Dictionary newFromPairs: {val := AKContainer value: 'a'. 1}. > val value: 'b'. > dictionary includesKey: val. "true" Same as above. > > All tests fails in Squeak 3.6 and in Dolphin ST. In Trunk fails only the > Bag. So it's just bad luck that these don't fail in Squeak trunk. Levente > > If this is not a bug, how can I escape this Anomaly of disappearing element > [1] > Thank you > Vaidotas > > [1] > http://books.google.lt/books?id=W8_Une9cbbgC&pg=PA76&lpg=PA76&dq=anomaly+of+the+disappearing+element+smalltalk&source=bl&ots=oOsY_y8pBc&sig=EDgG-Xblp7q1ib19_YunrgBAweY&hl=en&ei=-6NSTJ-4EtGKOOW__J4O&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBAQ6AEwAA#v=onepage&q=anomaly%20of%20the%20disappearing%20element%20smalltalk&f=false > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
So, one needs to remember and rehash some collections manually after
mutable object is changed? Brrr. I will forget. 2010/7/30 Levente Uzonyi <[hidden email]>: > On Fri, 30 Jul 2010, Vaidotas Didžbalis wrote: > >> Hello, >> >> Item "disappears" in Bag after contents of the item changes. Item is >> container with equality and hash is overridden. Is this a Bug? > > No it's not. Since the return value of AKContainer >> #hash and AKContainer >>> #= depend on 'value', they will change if you change the 'value'. Hashed > collections assume that the hash and equality of the contained objects don't > change. > >> >> bag:= Bag with: (val := AKContainer value: 'a'). >> val value: 'b'. >> bag valuesAndCounts includesKey: val. "false in Trunk," >> >> set:= Set with: (val := AKContainer value: 'a'). >> val value: 'b'. >> set includes: val. "true" > > That happens, because String >> #hash doesn't work well with 5: > ($a to: $z) collect: [ :each | each asString hash \\ 5 ] as: Set "===> a > Set(4)" > Most of the time it's expected to return false. > >> >> dictionary:= Dictionary newFromPairs: {val := AKContainer value: 'a'. 1}. >> val value: 'b'. >> dictionary includesKey: val. "true" > > Same as above. > >> >> All tests fails in Squeak 3.6 and in Dolphin ST. In Trunk fails only the >> Bag. > > So it's just bad luck that these don't fail in Squeak trunk. > > > Levente > >> >> If this is not a bug, how can I escape this Anomaly of disappearing >> element >> [1] >> Thank you >> Vaidotas >> >> [1] >> >> http://books.google.lt/books?id=W8_Une9cbbgC&pg=PA76&lpg=PA76&dq=anomaly+of+the+disappearing+element+smalltalk&source=bl&ots=oOsY_y8pBc&sig=EDgG-Xblp7q1ib19_YunrgBAweY&hl=en&ei=-6NSTJ-4EtGKOOW__J4O&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBAQ6AEwAA#v=onepage&q=anomaly%20of%20the%20disappearing%20element%20smalltalk&f=false > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Vaidotas" == Vaidotas Didžbalis <[hidden email]> writes:
Vaidotas> So, one needs to remember and rehash some collections manually after Vaidotas> mutable object is changed? Brrr. I will forget. How else would it be? If its identity-for-equality is based on its contents, how do you expect the collection to reidentify it? Note that IdentityDictionary doesn't suffer from this. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |