author | Claus Gittinger <cg@exept.de> |
Wed, 29 Jan 1997 22:11:16 +0100 | |
changeset 2316 | 6b24c092456a |
parent 2300 | 789e1dd0a0b7 |
child 2508 | 32924c15a4cd |
permissions | -rw-r--r-- |
2093 | 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 |
||
2297 | 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 |
||
2093 | 66 |
!WeakDependencyDictionary methodsFor:'special dependency support'! |
67 |
||
68 |
removeEmptyDependencyValues |
|
69 |
"special entry for dependency management: |
|
70 |
remove any empty (due to finalization) value WeakArray elements." |
|
71 |
||
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
72 |
|index t wasBlocked deps o key b originalKeyArray| |
2093 | 73 |
|
74 |
"/ careful: this is sent by the finalizer at low prio. |
|
75 |
"/ be prepared for the receiver to change while we walk over |
|
76 |
"/ the value array here ... |
|
77 |
||
2297 | 78 |
"/ 'removeEmptyDependencyValues ...' printCR. |
79 |
||
80 |
b := [:el | el notNil and:[el ~~ 0]]. |
|
81 |
||
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
82 |
originalKeyArray := keyArray. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
83 |
|
2093 | 84 |
index := 1. |
85 |
[index <= keyArray size] whileTrue:[ |
|
86 |
"/ get the size again - it could have changed |
|
87 |
||
88 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2297 | 89 |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
90 |
keyArray ~~ originalKeyArray ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
91 |
index := 1. "/ start over |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
92 |
'restart removeEmpty' printCR. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
93 |
originalKeyArray := keyArray. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
94 |
]. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
95 |
|
2093 | 96 |
index <= keyArray size ifTrue:[ |
2297 | 97 |
key := keyArray basicAt:index. |
98 |
key == 0 ifTrue:[ |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
99 |
"/ that one is gone |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
100 |
key := DeletedEntry. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
101 |
keyArray basicAt:index put:key. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
102 |
valueArray basicAt:index put:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
103 |
tally := tally - 1. |
2297 | 104 |
]. |
105 |
||
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
106 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
107 |
deps := valueArray basicAt:index. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
108 |
deps notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
109 |
"/ is it an empty WeakArray ? |
2093 | 110 |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
111 |
(deps isMemberOf:WeakArray) ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
112 |
t := deps findFirst:b. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
113 |
t == 0 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
114 |
"/ yes - nil it |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
115 |
valueArray basicAt:index put:nil. |
2093 | 116 |
keyArray basicAt:index put:DeletedEntry. |
117 |
tally := tally - 1. |
|
118 |
] |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
119 |
] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
120 |
"/ is it an empty WeakIdSet ? |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
121 |
|
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
122 |
(deps isMemberOf:WeakIdentitySet) ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
123 |
(t := deps size) == 0 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
124 |
"/ yes - nil it |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
125 |
valueArray basicAt:index put:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
126 |
keyArray basicAt:index put:DeletedEntry. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
127 |
tally := tally - 1. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
128 |
"/ ] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
129 |
"/ t == 1 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
130 |
"/ "/ careful - it could actually be empty |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
131 |
"/ o := deps firstIfEmpty:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
132 |
"/ o notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
133 |
"/ "/ the set lost an object, and shrunk to size 1 |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
134 |
"/ "/ can now use a WeakArray |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
135 |
"/ valueArray basicAt:index put:(WeakArray with:o) |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
136 |
"/ ] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
137 |
"/ key notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
138 |
"/ keyArray basicAt:index put:DeletedEntry. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
139 |
"/ tally := tally - 1. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
140 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
141 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
142 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
143 |
] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
144 |
] |
2093 | 145 |
] |
146 |
] ifFalse:[ |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
147 |
'oops: nil value for key' print. key printCR. |
2297 | 148 |
keyArray basicAt:index put:DeletedEntry. |
149 |
tally := tally - 1. |
|
150 |
] |
|
2093 | 151 |
] |
152 |
]. |
|
153 |
||
2279
ef0f7f5216c4
oops - irqBlockingstate was corrupted
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
154 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2093 | 155 |
index := index + 1. |
156 |
]. |
|
157 |
||
2297 | 158 |
"/ 'done' printCR. |
2093 | 159 |
" |
160 |
Dependencies removeEmptyDependencyValues |
|
161 |
" |
|
162 |
||
163 |
"Created: 9.1.1997 / 00:00:28 / cg" |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
164 |
"Modified: 29.1.1997 / 22:02:33 / cg" |
2299 | 165 |
! ! |
166 |
||
2093 | 167 |
!WeakDependencyDictionary class methodsFor:'documentation'! |
168 |
||
169 |
version |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
170 |
^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.8 1997-01-29 21:11:16 cg Exp $' |
2093 | 171 |
! ! |