WeakValueDictionary.st
changeset 6041 553103122a36
parent 4350 5aa2a3b9fd5b
child 6233 0a79cbd07543
--- a/WeakValueDictionary.st	Mon Sep 24 11:48:53 2001 +0200
+++ b/WeakValueDictionary.st	Mon Sep 24 16:38:26 2001 +0200
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+"{ Package: 'stx:libbasic' }"
+
 Dictionary subclass:#WeakValueDictionary
 	instanceVariableNames:''
 	classVariableNames:''
@@ -149,27 +151,44 @@
     |wasBlocked|
 
     something == #ElementExpired ifTrue:[
-        "
-         have to block here - dispose may be done at a low priority
-         from the background finalizer. If new items are added by a 
-         higher prio process, the dictionary might get corrupted otherwise
-        "
-        wasBlocked := OperatingSystem blockInterrupts.
-
-        valueArray 
-            forAllDeadIndicesDo:[:idx | tally := tally - 1]
-            replacingCorpsesWith:nil.
-
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        self clearDeadSlots.
     ]
 
     "Created: 7.1.1997 / 16:59:30 / stefan"
-
-
 ! !
 
 !WeakValueDictionary methodsFor:'private'!
 
+clearDeadSlots
+    |wasBlocked|
+
+    "
+     have to block here - dispose may be done at a low priority
+     from the background finalizer. If new items are added by a 
+     higher prio process, the dictionary might get corrupted otherwise
+    "
+    wasBlocked := OperatingSystem blockInterrupts.
+
+    valueArray 
+        forAllDeadIndicesDo:[:idx | keyArray at:idx put:nil.
+                                    tally := tally - 1.
+                            ]
+        replacingCorpsesWith:nil.
+
+    wasBlocked ifFalse:[
+        OperatingSystem unblockInterrupts.
+    ].
+!
+
+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)'"
+
+    self clearDeadSlots.
+    ^super emptyCheck
+!
+
 valueContainerOfSize:n
     "return a container for values of size n.
      use WeakArrays here."
@@ -234,5 +253,5 @@
 !WeakValueDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/WeakValueDictionary.st,v 1.11 1999-07-07 18:41:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/WeakValueDictionary.st,v 1.12 2001-09-24 14:38:26 penk Exp $'
 ! !