SortedCollection reversed...

goran.hultgren at bluefish.se goran.hultgren at bluefish.se
Thu Oct 11 09:41:58 UTC 2001


Hmmm, doing some archeology here:

'abd' asSortedCollection reversed -->  a SortedCollection($d $b $a)

...as expected but:

'abd' asSortedCollection reversed reSort --> a SortedCollection($a $b
$d)

...ok, so reversed (obvious, if you check the implementation of
reversed) is just a temporary state for SortedCollections. Hmm, is that
logical/intentional/intuitive/good? (I checked in Dolphin and they have
changed "self species" to "OrderedCollection" so that you actually do not
get a SortedCollection back. They noted the trickiness in maintaining an
inverted sortBlock.)

'abd' asSortedCollection reversed add: $c; yourself --> a
SortedCollection($d $b $a $c)

...not sorted anymore in either direction! Actually, it tried to put $c
in the right place but fails since it is reversed.

Questions:

- First, why is there both #reverse and #reversed ? Both are called in
numerous places and one is just implemented by calling the other. If
#reverse was done "inplace" I could understand the difference in name
(as reverse sounds like an imperative), but it isn't.

- Ok, if we reimplement reverse/reversed for SortedCollections so that
it remembers that it is reversed, how should it be done?

- Sidequestion: If a class without subclasses implements #species as for
example CharacterSet does (returning the class CharacterSet), what is
the point in that? I mean, what is the difference from just inheriting
Object>>species? Well, if it isn't in anticipation of new subclasses of
course... :-)

Thoughts:

I experimented with wrapping the sortBlock in a reversing block - [:a :b
| block value: b value: a ] - but I couldn't really figure out how to
get it working without adding some state to SortedCollection in order
for the SortedCollection to know when it has been reversed so that it
could "unwrap" the sortblock again. A simpler approach is to just add
another sortmethod and a boolean flag telling when being reversed, but
that would mean another instvar. 

Anyway, just some ramblings... Set me straight! :-)

regards, Gšran




More information about the Squeak-dev mailing list