WeakDependencyDictionary.st
changeset 2297 118f794c4e42
parent 2279 ef0f7f5216c4
child 2299 fc326c7457b4
equal deleted inserted replaced
2296:97eb35d5ce43 2297:118f794c4e42
    47     [See also:]
    47     [See also:]
    48         WeakArray WeakIdentityDictionary WeakValueDictionary WeakIdentitySet
    48         WeakArray WeakIdentityDictionary WeakValueDictionary WeakIdentitySet
    49 "
    49 "
    50 ! !
    50 ! !
    51 
    51 
       
    52 !WeakDependencyDictionary methodsFor:'private'!
       
    53 
       
    54 keyContainerOfSize:n
       
    55     "return a container for keys of size n.
       
    56      use WeakArrays here."
       
    57 
       
    58     |w|
       
    59 
       
    60     w := WeakArray new:n.
       
    61     ^ w
       
    62 
       
    63     "Modified: 7.1.1997 / 17:01:15 / stefan"
       
    64 ! !
       
    65 
    52 !WeakDependencyDictionary methodsFor:'special dependency support'!
    66 !WeakDependencyDictionary methodsFor:'special dependency support'!
    53 
    67 
    54 removeEmptyDependencyValues
    68 removeEmptyDependencyValues
    55     "special entry for dependency management:
    69     "special entry for dependency management:
    56      remove any empty (due to finalization) value WeakArray elements."
    70      remove any empty (due to finalization) value WeakArray elements."
    57 
    71 
    58     |index t wasBlocked deps o|
    72     |index t wasBlocked deps o key b|
    59 
    73 
    60     "/ careful: this is sent by the finalizer at low prio.
    74     "/ careful: this is sent by the finalizer at low prio.
    61     "/ be prepared for the receiver to change while we walk over
    75     "/ be prepared for the receiver to change while we walk over
    62     "/ the value array here ...
    76     "/ the value array here ...
       
    77 
       
    78 "/ 'removeEmptyDependencyValues ...' printCR.
       
    79 
       
    80     b := [:el | el notNil and:[el ~~ 0]].
    63 
    81 
    64     index := 1.
    82     index := 1.
    65     [index <= keyArray size] whileTrue:[
    83     [index <= keyArray size] whileTrue:[
    66         "/ get the size again - it could have changed
    84         "/ get the size again - it could have changed
    67 
    85 
    68         wasBlocked := OperatingSystem blockInterrupts.
    86         wasBlocked := OperatingSystem blockInterrupts.
       
    87 
    69         index <= keyArray size ifTrue:[
    88         index <= keyArray size ifTrue:[
       
    89             key := keyArray basicAt:index.
       
    90             key == 0 ifTrue:[
       
    91                 key := nil.
       
    92             ].
       
    93 
    70             deps := valueArray basicAt:index.
    94             deps := valueArray basicAt:index.
    71             deps notNil ifTrue:[
    95             deps notNil ifTrue:[
    72                 "/ is it an empty WeakArray ?
    96                 "/ is it an empty WeakArray ?
    73 
    97 
    74                 (deps isMemberOf:WeakArray) ifTrue:[
    98                 (deps isMemberOf:WeakArray) ifTrue:[
    75                     t := deps findFirst:[:el | el notNil and:[el ~~ 0]].
    99                     t := deps findFirst:b.
    76                     t == 0 ifTrue:[
   100                     t == 0 ifTrue:[
    77                         "/ yes - nil it
   101                         "/ yes - nil it
    78                         valueArray basicAt:index put:nil.
   102                         valueArray basicAt:index put:nil.
    79                         (keyArray basicAt:index) notNil ifTrue:[
   103                         key notNil ifTrue:[
    80                             keyArray basicAt:index put:DeletedEntry.
   104                             keyArray basicAt:index put:DeletedEntry.
    81                             tally := tally - 1.
   105                             tally := tally - 1.
    82                         ]
   106                         ]
    83                     ]
   107                     ]
    84                 ] ifFalse:[
   108                 ] ifFalse:[
    86 
   110 
    87                    (deps isMemberOf:WeakIdentitySet) ifTrue:[
   111                    (deps isMemberOf:WeakIdentitySet) ifTrue:[
    88                         (t := deps size) == 0 ifTrue:[
   112                         (t := deps size) == 0 ifTrue:[
    89                             "/ yes - nil it
   113                             "/ yes - nil it
    90                             valueArray basicAt:index put:nil.
   114                             valueArray basicAt:index put:nil.
    91                             (keyArray basicAt:index) notNil ifTrue:[
   115                             key notNil ifTrue:[
    92                                 keyArray basicAt:index put:DeletedEntry.
   116                                 keyArray basicAt:index put:DeletedEntry.
    93                                 tally := tally - 1.
   117                                 tally := tally - 1.
    94                             ]
   118                             ]
    95                         ] ifFalse:[
   119 "/                        ] ifFalse:[
    96                             t == 1 ifTrue:[
   120 "/                            t == 1 ifTrue:[
    97                                 "/ careful - it could actually be empty
   121 "/                                "/ careful - it could actually be empty
    98                                 o := deps firstIfEmpty:nil.
   122 "/                                o := deps firstIfEmpty:nil.
    99                                 o notNil ifTrue:[
   123 "/                                o notNil ifTrue:[
   100                                     "/ the set lost an object, and shrunk to size 1
   124 "/                                    "/ the set lost an object, and shrunk to size 1
   101                                     "/ can now use a WeakArray
   125 "/                                    "/ can now use a WeakArray
   102                                     valueArray basicAt:index put:(WeakArray with:o)
   126 "/                                    valueArray basicAt:index put:(WeakArray with:o)
   103                                 ]
   127 "/                                ] ifFalse:[
   104                             ]
   128 "/                                    key notNil ifTrue:[
       
   129 "/                                        keyArray basicAt:index put:DeletedEntry.
       
   130 "/                                        tally := tally - 1.
       
   131 "/                                    ]
       
   132 "/                                ]
       
   133 "/                            ]
   105                         ]
   134                         ]
   106                     ]
   135                     ]
       
   136                 ]
       
   137             ] ifFalse:[
       
   138                 (key notNil and:[key ~~ DeletedEntry]) ifTrue:[
       
   139                     'oops:' print. key printCR.
       
   140                     keyArray basicAt:index put:DeletedEntry.
       
   141                     tally := tally - 1.
   107                 ]
   142                 ]
   108             ]
   143             ]
   109         ].
   144         ].
   110 
   145 
   111         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   146         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   112         index := index + 1.
   147         index := index + 1.
   113     ].
   148     ].
   114 
   149 
       
   150 "/ 'done' printCR.
   115     "
   151     "
   116      Dependencies removeEmptyDependencyValues
   152      Dependencies removeEmptyDependencyValues
   117     "
   153     "
   118 
   154 
   119     "Created: 9.1.1997 / 00:00:28 / cg"
   155     "Created: 9.1.1997 / 00:00:28 / cg"
   120     "Modified: 27.1.1997 / 15:54:28 / cg"
   156     "Modified: 29.1.1997 / 14:17:38 / cg"
   121 ! !
   157 ! !
   122 
   158 
   123 !WeakDependencyDictionary class methodsFor:'documentation'!
   159 !WeakDependencyDictionary class methodsFor:'documentation'!
   124 
   160 
   125 version
   161 version
   126     ^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.4 1997-01-27 14:55:16 cg Exp $'
   162     ^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.5 1997-01-29 13:17:43 cg Exp $'
   127 ! !
   163 ! !