[BUG] Dictionary equality test

Andres Valloud sqrmax at prodigy.net
Sun Jun 9 06:49:48 UTC 2002


Hello.

> Dictionary>>
> = aDictionary
>     (aDictionary isKindOf: Dictionary) ifFalse: [^false].
>     self size = aDictionary size ifFalse: [^false].
>     self associationsDo: [:assoc|
>         (aDictionary at: assoc key ifAbsent: [^false]) =
>		assoc value ifFalse: [^false]].
>     ^true

I think Dictionaries are just collections whose contents are accessed
through arbitrary names --- as opposed to e.g. Arrays, whose contents
are accessed through positive integer names.

IMHO, given that associations are equal iif their keys are equal, a
dictionary is *not* a set of associations.

Therefore, I think Dictionary>>= should read:

= aDictionary

	self species = aDictionary species ifFalse: [^false].
	^self asBag = aDictionary asBag

I am assuming that Dictionary>>asBag is something like

asBag

	^self inject: Bag new into: [:x :y | x add: y; yourself]

Note that this definition of Dictionary>>= will discriminate between
dictionaries that have the same values with different amount of
occurrences (ie, it is stronger than self asSet = aDictionary asSet).

Just my 2 cents,
Andres.



More information about the Squeak-dev mailing list