|
correction [was: Re: [FIX] SortedCollectionFix-sr]: msg#00743lang.smalltalk.squeak.general
I wrote: <...> > Dictionary>>keysSortedSafely > "Answer a SortedCollection containing the receiver's keys." > | sortedKeys | > sortedKeys _ SortedCollection new: self size. > sortedKeys sortBlock: > [:x :y | "Should really be use <obj, string, num> > compareSafely..." > ((x isString and: [y isString]) > or: [x isNumber and: [y isNumber]]) > ifTrue: [x < y] > ifFalse: [x class == y class > ifTrue: [x printString < y printString] > ifFalse: [x class name < y class name]]]. > self keysDo: [:each | sortedKeys addLast: each]. > ^ sortedKeys reSort > > This seems to be safe, since >>reSort is called in every case, but using > SortedCollection>>addAll: seems to be better here. > > But let's take a look at > SortedCollection>> > addAll: aCollection > aCollection size > (self size // 3) > ifTrue: > [aCollection do: [:each | super addLast: each]. > self reSort] > ifFalse: [aCollection do: [:each | self add: each]]. > ^ aCollection > > Now I see a problem: the implementor (sma) of Dictionary>>keysSortedSafely > possibly has seen, that in his case each element would be added one by one, > instead of adding all unsorted followed by a reSort. And then he has tried > to optimize it... This statement is wrong! Calling SortedCollection>>addAll: with a temporarily constructed OrderedCollection containing the keys unsorted would lead to the "self reSort" case. Don't know, what I've seen here. Sorry, Stephan <...>
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Yahoo archive truncated, Andy Stoffel |
|---|---|
| Next by Date: | Re: [FIX] SortedCollectionFix-sr, Stephan Rudlof |
| Previous by Thread: | Re: [FIX] SortedCollectionFix-sr, Stephan Rudlof |
| Next by Thread: | RE: [FIX] SortedCollectionFix-sr, Andreas Raab |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |