On Wed, 23 Dec 2009, Nicolas Cellier wrote:
2009/12/23 Levente Uzonyi <leves@elte.hu>:
On Wed, 23 Dec 2009, Stéphane Ducasse wrote:
What bugs me is that #sortBy: does not what it says. I would expect that
 aCollection sortBy: [ :each | each name ]
does the same as
 aCollection sort: [ :a :b | a name <= b name ]
if you want that, I can provide a fast implementation of #sortBy:
Not all collections are sortable and #sort: is sorting in-place, so it's hardly doable.
But it would be nice to have sort: and sortBlock: polymorph. Because right now we cannot have OrderedCollection and Array or SortedCollection interchanged.
SortedCollection should be used as rarely as possible. In the past it was used for sorting which is a misuse of this data structure (I wonder why such data strucure exists at all, it's almost never useful).
The only case should be to keep collection automatically sorted when its contents further evolves...
Indeed.
Of course, using repeated #add: is inefficient (#addAll: has a rule for sorting once or at every #add:).
That's true, but #addAll:'s rule is not generally useful. For example: | s | s := (1 to: 300000) asSortedCollection. [ s addAll: (1 to: 100000) ] timeToRun ===> 24698 | s | s := (1 to: 300000) asSortedCollection. [ s addAll: (1 to: 100001) ] timeToRun ===> 1124 (+1 element makes a big difference) And in squeak: | s | s := (1 to: 300000) asOrderedCollection. [ s addAll: (1 to: 100000); sort ] timeToRun ===> 763 (mergesort beats quicksort) So the only use-case where SortedCollection is useful (IMO) is when you - have to keep the collection sorted and - you rarely some elements to it Getting rid of other uses is hard because #asSortedCollection always returns a copy, while most #as* selectors don't. Levente
If you pick the changes from squeak trunk, Array and OrderedCollection (and SortedCollection) will understand #sort and #sort: and will have the same semantics: sort in place (by a stable sorting algorithm).
Don't open a new issue. There is http://code.google.com/p/pharo/issues/detail?id=1214 http://code.google.com/p/pharo/issues/detail?id=1346
Nicolas
Levente
Stef _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project