TreeSet.st
changeset 3712 7f02da6caef2
parent 3011 ff9d57003145
child 4122 d868c6e94d96
--- a/TreeSet.st	Fri Jan 22 13:24:41 2016 +0100
+++ b/TreeSet.st	Fri Jan 22 13:27:45 2016 +0100
@@ -1,5 +1,7 @@
 "{ Package: 'stx:libbasic2' }"
 
+"{ NameSpace: Smalltalk }"
+
 Collection subclass:#TreeSet
 	instanceVariableNames:'tree sortKey'
 	classVariableNames:''
@@ -103,14 +105,23 @@
 !
 
 remove: anObject
-	| key bucket |
-	key _ self keyForValue: anObject.
-	bucket _ tree at: key ifAbsent: [^ self].
-	(self bucket: bucket includes: anObject) ifTrue:
-		[bucket _ bucket reject: [:ea | self value: anObject matches: ea].
-		bucket isEmpty
-			ifTrue: [tree removeKey: key]
-			ifFalse: [tree at: key put: bucket]]
+    "remove all occurrences of anObject
+     Warning:
+        This is inconsistent with the inherited collection>>remove:,
+        which only remove the first occurrence.
+        Should this be fixed?"
+    
+    | key bucket |
+    
+    key := self keyForValue: anObject.
+    bucket := tree at: key ifAbsent: [^ self].
+    (self bucket: bucket includes: anObject) ifTrue:[
+        "/ cg: wrong code here: removes all, not only the first match
+        bucket := bucket reject: [:ea | self value: anObject matches: ea].
+        bucket isEmpty
+                ifTrue: [tree removeKey: key]
+                ifFalse: [tree at: key put: bucket]
+    ]
 !
 
 sortSelector
@@ -128,6 +139,6 @@
 !TreeSet class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/TreeSet.st,v 1.3 2013-06-25 11:22:55 cg Exp $'
+    ^ '$Header$'
 ! !