[squeak-dev] The Trunk: Collections-ul.433.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Mar 15 15:20:58 UTC 2011
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.433.mcz
==================== Summary ====================
Name: Collections-ul.433
Author: ul
Time: 15 March 2011, 4:20:20.644 pm
UUID: 08029ff7-30fe-d441-b986-39a04ae7f730
Ancestors: Collections-ul.432
- fix: the array has to be copied in SortedCollection >> #reverseInPlace
=============== Diff against Collections-cmm.431 ===============
Item was removed:
- ----- Method: OrderedCollection>>reversed (in category 'copying') -----
- reversed
- "Answer a copy of the receiver with element order reversed. "
- | newCol |
- newCol := self species new.
- self reverseDo:
- [:elem | newCol addLast: elem].
- ^ newCol
-
- "#(2 3 4 'fred') reversed"!
Item was changed:
----- Method: SequenceableCollection>>reverse (in category 'converting') -----
reverse
+ "The ANSI standard (5.7.8.26) requires this method to return a copy of the receiver. If you want to reverse the collection in place, then use #reverseInPlace."
- "This method will be the in place version sometime"
- self deprecated: 'Use #reversed'.
^self reversed!
Item was added:
+ ----- Method: SequenceableCollection>>reverseInPlace (in category 'converting') -----
+ reverseInPlace
+ "Reverse this collect in place."
+
+ | start end |
+ start := 1.
+ end := self size.
+ [ start < end ] whileTrue: [
+ | temp |
+ temp := self at: start.
+ self
+ at: start put: (self at: end);
+ at: end put: temp.
+ start := start + 1.
+ end := end - 1 ]
+ !
Item was changed:
----- Method: SequenceableCollection>>reversed (in category 'converting') -----
reversed
"Answer a copy of the receiver with element order reversed."
"Example: 'frog' reversed"
| n result src |
n := self size.
+ result := self species ofSize: n.
- result := self species new: n.
src := n + 1.
1 to: n do: [:i | result at: i put: (self at: (src := src - 1))].
^ result
!
Item was changed:
----- Method: SortedCollection>>reverseInPlace (in category 'converting') -----
reverseInPlace
"Change this colleciton into its reversed.
Do not make a copy like reversed do, but change self in place."
+ | newFirstIndex |
- | newFirstIndex oldSortBlock |
newFirstIndex := 1 + array size - lastIndex.
lastIndex := 1 + array size - firstIndex.
firstIndex := newFirstIndex.
array := array reversed.
+ sortBlock := sortBlock
+ ifNil: [ [ :a :b | b <= a ] ]
+ ifNotNil: [ [ :a :b | sortBlock value: b value: a ] ]!
- oldSortBlock := (sortBlock ifNil: [[:a :b | a <= b]]) copy.
- sortBlock := [:a :b | oldSortBlock value: b value: a]!
More information about the Squeak-dev
mailing list
|