--- a/SeqColl.st Fri Jan 31 17:04:24 1997 +0100
+++ b/SeqColl.st Sat Feb 01 11:50:10 1997 +0100
@@ -332,8 +332,9 @@
!
remove:anElement ifAbsent:aBlock
- "search for anElement and, if present remove and return it.
- If not present, return the value of evaluating aBlock.
+ "search for an object 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.
Also note, that it may be a slow operation for some collections,
@@ -348,25 +349,29 @@
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
- ]
+ (anElement = (self at:srcIndex)) ifTrue:[
+ any := true
+ ] ifFalse:[
+ (dstIndex ~~ srcIndex) ifTrue:[
+ self at:dstIndex put:(self at:srcIndex)
+ ].
+ dstIndex := dstIndex + 1
+ ]
].
any ifTrue:[
- self grow:dstIndex - 1.
- ^ anElement
+ self grow:dstIndex - 1.
+ ^ anElement
].
^ aBlock value
"
#(1 2 3 4 5 6 7 8 9 0) remove:3 ifAbsent:[Transcript showCR:'no']
#(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]
"
+
+ "Modified: 1.2.1997 / 11:49:01 / cg"
!
removeAllSuchThat:aBlock
@@ -505,6 +510,47 @@
"
!
+removeIdentical:anElement ifAbsent:aBlock
+ "search for an object which is identical to anElement;
+ if found remove and return it; if not, return the value from evaluating aBlock.
+ Use identity compare (==) to search for an occurrence.
+
+ Notice, that this is modifies the receiver NOT a copy.
+ Also note, that it may be a slow operation for some collections,
+ due to the grow:-message, which is inefficient for fixed size
+ collections (i.e. for Strings and Arrays it is not recommened)."
+
+ |any
+ 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 ifTrue:[
+ self grow:dstIndex - 1.
+ ^ anElement
+ ].
+ ^ aBlock value
+
+ "
+ #(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]
+ "
+
+ "Created: 1.2.1997 / 11:49:25 / cg"
+!
+
removeIndex:index
"remove the argument stored at index. Return the receiver.
@@ -2902,5 +2948,5 @@
!SequenceableCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.73 1997-01-28 11:35:50 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.74 1997-02-01 10:50:10 cg Exp $'
! !
--- a/SequenceableCollection.st Fri Jan 31 17:04:24 1997 +0100
+++ b/SequenceableCollection.st Sat Feb 01 11:50:10 1997 +0100
@@ -332,8 +332,9 @@
!
remove:anElement ifAbsent:aBlock
- "search for anElement and, if present remove and return it.
- If not present, return the value of evaluating aBlock.
+ "search for an object 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.
Also note, that it may be a slow operation for some collections,
@@ -348,25 +349,29 @@
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
- ]
+ (anElement = (self at:srcIndex)) ifTrue:[
+ any := true
+ ] ifFalse:[
+ (dstIndex ~~ srcIndex) ifTrue:[
+ self at:dstIndex put:(self at:srcIndex)
+ ].
+ dstIndex := dstIndex + 1
+ ]
].
any ifTrue:[
- self grow:dstIndex - 1.
- ^ anElement
+ self grow:dstIndex - 1.
+ ^ anElement
].
^ aBlock value
"
#(1 2 3 4 5 6 7 8 9 0) remove:3 ifAbsent:[Transcript showCR:'no']
#(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]
"
+
+ "Modified: 1.2.1997 / 11:49:01 / cg"
!
removeAllSuchThat:aBlock
@@ -505,6 +510,47 @@
"
!
+removeIdentical:anElement ifAbsent:aBlock
+ "search for an object which is identical to anElement;
+ if found remove and return it; if not, return the value from evaluating aBlock.
+ Use identity compare (==) to search for an occurrence.
+
+ Notice, that this is modifies the receiver NOT a copy.
+ Also note, that it may be a slow operation for some collections,
+ due to the grow:-message, which is inefficient for fixed size
+ collections (i.e. for Strings and Arrays it is not recommened)."
+
+ |any
+ 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 ifTrue:[
+ self grow:dstIndex - 1.
+ ^ anElement
+ ].
+ ^ aBlock value
+
+ "
+ #(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]
+ "
+
+ "Created: 1.2.1997 / 11:49:25 / cg"
+!
+
removeIndex:index
"remove the argument stored at index. Return the receiver.
@@ -2902,5 +2948,5 @@
!SequenceableCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.73 1997-01-28 11:35:50 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.74 1997-02-01 10:50:10 cg Exp $'
! !