Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.256.mcz ==================== Summary ==================== Name: Collections-nice.256 Author: nice Time: 22 December 2009, 4:29:50 am UUID: 8683c968-b75c-fa4e-9cd0-9da55637590a Ancestors: Collections-ar.255 Correct interval #do: and #reverseDo: from http://bugs.squeak.org/view.php?id=6456 For example, self assert: ((1.0 to: 3.0 by: 1.0 successor) max closeTo: 2.0). Correct inclusion test self assert: ((1.0 to: 3.0 by: 1.0 successor) includes: 3.0) not. =============== Diff against Collections-ar.255 =============== Item was changed: ----- Method: Interval>>reverseDo: (in category 'enumerating') ----- reverseDo: aBlock + "Evaluate aBlock for each element of my interval, in reverse order. + Implementation notes: see do: for an explanation on loop detail" + + | aValue index | + index := self size. + [index > 0] + whileTrue: [ + index := index - 1. + aValue := start + (index * step). + aBlock value: aValue]! - "Evaluate aBlock for each element of my interval, in reverse order." - | aValue | - aValue := self last. - step < 0 - ifTrue: [[start >= aValue] - whileTrue: [aBlock value: aValue. - aValue := aValue - step]] - ifFalse: [[start <= aValue] - whileTrue: [aBlock value: aValue. - aValue := aValue - step]]! Item was changed: ----- Method: Interval>>indexOf:startingAt:ifAbsent: (in category 'accessing') ----- indexOf: anElement startingAt: startIndex ifAbsent: exceptionBlock "startIndex is an positive integer, the collection index where the search is started." "during the computation of val , floats are only used when the receiver contains floats" | index val | (self rangeIncludes: anElement) ifFalse: [^ exceptionBlock value]. val := anElement - self first / self increment. val isFloat ifTrue: [(val - val rounded) abs * 100000000 < 1 ifTrue: [index := val rounded + 1] ifFalse: [^ exceptionBlock value]] ifFalse: [val isInteger ifTrue: [index := val + 1] ifFalse: [^ exceptionBlock value]]. "finally, the value of startIndex comes into play:" + ^ (index between: startIndex and: self size) + ifTrue: [index] + ifFalse: [exceptionBlock value]! - ^ index < startIndex - ifTrue: [exceptionBlock value] - ifFalse: [index]! Item was changed: ----- Method: Interval>>do: (in category 'enumerating') ----- + do: aBlock + "Evaluate aBlock for each value of the interval. + Implementation note: instead of repeatedly incrementing the value + aValue := aValue + step. + until stop is reached, + We prefer to recompute value from start + aValue := start + (index * step). + This is better for floating points accuracy, while not degrading Integer and Fraction speed too much. + Moreover, this is consistent with methods #at: and #size" + + | aValue index size | + index := 0. + size := self size. + [index < size] + whileTrue: [aValue := start + (index * step). + index := index + 1. + aBlock value: aValue]! - do: aBlock - - | aValue | - aValue := start. - step < 0 - ifTrue: [[stop <= aValue] - whileTrue: - [aBlock value: aValue. - aValue := aValue + step]] - ifFalse: [[stop >= aValue] - whileTrue: - [aBlock value: aValue. - aValue := aValue + step]]! |
Free forum by Nabble | Edit this page |