The Trunk: Collections-ul.737.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ul.737.mcz

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

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

Name: Collections-ul.737
Author: ul
Time: 26 February 2017, 11:57:55.668118 pm
UUID: 8c9af190-2eba-4c9c-98d6-65aab3850908
Ancestors: Collections-ul.736

Part #2 of Improve SequenceableCollection's index-related search methods

- rewrote remaining #indexOf*ifAbsent: implementations in SequenceableCollection
- removed remaining #indexOf*ifAbsent: implementations from subclasses
- implemented correct variant of #indexOfSubCollection:startingAt: in String ('abc' indexOfSubCollection: #[98] startingAt: 1 ifAbsent: [ 0 ] returns 0 instead of 2)

=============== Diff against Collections-ul.736 ===============

Item was removed:
- ----- Method: ByteArray>>indexOf:startingAt:ifAbsent: (in category 'accessing') -----
- indexOf: anInteger startingAt: start ifAbsent: aBlock
-
- | index |
- (index := self indexOf: anInteger startingAt: start) = 0 ifTrue: [ ^aBlock value ].
- ^index!

Item was removed:
- ----- Method: ByteString>>indexOfAnyOf:startingAt:ifAbsent: (in category 'accessing') -----
- indexOfAnyOf: aCollection startingAt: start ifAbsent: aBlock
- "Use double dispatching for speed"
- | index |
- ^(index := aCollection findFirstInByteString: self startingAt: start) = 0
- ifTrue: [aBlock value]
- ifFalse: [index]!

Item was removed:
- ----- Method: ByteSymbol>>indexOfAnyOf:startingAt:ifAbsent: (in category 'accessing') -----
- indexOfAnyOf: aCollection startingAt: start ifAbsent: aBlock
- "Use double dispatching for speed"
- | index |
- ^(index := aCollection findFirstInByteString: self startingAt: start) = 0
- ifTrue: [aBlock value]
- ifFalse: [index]!

Item was removed:
- ----- 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]!

Item was removed:
- ----- Method: LinkedList>>indexOf:startingAt:ifAbsent: (in category 'private') -----
- indexOf: anElement startingAt: start ifAbsent: exceptionBlock
- "Answer the index of the first occurence of anElement after start
- within the receiver. If the receiver does not contain anElement,
- answer the result of evaluating the argument, exceptionBlock."
-
- |currentLink index|
- currentLink := self linkAt: start ifAbsent: [nil].
- index := start.
- [currentLink isNil ]
- whileFalse: [currentLink value = anElement value ifTrue: [^index].
- currentLink := currentLink nextLink.
- index := index +1].
- ^exceptionBlock value!

Item was removed:
- ----- Method: OrderedCollection>>indexOf:startingAt:ifAbsent: (in category 'accessing') -----
- indexOf: anElement startingAt: start ifAbsent: exceptionBlock
- "Optimized version."
-
- firstIndex + start - 1 to: lastIndex do: [ :index |
- (array at: index) = anElement ifTrue: [ ^index - firstIndex + 1 ] ].
- ^exceptionBlock value!

Item was changed:
  ----- Method: SequenceableCollection>>indexOf:startingAt:ifAbsent: (in category 'accessing') -----
  indexOf: anElement startingAt: start ifAbsent: exceptionBlock
  "Answer the index of the first occurence of anElement after start
  within the receiver. If the receiver does not contain anElement,
  answer the result of evaluating the argument, exceptionBlock."
 
+ | index |
+ (index := self indexOf: start startingAt: start) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- start to: self size do:
- [:index |
- (self at: index) = anElement ifTrue: [^ index]].
- ^ exceptionBlock value!

Item was changed:
  ----- Method: SequenceableCollection>>indexOfAnyOf:startingAt:ifAbsent: (in category 'accessing') -----
  indexOfAnyOf: aCollection startingAt: start ifAbsent: exceptionBlock
  "Answer the index of the first occurence of any element included in aCollection after start within the receiver.
  If the receiver does not contain anElement, answer the result of evaluating the argument, exceptionBlock.
  Note: it is user responsibility to provide aCollection that behaves relatevily fast when asked for includes: (like a Set)"
 
+ | index |
+ (index := self indexOfAnyOf: aCollection startingAt: start) = 0 ifFalse: [ ^index ].
+ ^exceptionBlock value!
- start to: self size do:
- [:index |
- (aCollection includes: (self at: index)) ifTrue: [^ index]].
- ^ exceptionBlock value!

Item was removed:
- ----- Method: String>>indexOf:startingAt:ifAbsent: (in category 'accessing') -----
- indexOf: aCharacter  startingAt: start  ifAbsent: aBlock
-
- | index |
- (index := self indexOf: aCharacter startingAt: start) = 0 ifTrue: [ ^aBlock value ].
- ^index!

Item was added:
+ ----- Method: String>>indexOfSubCollection:startingAt: (in category 'accessing') -----
+ indexOfSubCollection: subCollection startingAt: start
+
+ subCollection isString ifFalse: [ ^super indexOfSubCollection: subCollection startingAt: start ].
+ ^self findString: subCollection startingAt: start caseSensitive: true!

Item was removed:
- ----- Method: String>>indexOfSubCollection:startingAt:ifAbsent: (in category 'accessing') -----
- indexOfSubCollection: sub startingAt: start ifAbsent: exceptionBlock
- | index |
- index := self findString: sub startingAt: start.
- index = 0 ifTrue: [^ exceptionBlock value].
- ^ index!