--- a/Set.st Mon Aug 13 18:46:45 2012 +0200
+++ b/Set.st Mon Aug 13 19:11:21 2012 +0200
@@ -368,23 +368,6 @@
"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:oldObjectArg ifAbsent:exceptionBlock
"remove oldObject from the collection and return it.
If it was not in the collection return the value of exceptionBlock.
@@ -437,7 +420,7 @@
"Modified: 12.4.1996 / 13:35:06 / cg"
!
-saveRemove:oldObjectArg
+saveRemove:oldObject
"remove the element, oldObject from the collection.
Return the element
(could be non-identical to oldObject, since I hash on equality, not on identity).
@@ -445,6 +428,28 @@
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,
+ 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)"
+
+ ^ self saveRemove:oldObject ifAbsent:[].
+
+ "Created: / 16.11.2001 / 10:23:48 / cg"
+ "Modified: / 16.11.2001 / 10:24:03 / cg"
+!
+
+saveRemove:oldObjectArg ifAbsent:exceptionValueProvider
+ "remove the element, oldObject from the collection.
+ Return the element
+ (could be non-identical to oldObject, since I hash on equality, not on identity).
+ If it was not in the collection return the value of exceptionValueProvider.
+
+ In contrast to #remove:, this does not resize the underlying collection
+ and therefore does NOT rehash & change the elements order.
Therefore this can be used while enumerating the receiver,
which is not possible if #remove: is used.
@@ -465,7 +470,7 @@
].
index := self find:oldObject ifAbsent:0.
- index == 0 ifTrue:[^ nil].
+ index == 0 ifTrue:[^ exceptionValueProvider value].
removedObject := keyArray basicAt:index.
keyArray basicAt:index put:nil.
@@ -1221,11 +1226,11 @@
!Set class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.114 2012-08-13 16:45:28 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.115 2012-08-13 17:11:21 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.114 2012-08-13 16:45:28 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.115 2012-08-13 17:11:21 stefan Exp $'
! !
Set initialize!