--- a/Set.st Thu Feb 16 13:45:01 2017 +0100
+++ b/Set.st Thu Feb 16 14:12:58 2017 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
@@ -200,6 +202,7 @@
"Created: / 24.10.1997 / 23:13:44 / cg"
! !
+
!Set methodsFor:'Compatibility-ST80'!
initialIndexFor:hashKey boundedBy:length
@@ -638,31 +641,33 @@
].
index := self findKeyOrNil:key.
- (keyArray basicAt:index) isNil ifTrue:[
- "/ not already there
- keyArray basicAt:index put:key.
- tally := tally + 1.
+ (keyArray basicAt:index) notNil ifTrue:[
+ ^ true.
+ ].
- self possiblyGrow.
- ^ false.
- ].
- ^ true.
+ "/ not already there
+ keyArray basicAt:index put:key.
+ tally := tally + 1.
- "Modified: 30.1.1997 / 14:58:08 / cg"
+ self possiblyGrow.
+ ^ false.
+
+ "Modified: / 30-01-1997 / 14:58:08 / cg"
+ "Modified: / 16-02-2017 / 13:47:10 / stefan"
! !
!Set methodsFor:'comparing'!
-= aCollection
+= anObject
"return true, if the argument is a Set containing the same elements
as I do"
- aCollection species ~~ self species ifTrue:[^ false].
- aCollection size ~~ self size ifTrue:[^ false].
+ anObject species ~~ self species ifTrue:[^ false].
+ anObject size ~~ self size ifTrue:[^ false].
"/ same number of elements; since I am a Set, all of
"/ of my elements must be in the other collection ...
- self do:[:eachElement | (aCollection includes:eachElement) ifFalse:[^ false]].
+ self do:[:eachElement | (anObject includes:eachElement) ifFalse:[^ false]].
^ true.
"
@@ -714,6 +719,7 @@
"
"Modified: / 13-10-2006 / 12:58:43 / cg"
+ "Modified (comment): / 16-02-2017 / 14:09:32 / stefan"
!
hash
@@ -767,7 +773,7 @@
self class == Set ifTrue:[
^ self copy
].
- ^ super asSet
+ ^ self asSet
"
|s|
@@ -775,6 +781,8 @@
self assert:(s ~~ s asNewSet).
self assert:(s = s asNewSet).
"
+
+ "Modified: / 16-02-2017 / 14:10:43 / stefan"
!
asSet
@@ -825,6 +833,7 @@
! !
+
!Set methodsFor:'obsolete set operations'!
+ aCollection
@@ -1083,18 +1092,6 @@
"Modified: / 4.8.1998 / 22:07:25 / cg"
!
-invalidElementError
- "this is send when a nil is used with a Set.
- For now this is just an info-Message. Will become an error sometimes."
-
- "/ self elementBoundError.
-
- InfoPrinting ifTrue:[
- 'Set [warning]: nil is not a valid element - will be an error in later versions' errorPrintCR.
- Context showWhereWeCameFrom.
- ].
-!
-
keyArray
^ keyArray
@@ -1129,35 +1126,6 @@
]
"Modified: / 30.10.1997 / 16:04:46 / cg"
-!
-
-rehashFrom:startIndex
- "rehash elements starting at index - after a remove.
- Notice: due to the new implementation of remove,
- this is no longer needed"
-
- |element i "{ Class:SmallInteger }"
- length
- index "{ Class:SmallInteger }" |
-
- length := keyArray basicSize.
- index := startIndex.
- element := keyArray basicAt:index.
- [element notNil] whileTrue:[
- i := self findNil:element.
- i == index ifTrue:[
- ^ self
- ].
- keyArray basicAt:i put:element.
- keyArray basicAt:index put:nil.
-
- index == length ifTrue:[
- index := 1
- ] ifFalse:[
- index := index + 1.
- ].
- element := keyArray basicAt:index.
- ]
! !
!Set methodsFor:'private-grow & shrink'!
@@ -1305,6 +1273,7 @@
^ tally
! !
+
!Set methodsFor:'searching'!
findFirst:aBlock ifNone:exceptionValue
@@ -1316,6 +1285,14 @@
Sets do not have indices."
^ self shouldNotImplement
+!
+
+findLast:aBlock ifNone:exceptionValue
+ "Sets do not have indices."
+
+ ^ self shouldNotImplement
+
+ "Created: / 16-02-2017 / 13:54:53 / stefan"
! !
!Set methodsFor:'testing'!