#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Tue, 05 Apr 2016 20:44:48 +0200
changeset 19542 0cff447dfffa
parent 19541 1417ba3bcde7
child 19543 2ab62a8fbe29
#REFACTORING by stefan class: Set removed: #slotIsEmpty: changed: #collisionsFor: #find:ifAbsent: #findKeyOrNil:
Set.st
--- a/Set.st	Tue Apr 05 20:29:05 2016 +0200
+++ b/Set.st	Tue Apr 05 20:44:48 2016 +0200
@@ -813,6 +813,7 @@
 ! !
 
 
+
 !Set methodsFor:'obsolete set operations'!
 
 + aCollection
@@ -857,9 +858,9 @@
     startIndex := index := self initialIndexForKey:key.
 
     [
-        probe := (keyArray basicAt:index).
-        (probe notNil and:[probe ~~ DeletedEntry and:[key = probe]]) ifTrue:[^ index].
-        (self slotIsEmpty:probe) ifTrue:[^ aBlock value].
+        probe := keyArray basicAt:index.
+        probe isNil ifTrue:[^ aBlock value].
+        (probe ~~ DeletedEntry and:[key = probe]) ifTrue:[^ index].
 
         index == length ifTrue:[
             index := 1
@@ -883,29 +884,34 @@
 findKeyOrNil:key
     "Look for the key in the receiver.  
      If it is found, return the index of the first unused slot. 
-     Grow the receiver, if key was not found, and no unused slots were present"
+     Grow the receiver, if key was not found, and no unused slots were present
+
+     Warning: an empty slot MUST be filled by the sender - it is only to be sent
+              by at:put: / add: - like methods."
 
     |index  "{ Class:SmallInteger }"
      length "{ Class:SmallInteger }"
      startIndex probe 
-     delIndex|
+     delIndex "{ Class:SmallInteger }"|
+
+    delIndex := 0.
 
     length := keyArray basicSize.
     startIndex := index := self initialIndexForKey:key.
 
     [
         probe := keyArray basicAt:index.
-        (probe notNil and:[probe ~~ DeletedEntry and:[key = probe]]) ifTrue:[^ index].
-        (self slotIsEmpty:probe) ifTrue:[
-            delIndex isNil ifTrue:[^ index].
+        probe isNil ifTrue:[
+            delIndex == 0 ifTrue:[^ index].
             keyArray basicAt:delIndex put:nil.
             ^ delIndex
         ].
-
         probe == DeletedEntry ifTrue:[
-            delIndex isNil ifTrue:[
+            delIndex == 0 ifTrue:[
                 delIndex := index
             ]
+        ] ifFalse:[
+            key = probe ifTrue:[^ index]
         ].
 
         index == length ifTrue:[
@@ -914,7 +920,7 @@
             index := index + 1
         ].
         index == startIndex ifTrue:[
-            delIndex notNil ifTrue:[
+            delIndex ~~ 0 ifTrue:[
                 keyArray basicAt:delIndex put:nil.
                 ^ delIndex
             ].
@@ -1086,13 +1092,6 @@
 	].
 	element := keyArray basicAt:index.
     ]
-!
-
-slotIsEmpty:aSlotValue
-    "only redefined in weak subclasses, since they treat a 0-value
-     as being empty"
-
-    ^ aSlotValue isNil
 ! !
 
 !Set methodsFor:'private-grow & shrink'!
@@ -1204,7 +1203,7 @@
     [
         probe := keyArray basicAt:index.
         (probe notNil and:[key = probe]) ifTrue:[^ count].
-        (self slotIsEmpty:probe) ifTrue:[self error:'non existing key'].
+        probe isNil ifTrue:[self error:'non existing key'].
 
         index == length ifTrue:[
             index := 1.
@@ -1240,6 +1239,7 @@
     ^ tally
 ! !
 
+
 !Set methodsFor:'searching'!
 
 findFirst:aBlock ifNone:exceptionValue