--- a/SequenceableCollection.st Thu Jan 21 17:58:19 2016 +0000
+++ b/SequenceableCollection.st Sat Jan 23 07:23:05 2016 +0000
@@ -1190,8 +1190,10 @@
!
remove:anElement ifAbsent:aBlock
- "search for an object which is equal to anElement;
- if found remove and return it; if not, return the value from evaluating aBlock.
+ "search for the first occurrrence of object
+ (i.e. which is equal to anElement)
+ If found remove and return it;
+ if not, return the value from evaluating aBlock.
Use equality compare (=) to search for an occurrence.
Notice, that this is modifies the receiver NOT a copy.
@@ -1199,26 +1201,28 @@
due to the grow:-message, which is inefficient for fixed size
collections (i.e. for Strings and Arrays it is not recommened)."
- |any
+ |any foundElement
dstIndex "{ Class: SmallInteger }"
sz "{ Class: SmallInteger }"|
- dstIndex := 1.
any := false.
sz := self size.
1 to:sz do:[:srcIndex |
- (anElement = (self at:srcIndex)) ifTrue:[
- any := true
- ] ifFalse:[
- (dstIndex ~~ srcIndex) ifTrue:[
- self at:dstIndex put:(self at:srcIndex)
- ].
- dstIndex := dstIndex + 1
- ]
+ any ifFalse:[
+ "/ still searching
+ (anElement = (foundElement := self at:srcIndex)) ifTrue:[
+ any := true.
+ dstIndex := srcIndex.
+ ]
+ ] ifTrue:[
+ "/ already copying
+ self at:dstIndex put:(self at:srcIndex).
+ dstIndex := dstIndex + 1
+ ]
].
any ifTrue:[
- self grow:dstIndex - 1.
- ^ anElement
+ self grow:dstIndex - 1.
+ ^ foundElement
].
^ aBlock value
@@ -1227,6 +1231,16 @@
#(1 2 3 4 5 6 7 8 9 0) remove:99 ifAbsent:[#oops]
#(1.0 2.0 3.0 4.0 5.0) remove:5 ifAbsent:[#oops]
#(1.0 2.0 3.0 4.0 5.0) removeIdentical:5 ifAbsent:[#oops]
+
+ |a|
+ a := #(1 2 3 1 2 3 1 2 3).
+ a remove:3.
+ a
+
+ |a|
+ a := #(1 2 3 1 2 3 1 2 3) asOrderedCollection.
+ a remove:3.
+ a
"
"Modified: 1.2.1997 / 11:49:01 / cg"
@@ -1378,27 +1392,28 @@
due to the grow:-message, which is inefficient for fixed size
collections (i.e. for Strings and Arrays it is not recommened)."
- |any el
+ |any
dstIndex "{ Class: SmallInteger }"
sz "{ Class: SmallInteger }"|
- dstIndex := 1.
any := false.
sz := self size.
1 to:sz do:[:srcIndex |
- el := self at:srcIndex.
- (anElement == el) ifTrue:[
- any := true
- ] ifFalse:[
- (dstIndex ~~ srcIndex) ifTrue:[
- self at:dstIndex put:el
- ].
- dstIndex := dstIndex + 1
- ]
+ any ifFalse:[
+ "/ still searching
+ (anElement == (self at:srcIndex)) ifTrue:[
+ any := true.
+ dstIndex := srcIndex.
+ ]
+ ] ifTrue:[
+ "/ already copying
+ self at:dstIndex put:(self at:srcIndex).
+ dstIndex := dstIndex + 1
+ ]
].
any ifTrue:[
- self grow:dstIndex - 1.
- ^ anElement
+ self grow:dstIndex - 1.
+ ^ anElement
].
^ aBlock value