Set.st
branchjv
changeset 17795 569eec7576f1
parent 17780 b6e42c92eba0
child 17807 06cc6c49e291
--- a/Set.st	Sun Aug 01 12:11:07 2010 +0100
+++ b/Set.st	Tue Aug 10 09:55:15 2010 +0100
@@ -340,6 +340,23 @@
     "Modified: 30.1.1997 / 14:58:08 / cg"
 !
 
+addAllNonNilElements:aCollection
+    "add all non-nil elements of the argument, aCollection to the receiver.
+     Use this, when operating on a Set, that cannot hold nil.
+     Answer the argument, aCollection (sigh)."
+
+    aCollection do:[:eachElement |
+        eachElement notNil ifTrue:[
+            self add:eachElement
+        ].
+    ].
+    ^ aCollection
+
+    "
+     #(1 2 3 4) asSet addAllNonNilElements:#(5 nil 6 7 8)
+    "
+!
+
 remove:oldObject ifAbsent:exceptionBlock
     "remove oldObject from the collection and return it.
      If it was not in the collection return the value of exceptionBlock.
@@ -393,13 +410,13 @@
 
      In contrast to #remove:, this does not resize the underlying collection
      and therefore does NOT rehash & change the elements order.
-     Therefor this can be used while enumerating the receiver,
+     Therefore this can be used while enumerating the receiver,
      which is not possible if #remove: is used.
 
      WARNING: since no resizing is done, the physical amount of memory used
-	      by the container remains the same, although the logical size shrinks.
-	      You may want to manually resize the receiver using #emptyCheck.
-	      (after the loop)"
+              by the container remains the same, although the logical size shrinks.
+              You may want to manually resize the receiver using #emptyCheck.
+              (after the loop)"
 
     |index "{ Class:SmallInteger }"
      next  "{ Class:SmallInteger }"
@@ -415,59 +432,59 @@
 
     tally := tally - 1.
     tally ~~ 0 ifTrue:[
-	index == keyArray basicSize ifTrue:[
-	    next := 1
-	] ifFalse:[
-	    next := index + 1.
-	].
-	(keyArray basicAt:next) notNil ifTrue:[
-	    keyArray basicAt:index put:DeletedEntry
-	].
+        index == keyArray basicSize ifTrue:[
+            next := 1
+        ] ifFalse:[
+            next := index + 1.
+        ].
+        (keyArray basicAt:next) notNil ifTrue:[
+            keyArray basicAt:index put:DeletedEntry
+        ].
     ].
     ^ removedObject
 
     "does NOT work:
 
-	|s|
+        |s|
 
-	s := Set new.
-	s add:1.
-	s add:2.
-	s add:3.
-	s add:4.
-	s add:5.
-	s add:6.
-	s add:7.
-	s add:8.
-	s add:9.
-	s do:[:v |
-	    v odd ifTrue:[
-		s remove:v 
-	    ]
-	].
-	s inspect
+        s := Set new.
+        s add:1.
+        s add:2.
+        s add:3.
+        s add:4.
+        s add:5.
+        s add:6.
+        s add:7.
+        s add:8.
+        s add:9.
+        s do:[:v |
+            v odd ifTrue:[
+                s remove:v 
+            ]
+        ].
+        s inspect
     "
 
     "DOES work:
 
-	|s|
+        |s|
 
-	s := Set new.
-	s add:1.
-	s add:2.
-	s add:3.
-	s add:4.
-	s add:5.
-	s add:6.
-	s add:7.
-	s add:8.
-	s add:9.
-	s do:[:v |
-	    v odd ifTrue:[
-		s saveRemove:v 
-	    ]
-	].
-	s inspect
+        s := Set new.
+        s add:1.
+        s add:2.
+        s add:3.
+        s add:4.
+        s add:5.
+        s add:6.
+        s add:7.
+        s add:8.
+        s add:9.
+        s do:[:v |
+            v odd ifTrue:[
+                s saveRemove:v 
+            ]
+        ].
+        s inspect
     "
 
     "Created: / 1.3.1996 / 21:14:26 / cg"
@@ -1055,6 +1072,7 @@
     ^ tally
 ! !
 
+
 !Set methodsFor:'testing'!
 
 capacity 
@@ -1156,18 +1174,19 @@
 !Set class methodsFor:'documentation'!
 
 version
-    ^ '$Id: Set.st 10544 2010-07-12 16:20:36Z vranyj1 $'
+    ^ '$Id: Set.st 10564 2010-08-10 08:55:15Z vranyj1 $'
 !
 
 version_CVS
-    ^ 'Header: /cvs/stx/stx/libbasic/Set.st,v 1.105 2010/02/26 10:53:48 cg Exp '
+    ^ 'Header: /cvs/stx/stx/libbasic/Set.st,v 1.106 2010/07/23 19:40:09 stefan Exp '
 !
 
 version_SVN
-    ^ '$Id: Set.st 10544 2010-07-12 16:20:36Z vranyj1 $'
+    ^ '$Id: Set.st 10564 2010-08-10 08:55:15Z vranyj1 $'
 ! !
 
 Set initialize!
 
 
 
+