WeakDepDict.st
changeset 2093 3a849047dc90
child 2101 516fedf50916
equal deleted inserted replaced
2092:054598f8f50e 2093:3a849047dc90
       
     1 "
       
     2  COPYRIGHT (c) 1997 by Claus Gittinger
       
     3               All Rights Reserved
       
     4 
       
     5  This software is furnished under a license and may be used
       
     6  only in accordance with the terms of that license and with the
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 
       
    14 WeakIdentityDictionary subclass:#WeakDependencyDictionary
       
    15 	instanceVariableNames:''
       
    16 	classVariableNames:''
       
    17 	poolDictionaries:''
       
    18 	category:'Collections-Unordered'
       
    19 !
       
    20 
       
    21 !WeakDependencyDictionary class methodsFor:'documentation'!
       
    22 
       
    23 copyright
       
    24 "
       
    25  COPYRIGHT (c) 1997 by Claus Gittinger
       
    26               All Rights Reserved
       
    27 
       
    28  This software is furnished under a license and may be used
       
    29  only in accordance with the terms of that license and with the
       
    30  inclusion of the above copyright notice.   This software may not
       
    31  be provided or otherwise made available to, or used by, any
       
    32  other person.  No title to or ownership of the software is
       
    33  hereby transferred.
       
    34 "
       
    35 
       
    36 !
       
    37 
       
    38 documentation
       
    39 "
       
    40     A specialized WeakIdentityDictionary, which 'knowns' how
       
    41     to get rid of obsolete entries. This is only used with the
       
    42     dependency mechanism.
       
    43 
       
    44     [author:]
       
    45         Claus Gittinger
       
    46 
       
    47     [See also:]
       
    48         WeakArray WeakIdentityDictionary WeakValueDictionary WeakIdentitySet
       
    49 "
       
    50 ! !
       
    51 
       
    52 !WeakDependencyDictionary methodsFor:'special dependency support'!
       
    53 
       
    54 removeEmptyDependencyValues
       
    55     "special entry for dependency management:
       
    56      remove any empty (due to finalization) value WeakArray elements."
       
    57 
       
    58     |index t wasBlocked val|
       
    59 
       
    60     "/ careful: this is sent by the finalizer at low prio.
       
    61     "/ be prepared for the receiver to change while we walk over
       
    62     "/ the value array here ...
       
    63 
       
    64     index := 1.
       
    65     [index <= keyArray size] whileTrue:[
       
    66         "/ get the size again - it could have changed
       
    67 
       
    68         wasBlocked := OperatingSystem blockInterrupts.
       
    69         index <= keyArray size ifTrue:[
       
    70             val := valueArray basicAt:index.
       
    71             val notNil ifTrue:[
       
    72                 "/ is it an empty WeakArray ?
       
    73 
       
    74                 (val isMemberOf:WeakArray) ifTrue:[
       
    75                     t := val findFirst:[:el | el notNil and:[el ~~ 0]].
       
    76                     t == 0 ifTrue:[
       
    77                         "/ yes - nil it
       
    78                         valueArray basicAt:index put:nil.
       
    79                         (keyArray basicAt:index) notNil ifTrue:[
       
    80                             keyArray basicAt:index put:DeletedEntry.
       
    81                             tally := tally - 1.
       
    82                         ]
       
    83                     ]
       
    84                 ] ifFalse:[
       
    85                    "/ is it an empty WeakIdSet ?
       
    86 
       
    87                    (val isMemberOf:WeakIdentitySet) ifTrue:[
       
    88                         val size == 0 ifTrue:[
       
    89                             "/ yes - nil it
       
    90                             valueArray basicAt:index put:nil.
       
    91                             (keyArray basicAt:index) notNil ifTrue:[
       
    92                                 keyArray basicAt:index put:DeletedEntry.
       
    93                                 tally := tally - 1.
       
    94                             ]
       
    95                         ].
       
    96                     ]
       
    97                 ]
       
    98             ]
       
    99         ].
       
   100 
       
   101         wasBlocked ifTrue:[OperatingSystem unblockInterrupts].
       
   102         index := index + 1.
       
   103     ].
       
   104 
       
   105     "
       
   106      Dependencies removeEmptyDependencyValues
       
   107     "
       
   108 
       
   109     "Modified: 8.1.1997 / 23:57:56 / cg"
       
   110     "Created: 9.1.1997 / 00:00:28 / cg"
       
   111 ! !
       
   112 
       
   113 !WeakDependencyDictionary class methodsFor:'documentation'!
       
   114 
       
   115 version
       
   116     ^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakDepDict.st,v 1.1 1997-01-08 23:06:22 cg Exp $'
       
   117 ! !