On Wed, 23 Dec 2009, Stéphane Ducasse wrote:
levente
I compared
in Squeak
Arrayed ... sort: nil
mergeFirst: first middle: middle last: last into: dst by: aBlock
... [ (i1 <= middle) and: [ i2 <= last ] ] whileTrue: [ (aBlock ifNil: [ val1 <= val2 ] ifNotNil: [ aBlock value: val1 value: val2 ]) ifTrue: [ dst at: (out := out + 1) put: val1. val1 := self at: (i1 := i1 + 1)] ifFalse: [ dst at: (out := out + 1) put: val2. (i2 := i2 + 1) <= last ifTrue: [ val2 := self at: i2 ] ] ]. ...
in pharo
Arrayed ... sort: [:a :b | a <= b]
mergeFirst: first middle: middle last: last into: dst by: aBlock ... [(i1 <= middle) and: [i2 <= last]] whileTrue: [(aBlock value: val1 value: val2) ifTrue: [dst at: (out := out + 1) put: val1. val1 := self at: (i1 := i1 + 1)] ifFalse: [dst at: (out := out + 1) put: val2. i2 := i2 + 1. i2 <= last ifTrue: [val2 := self at: i2]]].
what is the best?
It's a hack, I took it from SortedCollection's quicksort implementation. This gives the best performance if you're sorting by <= which is the default. Levente
Stef
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project