At 12:03 Uhr -0700 27.04.2000, Andres Valloud wrote:
s _ SortedCollection sortBlock: [:x :y | x x + x y < (y x + y y)]. 1 to: 5 do: [:each | 1 to: 5 do: [:some | s add: each @ some]]. s includes: 3@3.
In this example, the collection includes 3@3. The index for inserting 3@3 is 26, but neither array at: 26 or array at: 25 is 3@3.
A valid observation, thanks. I was not aware how little a SortedCollection actually knows about its content.
!SortedCollection methodsFor: 'adding' stamp: 'go 4/27/2000 13:16'! addAll: aCollection "Optimize for large additions."
aCollection size > (self size // 3) ifTrue: [ aCollection do: [ :each | super addLast: each ]. self reSort ] ifFalse: [ aCollection do: [ :each | self add: each ]]. ^aCollection! !
This may modify aCollection, although the collection supposed to be modified was the receiver. Merge sort would be ok, but only if both collections had equivalent (or nil) sortBlocks.
Sorry, I do not understand this one. Can you elaborate ?
Georg