Sorting oddity - feature or ??
Jon Hylands
jon at huv.com
Wed May 1 16:49:25 UTC 2002
At Wednesday, 1 May 2002, you wrote:
>No, I don't think it is known and accepted.
>And #addAll: is implemented in SortedCollection
>
>addAll: aCollection
> aCollection size > (self size // 3)
> ifTrue:
> [aCollection do: [:each | self addLast: each].
> self reSort]
> ifFalse: [aCollection do: [:each | self add: each]].
> ^ aCollection
When you send asSortedCollection to an unsorted collection, the ifTrue
part is what is used -- it adds all the elements, and then does an
in-place sort. I haven't checked Squeak, but I assume it uses some
variation of Quicksort. This (a large collection equal values) is
probably just a worst-case scenario for whatever sorting algorithm
is used.
Later,
Jon
--------------------------------------------------------------
Jon Hylands Jon at huv.com http://www.huv.com/jon
Project: Micro Seeker (Micro Autonomous Underwater Vehicle)
http://www.huv.com
More information about the Squeak-dev
mailing list
|