Sorting oddity - feature or ??

Ned Konz ned at bike-nomad.com
Wed May 1 17:25:15 UTC 2002


On Wednesday 01 May 2002 09:59 am, David A. Smith wrote:
> Well, actually...
>
> The default for #asSortedCollection is <=.
> If instead, one were to replace this with:
>
> [((1 to: 10000) collect: [:x |3]) asSorterdCollection:[ :a :b | 
> a<b ] timeToRun ==> 183
>
> compared with:
>
> [((1 to: 10000) collect: [:x |3]) asSorterdCollection:[ :a :b |
> a<=b]] timeToRun ==> 29150
>
> Obviously, the comparison is always true, hence something always
> happens (probably a swap).
>
> Hence, not a bug - though I think sorting on <= is inefficient.

It is, but I think there is a bug.

The main problem seems to be that defaultSort:to: recurses way too 
much. I'd expect its recursion depth to max out at log2(size) (I 
think), but it's going down to about (size).

I ran it on 100 items, and it got to a recursion depth of 98 (!). 
Twice.

defaultSort: 1 to: 1000
   calls defaultSort: 1 to: 0
  and defaultSort: 2 to: 1000

which doesn't seem right. For one thing, sorting 1 to: 0 is a waste of 
time.

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE




More information about the Squeak-dev mailing list