--- a/PluggableSet.st Thu Aug 11 15:20:12 2016 +0200
+++ b/PluggableSet.st Thu Aug 11 15:20:27 2016 +0200
@@ -11,6 +11,8 @@
"
"{ Package: 'stx:libbasic2' }"
+"{ NameSpace: Smalltalk }"
+
Set subclass:#PluggableSet
instanceVariableNames:'hashFunction compareFunction'
classVariableNames:''
@@ -171,10 +173,14 @@
[true] whileTrue:[
probe := keyArray basicAt:index.
- probe notNil ifTrue:[
- (compareFunction value:probe value:key) ifTrue:[^ index]. "<<<< == is different from inherited"
+ probe isNil ifTrue:[
+ ^ aBlock value.
].
- (self slotIsEmpty:probe) ifTrue:[^ aBlock value].
+
+ (probe ~~ DeletedEntry
+ and:[compareFunction value:probe value:key]) ifTrue:[ "<<<< == is different from inherited"
+ ^ index
+ ].
index == length ifTrue:[
index := 1
@@ -202,21 +208,17 @@
length := keyArray basicSize.
startIndex := index := self initialIndexForKey:key.
- [true] whileTrue:[
+ [
probe := keyArray basicAt:index.
- probe notNil ifTrue:[
- (compareFunction value:key value:probe) ifTrue:[^ index].
- ].
- (self slotIsEmpty:probe) ifTrue:[
+ probe isNil ifTrue:[
delIndex == 0 ifTrue:[^ index].
keyArray basicAt:delIndex put:nil.
^ delIndex
].
-
- probe == DeletedEntry ifTrue:[
- delIndex == 0 ifTrue:[
- delIndex := index
- ]
+ (probe == DeletedEntry and:[delIndex == 0]) ifTrue:[
+ delIndex := index.
+ ] ifFalse:[
+ (compareFunction value:probe value:key) ifTrue:[^ index]
].
index == length ifTrue:[
@@ -229,9 +231,56 @@
keyArray basicAt:delIndex put:nil.
^ delIndex
].
- ^ self grow findKeyOrNil:key
+ self grow.
+ length := keyArray basicSize.
+ startIndex := index := self initialIndexForKey:key.
].
- ]
+ ] loop.
+
+ "Modified: 26.3.1996 / 20:00:42 / cg"
+!
+
+findKeyOrNilOrDeletedEntry:key
+ "Look for the key in the receiver.
+ If it is found, return return the index of the first unused slot.
+ Grow the receiver, if key was not found, and no unused slots were present"
+
+ |index "{ Class:SmallInteger }"
+ length "{ Class:SmallInteger }"
+ startIndex probe
+ delIndex "{ Class:SmallInteger }" |
+
+ delIndex := 0.
+
+ length := keyArray basicSize.
+ startIndex := index := self initialIndexForKey:key.
+
+ [
+ probe := keyArray basicAt:index.
+ probe isNil ifTrue:[
+ delIndex == 0 ifTrue:[^ index].
+ ^ delIndex
+ ].
+ (probe == DeletedEntry and:[delIndex == 0]) ifTrue:[
+ delIndex := index.
+ ] ifFalse:[
+ (compareFunction value:probe value:key) ifTrue:[^ index]
+ ].
+
+ index == length ifTrue:[
+ index := 1
+ ] ifFalse:[
+ index := index + 1
+ ].
+ index == startIndex ifTrue:[
+ delIndex ~~ 0 ifTrue:[
+ ^ delIndex
+ ].
+ self grow.
+ length := keyArray basicSize.
+ startIndex := index := self initialIndexForKey:key.
+ ].
+ ] loop.
"Modified: 26.3.1996 / 20:00:42 / cg"
!
@@ -245,10 +294,10 @@
!PluggableSet class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/PluggableSet.st,v 1.2 2014-02-18 21:21:18 cg Exp $'
+ ^ '$Header$'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/PluggableSet.st,v 1.2 2014-02-18 21:21:18 cg Exp $'
+ ^ '$Header$'
! !