[squeak-dev] The Trunk: Collections-ul.529.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Aug 8 12:43:35 UTC 2013


Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.529.mcz

==================== Summary ====================

Name: Collections-ul.529
Author: ul
Time: 8 August 2013, 2:41:52.108 pm
UUID: 50df97ce-0aed-44f0-a0bf-e0f96d541205
Ancestors: Collections-fbs.528

- reimplemented ArrayedCollection >> #isSorted and #isSortedBy:
- added #isSorted and #isSortedBy: to OrderedCollection
- added two new variants: #isSortedBetween:and: and #isSortedBy:between:and: which only check the given range

=============== Diff against Collections-fbs.528 ===============

Item was changed:
  ----- Method: ArrayedCollection>>isSorted (in category 'sorting') -----
  isSorted
+ 	"Return true if the receiver is sorted by #<=."
- 	"Return true if the receiver is sorted by the given criterion.
- 	Optimization for isSortedBy: [:a :b | a <= b]."
  
+ 	^self isSortedBetween: 1 and: self size!
- 	| lastElm elm |
- 	self isEmpty ifTrue: [^ true].
- 	lastElm := self first.
- 	2 to: self size do: 
- 		[:index | 
- 		elm := self at: index.
- 		lastElm <= elm ifFalse: [^ false].
- 		lastElm := elm].
- 	^ true!

Item was added:
+ ----- Method: ArrayedCollection>>isSortedBetween:and: (in category 'sorting') -----
+ isSortedBetween: startIndex and: endIndex
+ 	"Return true if the receiver is sorted by #<= between startIndex and endIndex."
+ 
+ 	| previousElement |
+ 	endIndex < startIndex ifTrue: [ ^true ].
+ 	previousElement := self at: startIndex.
+ 	startIndex + 1 to: endIndex do: [ :index |
+ 		| element |
+ 		element := self at: index.
+ 		previousElement <= element ifFalse: [ ^false ].
+ 		previousElement := element ].
+ 	^true!

Item was changed:
  ----- Method: ArrayedCollection>>isSortedBy: (in category 'sorting') -----
+ isSortedBy: aSortBlockOrNil
+ 	"Return true if the receiver is sorted by aSortBlockOrNil. Use #<= for comparison if aSortBlockOrNil is nil."
- isSortedBy: aBlock
- 	"Return true if the receiver is sorted by the given criterion."
  
+ 	^self isSortedBy: aSortBlockOrNil between: 1 and: self size!
- 	| lastElm elm |
- 	self isEmpty ifTrue: [^ true].
- 	lastElm := self first.
- 	2 to: self size do: 
- 		[:index | 
- 		elm := self at: index.
- 		(aBlock value: lastElm value: elm) ifFalse: [^ false].
- 		lastElm := elm].
- 	^ true!

Item was added:
+ ----- Method: ArrayedCollection>>isSortedBy:between:and: (in category 'sorting') -----
+ isSortedBy: aSortBlockOrNil between: startIndex and: endIndex
+ 	"Return true if the receiver is sorted by aSortBlockOrNil between startIndex and endIndex. Use #<= for comparison if aSortBlockOrNil is nil."
+ 
+ 	| previousElement |
+ 	aSortBlockOrNil ifNil: [ ^self isSortedBetween: startIndex and: endIndex ].
+ 	endIndex < startIndex ifTrue: [ ^true ].
+ 	previousElement := self at: startIndex.
+ 	startIndex + 1 to: endIndex do: [ :index |
+ 		| element |
+ 		element := self at: index.
+ 		(aSortBlockOrNil value: previousElement value: element) ifFalse: [ ^false ].
+ 		previousElement := element ].
+ 	^true!

Item was added:
+ ----- Method: OrderedCollection>>isSorted (in category 'sorting') -----
+ isSorted
+ 	"Return true if the receiver is sorted by #<=."
+ 	
+ 	^array
+ 		isSortedBetween: firstIndex
+ 		and: lastIndex!

Item was added:
+ ----- Method: OrderedCollection>>isSortedBetween:and: (in category 'sorting') -----
+ isSortedBetween: startIndex and: endIndex
+ 	"Return true if the receiver is sorted by #<= between startIndex and endIndex."
+ 	
+ 	^array isSortedBetween: startIndex + firstIndex - 1 and: endIndex + firstIndex - 1!

Item was added:
+ ----- Method: OrderedCollection>>isSortedBy: (in category 'sorting') -----
+ isSortedBy: aSortBlockOrNil
+ 	"Return true if the receiver is sorted by aSortBlockOrNil. Use #<= for comparison if aSortBlockOrNil is nil."
+ 	
+ 	^array
+ 		isSortedBy: aSortBlockOrNil
+ 		between: firstIndex
+ 		and: lastIndex!

Item was added:
+ ----- Method: OrderedCollection>>isSortedBy:between:and: (in category 'sorting') -----
+ isSortedBy: aSortBlockOrNil between: startIndex and: endIndex
+ 	"Return true if the receiver is sorted by #<= between startIndex and endIndex."
+ 	
+ 	^array
+ 		isSortedBy: aSortBlockOrNil
+ 		between: startIndex + firstIndex - 1
+ 		and: endIndex + firstIndex - 1!



More information about the Squeak-dev mailing list