--- a/Set.st Wed Nov 20 15:12:13 2013 +0000
+++ b/Set.st Mon Nov 25 10:37:44 2013 +0000
@@ -198,6 +198,7 @@
"Created: / 24.10.1997 / 23:13:44 / cg"
! !
+
!Set methodsFor:'Compatibility-ST80'!
initialIndexFor:hashKey boundedBy:length
@@ -421,6 +422,55 @@
"Modified: 12.4.1996 / 13:35:06 / cg"
!
+removeIdentical:oldObjectArg ifAbsent:exceptionBlock
+ "remove oldObject from the collection and return it.
+ If it was not in the collection return the value of exceptionBlock.
+ Uses identity compare (==) to search for an occurrence.
+
+ WARNING: do not remove elements while iterating over the receiver.
+ See #saveRemove: to do this."
+
+ |oldObject index next|
+
+ oldObjectArg isNil ifTrue:[
+ oldObject := NilEntry.
+ ] ifFalse:[
+ oldObject := oldObjectArg.
+ ].
+
+ "first a quick check.
+ There is a high possibility that objects, which are
+ equal are also identical"
+ index := self find:oldObject ifAbsent:0.
+ index ~~ 0 ifTrue:[
+ oldObject ~~ (keyArray basicAt:index) ifTrue:[
+ index := 0.
+ ]
+ ].
+ index == 0 ifTrue:[
+ "have to go the long and hard path..."
+ index := self findIdentical:oldObject ifAbsent:0.
+ index == 0 ifTrue:[^ exceptionBlock value].
+ ].
+
+ keyArray basicAt:index put:nil.
+ tally := tally - 1.
+ tally == 0 ifTrue:[
+ keyArray := self keyContainerOfSize:(self class goodSizeFrom:0).
+ ] ifFalse:[
+ index == keyArray basicSize ifTrue:[
+ next := 1
+ ] ifFalse:[
+ next := index + 1.
+ ].
+ (keyArray basicAt:next) notNil ifTrue:[
+ keyArray basicAt:index put:DeletedEntry.
+ ].
+ self emptyCheck
+ ].
+ ^ oldObjectArg
+!
+
saveRemove:oldObject
"remove the element, oldObject from the collection.
Return the element
@@ -800,6 +850,14 @@
"Modified: / 03-02-2011 / 13:53:18 / sr"
!
+findIdentical:key ifAbsent:aBlock
+ "Look for the key in the receiver. If it is found, return
+ the index of the slot containing the key, otherwise
+ return the value of evaluating aBlock."
+
+ ^ keyArray identityIndexOf:key ifAbsent:aBlock
+!
+
findKeyOrNil:key
"Look for the key in the receiver.
If it is found, return the index of the first unused slot.
@@ -1206,29 +1264,6 @@
^ 1
"Modified: / 16.11.2001 / 10:30:14 / cg"
-!
-
-sameContentsAs:aCollection
- "answer true, if all the elements in self and aCollection
- are common. This is not defined as #=, since we cannot redefine #hash
- for aCollection."
-
- aCollection size ~~ self size ifTrue:[
- ^ false
- ].
-
- ^ aCollection conform:[:e | (self includes:e)]
-
- "
- #(1 2 3) asSet sameContentsAs: #(1 2 3)
- #(1 2 3 4) asSet sameContentsAs: #(1 2 3)
- #(1 2 3) asSet sameContentsAs: #(1 2 3 3)
- #(1 2 3 'aa') asSet sameContentsAs: #(1 2 3 'aa')
- #(1 2 3 'aa') asIdentitySet sameContentsAs: #(1 2 3 'aa')
- #(1 2 3 #aa) asIdentitySet sameContentsAs: #(1 2 3 #aa)
- "
-
- "Modified: / 13-10-2006 / 12:59:01 / cg"
! !
!Set methodsFor:'visiting'!
@@ -1262,11 +1297,11 @@
!Set class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.120 2013-04-03 09:10:55 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.122 2013-11-14 15:33:50 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.120 2013-04-03 09:10:55 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.122 2013-11-14 15:33:50 stefan Exp $'
! !