Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.259.mcz ==================== Summary ==================== Name: Collections-ul.259 Author: ul Time: 22 December 2009, 7:44:15 am UUID: a72038cf-e6a6-9a41-ae33-4a060f20af91 Ancestors: Collections-ar.256, Collections-nice.256 - merged Collections-nice.256 =============== Diff against Collections-ar.256 =============== 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 |