[Pkg] The Trunk: Collections-ul.432.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Mar 15 15:21:17 UTC 2011
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.432.mcz
==================== Summary ====================
Name: Collections-ul.432
Author: ul
Time: 15 March 2011, 2:57:58.007 pm
UUID: fdfbcb54-51ad-2d41-84df-36b50ea10ed6
Ancestors: Collections-cmm.431
- added SequenceableCollection >> #reverseInPlace, because #reverse can't be used to reverse the collection in place.
- changed SequenceableCollection >> #reversed to work with OrderedCollections
- removed OrderedCollection >> #reversed
- updated 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 reverseInPlace.
+ sortBlock := sortBlock
+ ifNil: [ [ :a :b | b <= a ] ]
+ ifNotNil: [ [ :a :b | sortBlock value: b value: a ] ]!
- array := array reversed.
- oldSortBlock := (sortBlock ifNil: [[:a :b | a <= b]]) copy.
- sortBlock := [:a :b | oldSortBlock value: b value: a]!
More information about the Packages
mailing list