[FIX][ENH] SortedCollection robustness & speedup
Georg Gollmann
georg.gollmann at tuwien.ac.at
Fri Apr 28 07:58:44 UTC 2000
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 at 3.
>
>In this example, the collection includes 3 at 3. The index for
>inserting 3 at 3 is 26,
>but neither array at: 26 or array at: 25 is 3 at 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
--
----
Dipl.Ing. Georg Gollmann TU-Wien, Zentraler Informatikdienst
Wiedner Hauptstr. 8-10
phon:(+43-1) 58801 - 42022 A-1040 Wien
fax: (+43-1) 58801 - 42099
mail:gollmann at zid.tuwien.ac.at
http://macos.tuwien.ac.at/Gollmann.html
More information about the Squeak-dev
mailing list
|