OrdColl.st
changeset 2348 523e9d6e0049
parent 2222 e6fa084818ec
child 2354 652d17daeeb5
--- a/OrdColl.st	Sat Feb 01 11:50:59 1997 +0100
+++ b/OrdColl.st	Sat Feb 01 11:54:01 1997 +0100
@@ -506,33 +506,34 @@
 !
 
 remove:anObject ifAbsent:exceptionBlock
-    "remove the first occurrence of anObject from the collection
-     and return it.
-     If its not in the receiver collection, return the value of exceptionBlock."
+    "remove the first element which is equal to anObject;
+     if found, remove and return it; 
+     if not, return the value from evaluating exceptionBlock.
+     Used equality compare (=) to search for the element."
 
     |index "{ Class:SmallInteger }"|
 
     index := firstIndex.
     [index <= lastIndex] whileTrue:[
-	anObject = (contentsArray at:index) ifTrue:[
-	    contentsArray 
-		replaceFrom:index
-		to:(contentsArray size - 1)
-		with:contentsArray 
-		startingAt:(index + 1).
+        anObject = (contentsArray at:index) ifTrue:[
+            contentsArray 
+                replaceFrom:index
+                to:(contentsArray size - 1)
+                with:contentsArray 
+                startingAt:(index + 1).
 
-    	    "/ nil it (helps GC)
-	    contentsArray at:lastIndex put:nil.
+            "/ nil it (helps GC)
+            contentsArray at:lastIndex put:nil.
 
-	    lastIndex := lastIndex - 1.
-	    firstIndex > lastIndex ifTrue:[
-		"reset to avoid ever growing"
-		firstIndex := 1.
-		lastIndex := 0 
-	    ].
-	    ^ anObject
-	].
-	index := index + 1
+            lastIndex := lastIndex - 1.
+            firstIndex > lastIndex ifTrue:[
+                "reset to avoid ever growing"
+                firstIndex := 1.
+                lastIndex := 0 
+            ].
+            ^ anObject
+        ].
+        index := index + 1
     ].
     ^ exceptionBlock value
 
@@ -542,7 +543,11 @@
 
      #(1 2 3 4 5 6 7 8 9) asOrderedCollection remove:3 ifAbsent:'oops' 
      #(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:'oops' 
+     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops' 
+     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops' 
     "
+
+    "Modified: 1.2.1997 / 11:53:12 / cg"
 !
 
 removeAll
@@ -704,6 +709,46 @@
     "
 !
 
+removeIdentical:anObject ifAbsent:exceptionBlock
+    "remove the first element which is identical to anObject;
+     if found, remove and return it; 
+     if not, return the value from evaluating exceptionBlock.
+     Used equality compare (==) to search for the element."
+
+    |index "{ Class:SmallInteger }"|
+
+    index := firstIndex.
+    [index <= lastIndex] whileTrue:[
+        anObject == (contentsArray at:index) ifTrue:[
+            contentsArray 
+                replaceFrom:index
+                to:(contentsArray size - 1)
+                with:contentsArray 
+                startingAt:(index + 1).
+
+            "/ nil it (helps GC)
+            contentsArray at:lastIndex put:nil.
+
+            lastIndex := lastIndex - 1.
+            firstIndex > lastIndex ifTrue:[
+                "reset to avoid ever growing"
+                firstIndex := 1.
+                lastIndex := 0 
+            ].
+            ^ anObject
+        ].
+        index := index + 1
+    ].
+    ^ exceptionBlock value
+
+    "
+     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops'  
+     #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops' 
+    "
+
+    "Modified: 1.2.1997 / 11:53:47 / cg"
+!
+
 removeLast
     "remove the last element from the collection; return the element"
 
@@ -1557,5 +1602,5 @@
 !OrderedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.55 1997-01-22 03:29:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.56 1997-02-01 10:54:01 cg Exp $'
 ! !