Is there an Ordered Dictionary?
Andreas Raab
andreas.raab at gmx.de
Thu Jan 9 22:08:36 UTC 2003
> Is there a dictionary that holds its associations in the same
> order you add them in?
No.
> BTW, on the subject of dictionaries, are you supposed to use
> associationsDo to iterate over all key - value pairs?
Well, it largely depends on how you view sequenceable collections. I
commonly think about them as "keyed by index" (which is consistent with
#at:[put:]) but #associationsDo: will enumerate over their values (which
is "correct" for the case that the collection contains associations but
for all others it isn't).
If you use #keysAndValuesDo: for enumeration the system will give you
the "integer keys" for sequenceable collections, so in most cases I
prefer this protocol (and yes, I think the inconsistency between
#keysAndValuesDo: and #associationsDo: is quite annoying).
Incidentally, whether any of the two really make sense for the case of
an "OrderedDictionary" is yet another matter ;-) In this case you migh
(at least at times) need a "third interpretation" since whether you mean
the "index key" or the "name key" is not obvious in any case.
Cheers,
- Andreas
More information about the Squeak-dev
mailing list
|