--- a/Set.st Tue Dec 30 01:36:46 2014 +0100
+++ b/Set.st Tue Dec 30 13:35:29 2014 +0100
@@ -11,6 +11,8 @@
"
"{ Package: 'stx:libbasic' }"
+"{ NameSpace: Smalltalk }"
+
Collection subclass:#Set
instanceVariableNames:'tally keyArray'
classVariableNames:'DeletedEntry NilEntry'
@@ -362,7 +364,7 @@
keyArray basicAt:index put:key.
tally := tally + 1.
- self fullCheck.
+ self possiblyGrow.
].
^ keyArg
@@ -403,7 +405,7 @@
(keyArray basicAt:next) notNil ifTrue:[
keyArray basicAt:index put:DeletedEntry.
].
- self emptyCheck
+ self possiblyShrink
].
removedObject == NilEntry ifTrue:[
removedObject := nil.
@@ -465,7 +467,7 @@
(keyArray basicAt:next) notNil ifTrue:[
keyArray basicAt:index put:DeletedEntry.
].
- self emptyCheck
+ self possiblyShrink
].
^ oldObjectArg
!
@@ -625,7 +627,7 @@
keyArray basicAt:index put:key.
tally := tally + 1.
- self fullCheck.
+ self possiblyGrow.
^ false.
].
^ true.
@@ -1087,43 +1089,6 @@
!Set methodsFor:'private-grow & shrink'!
-emptyCheck
- "check if the receiver has become too empty (after a remove)
- and shrink if it makes sense.
- Definition of 'too empty' is 'filled less than 12.5% (i.e. 1/8th)'"
-
- |sz "{Class: SmallInteger}"
- newSize "{Class: SmallInteger}" |
-
- sz := keyArray basicSize.
- sz > 56 ifTrue:[
- "
- shrink if too empty
- "
- tally < (sz // 8) ifTrue:[
- newSize := sz // 4.
- self grow:newSize
- ]
- ]
-
- "Modified: 19.3.1997 / 16:02:55 / cg"
-!
-
-fullCheck
- "check if collection is full (after an add); grow if so.
- Definition of 'full' is currently: 'filled more than 75% (i.e. 3/4th)'"
-
- |sz "{Class: SmallInteger}" |
-
- "
- grow if filled more than 75%
- "
- sz := keyArray basicSize.
- tally > (sz * 3 // 4) ifTrue:[
- self grow
- ]
-!
-
grow
"change the number of element slots of the collection to a useful
new size"
@@ -1154,6 +1119,43 @@
newKeyArray basicAt:(self findNil:elem) put:elem
].
].
+!
+
+possiblyGrow
+ "check if collection is full (after an add); grow if so.
+ Definition of 'full' is currently: 'filled more than 75% (i.e. 3/4th)'"
+
+ |sz "{Class: SmallInteger}" |
+
+ "
+ grow if filled more than 75%
+ "
+ sz := keyArray basicSize.
+ tally > (sz * 3 // 4) ifTrue:[
+ self grow
+ ]
+!
+
+possiblyShrink
+ "check if the receiver has become too empty (after a remove)
+ and shrink if it makes sense.
+ Definition of 'too empty' is: 'filled less than 12.5% (i.e. 1/8th)'"
+
+ |sz "{Class: SmallInteger}"
+ newSize "{Class: SmallInteger}" |
+
+ sz := keyArray basicSize.
+ sz > 56 ifTrue:[
+ "
+ shrink if too empty
+ "
+ tally < (sz // 8) ifTrue:[
+ newSize := sz // 4.
+ self grow:newSize
+ ]
+ ]
+
+ "Modified: 19.3.1997 / 16:02:55 / cg"
! !
!Set methodsFor:'queries'!
@@ -1322,11 +1324,11 @@
!Set class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.128 2014-12-09 10:11:35 sr Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.129 2014-12-30 12:35:29 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.128 2014-12-09 10:11:35 sr Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.129 2014-12-30 12:35:29 cg Exp $'
! !