author | Claus Gittinger <cg@exept.de> |
Wed, 07 Jul 1999 20:41:37 +0200 | |
changeset 4350 | 5aa2a3b9fd5b |
parent 2988 | c6550b3e9b3c |
child 4530 | 793b116fef3e |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
358 | 3 |
All Rights Reserved |
6 | 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 |
IdentityDictionary subclass:#WeakIdentityDictionary |
|
1054 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
4350 | 17 |
category:'Collections-Weak' |
6 | 18 |
! |
19 |
||
10 | 20 |
!WeakIdentityDictionary class methodsFor:'documentation'! |
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
358 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
10 | 36 |
documentation |
37 |
" |
|
1263 | 38 |
WeakIdentityDictionaries behave like IdentityDictionaries, |
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
39 |
as long as the keys are still referenced by some |
1263 | 40 |
other (non-weak) object. |
41 |
However, once the last non-weak reference ceases to exist, |
|
42 |
the object will be automatically removed from the Weakcollection |
|
43 |
(with some delay: it will be removed after the next garbage collect). |
|
44 |
||
45 |
This class was added to support keeping track of dependents without |
|
88 | 46 |
keeping the values alive - values simply become nil when no one else |
47 |
references it. The original dependency mechanism used a regular Dictionary, |
|
48 |
which usually leads to a lot of garbage being kept due to a forgotten |
|
49 |
release. Using a WeakDictionary may be incompatible to ST-80 but is much |
|
50 |
more comfortable, since no manual release of dependents is needed. |
|
1263 | 51 |
|
2306 | 52 |
[Warning:] |
53 |
If you use this, be very careful since the collections size changes |
|
54 |
'magically' - for example, testing for being nonEmpty and then |
|
55 |
removing the first element may fail, since the element may vanish inbetween. |
|
56 |
In general, never trust the value as returned by the size/isEmpty messages. |
|
2260 | 57 |
|
58 |
||
1290 | 59 |
[author:] |
2910 | 60 |
Claus Gittinger |
1290 | 61 |
|
1263 | 62 |
[See also:] |
2910 | 63 |
WeakArray WeakValueDictionary WeakIdentitySet |
10 | 64 |
" |
65 |
! ! |
|
66 |
||
359 | 67 |
!WeakIdentityDictionary methodsFor:'adding & removing'! |
68 |
||
2298 | 69 |
at:key |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
70 |
"redefined to block interrupts |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
71 |
(avoid change of the dictionary while accessing)" |
2298 | 72 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
73 |
|val| |
2298 | 74 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
75 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 76 |
"/ already blocked |
77 |
^ super at:key. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
78 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
79 |
|
2298 | 80 |
[ |
2910 | 81 |
val := super at:key. |
2298 | 82 |
] valueNowOrOnUnwindDo:[ |
2910 | 83 |
OperatingSystem unblockInterrupts. |
2298 | 84 |
]. |
85 |
^ val |
|
86 |
||
87 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
88 |
"Modified: 1.7.1997 / 10:45:42 / cg" |
2298 | 89 |
! |
90 |
||
91 |
at:key ifAbsent:exceptionBlock |
|
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
92 |
"redefined to block interrupts |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
93 |
(avoid change of the dictionary while accessing)" |
2298 | 94 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
95 |
|val| |
2298 | 96 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
97 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 98 |
"/ already blocked |
99 |
^ super at:key ifAbsent:exceptionBlock. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
100 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
101 |
|
2298 | 102 |
[ |
2910 | 103 |
val := super at:key ifAbsent:exceptionBlock. |
2298 | 104 |
] valueNowOrOnUnwindDo:[ |
2910 | 105 |
OperatingSystem unblockInterrupts. |
2298 | 106 |
]. |
107 |
^ val |
|
108 |
||
109 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
110 |
"Modified: 1.7.1997 / 10:45:47 / cg" |
2298 | 111 |
! |
112 |
||
1256 | 113 |
at:key put:anObject |
114 |
"add the argument anObject under key, aKey to the receiver. |
|
115 |
Return anObject (sigh). |
|
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
116 |
Redefined to block interrupts, to avoid trouble when dependencies |
1256 | 117 |
are added within interrupting high prio processes." |
118 |
||
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
119 |
|val| |
359 | 120 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
121 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 122 |
"/ already blocked |
123 |
^ super at:key put:anObject. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
124 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
125 |
|
1790 | 126 |
[ |
2910 | 127 |
val := super at:key put:anObject. |
1790 | 128 |
] valueNowOrOnUnwindDo:[ |
2910 | 129 |
OperatingSystem unblockInterrupts. |
1790 | 130 |
]. |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
131 |
^ val |
1223 | 132 |
|
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
133 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
134 |
"Modified: 29.1.1997 / 15:08:45 / cg" |
359 | 135 |
! |
136 |
||
137 |
removeKey:aKey ifAbsent:aBlock |
|
1256 | 138 |
"remove the association under aKey from the collection, |
2910 | 139 |
return the value previously stored there. |
1256 | 140 |
If it was not in the collection return the result |
141 |
from evaluating aBlock. |
|
142 |
||
143 |
Redefined to avoid synchronization problems, in case |
|
144 |
of interrupts (otherwise, there could be some other operation |
|
145 |
on the receiver done by another process, which garbles my contents)." |
|
1054 | 146 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
147 |
|ret| |
359 | 148 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
149 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 150 |
"/ already blocked |
151 |
^ super removeKey:aKey ifAbsent:aBlock. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
152 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
153 |
|
359 | 154 |
[ |
2910 | 155 |
ret := super removeKey:aKey ifAbsent:aBlock |
359 | 156 |
] valueNowOrOnUnwindDo:[ |
2910 | 157 |
OperatingSystem unblockInterrupts |
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
158 |
]. |
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
159 |
^ ret |
1054 | 160 |
|
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
161 |
"Modified: 6.5.1996 / 12:44:51 / stefan" |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
162 |
"Modified: 29.1.1997 / 15:09:11 / cg" |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
163 |
! |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
164 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
165 |
saveRemoveKey:key |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
166 |
"redefined to block interrupts |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
167 |
(avoid change of the dictionary while accessing)" |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
168 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
169 |
|val| |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
170 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
171 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 172 |
"/ already blocked |
173 |
^ super saveRemoveKey:key. |
|
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
174 |
]. |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
175 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
176 |
[ |
2910 | 177 |
val := super saveRemoveKey:key. |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
178 |
] valueNowOrOnUnwindDo:[ |
2910 | 179 |
OperatingSystem unblockInterrupts. |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
180 |
]. |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
181 |
^ val |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
182 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
183 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
184 |
"Modified: 1.7.1997 / 10:45:52 / cg" |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
185 |
"Created: 1.7.1997 / 10:46:34 / cg" |
359 | 186 |
! ! |
187 |
||
10 | 188 |
!WeakIdentityDictionary methodsFor:'element disposal'! |
189 |
||
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
190 |
update:something with:aParameter from:changedObject |
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
191 |
"an element (either key or value) died - clear out slots for |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
192 |
disposed keys." |
6 | 193 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
194 |
|wasBlocked| |
358 | 195 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
196 |
something == #ElementExpired ifTrue:[ |
2910 | 197 |
" |
198 |
have to block here - dispose may be done at a low priority |
|
199 |
from the background finalizer. If new items are added by a |
|
200 |
higher prio process, the dictionary might get corrupted otherwise |
|
201 |
" |
|
202 |
wasBlocked := OperatingSystem blockInterrupts. |
|
10 | 203 |
|
2910 | 204 |
keyArray |
205 |
forAllDeadIndicesDo:[:idx | |
|
206 |
valueArray basicAt:idx put:nil. |
|
207 |
tally := tally - 1. |
|
208 |
] |
|
209 |
replacingCorpsesWith:DeletedEntry. |
|
358 | 210 |
|
2910 | 211 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
212 |
] |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
213 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
214 |
"Created: 7.1.1997 / 16:59:30 / stefan" |
6 | 215 |
! ! |
609 | 216 |
|
217 |
!WeakIdentityDictionary methodsFor:'private'! |
|
218 |
||
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
219 |
findKeyOrNil:key |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
220 |
"Look for the key in the receiver. |
2988 | 221 |
If it is found, return the index, |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
222 |
otherwise the index of the first unused slot. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
223 |
Grow the receiver, if key was not found, and no unused slots were present. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
224 |
|
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
225 |
Warning: an empty slot MUST be filled by the sender - it is only to be sent |
2988 | 226 |
by at:put: / add: - like methods." |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
227 |
|
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
228 |
|index "{ Class:SmallInteger }" |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
229 |
length "{ Class:SmallInteger }" |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
230 |
startIndex probe |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
231 |
delIndex "{ Class:SmallInteger }"| |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
232 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
233 |
(OperatingSystem blockInterrupts) ifFalse:[ |
2988 | 234 |
"/ |
235 |
"/ may never be entered with interrupts enabled |
|
236 |
"/ |
|
237 |
OperatingSystem unblockInterrupts. |
|
238 |
self error:'oops - unblocked call of findKeyOrNil'. |
|
239 |
^ nil "/ leads to another error, if proceeded |
|
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
240 |
]. |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
241 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
242 |
delIndex := 0. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
243 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
244 |
length := keyArray basicSize. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
245 |
index := key identityHash. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
246 |
index < 16r1FFFFFFF ifTrue:[ |
2988 | 247 |
index := index * 2 |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
248 |
]. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
249 |
index := index \\ length + 1. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
250 |
startIndex := index. |
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
251 |
|
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
252 |
[true] whileTrue:[ |
2988 | 253 |
probe := keyArray basicAt:index. |
254 |
key == probe ifTrue:[^ index]. |
|
255 |
probe isNil ifTrue:[ |
|
256 |
delIndex == 0 ifTrue:[^ index]. |
|
257 |
keyArray basicAt:delIndex put:nil. |
|
258 |
^ delIndex |
|
259 |
]. |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
260 |
|
2988 | 261 |
probe == 0 ifTrue:[ |
262 |
probe := DeletedEntry. |
|
263 |
keyArray basicAt:index put:probe. |
|
264 |
valueArray basicAt:index put:nil. |
|
265 |
tally := tally - 1. |
|
266 |
]. |
|
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
267 |
|
2988 | 268 |
delIndex == 0 ifTrue:[ |
269 |
probe == DeletedEntry ifTrue:[ |
|
270 |
delIndex := index |
|
271 |
] |
|
272 |
]. |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
273 |
|
2988 | 274 |
index == length ifTrue:[ |
275 |
index := 1 |
|
276 |
] ifFalse:[ |
|
277 |
index := index + 1 |
|
278 |
]. |
|
279 |
index == startIndex ifTrue:[ |
|
280 |
delIndex ~~ 0 ifTrue:[ |
|
281 |
keyArray basicAt:delIndex put:nil. |
|
282 |
^ delIndex |
|
283 |
]. |
|
284 |
^ self grow findKeyOrNil:key |
|
285 |
]. |
|
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
286 |
] |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
287 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
288 |
"Modified: 30.1.1997 / 15:04:34 / cg" |
2988 | 289 |
"Modified: 1.10.1997 / 11:25:32 / stefan" |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
290 |
! |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
291 |
|
2298 | 292 |
grow:newSize |
293 |
"grow the receiver. |
|
294 |
Redefined to block interrupts, to avoid trouble when dependencies |
|
295 |
are added within interrupting high prio processes." |
|
296 |
||
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
297 |
"/ 'grow:' printCR. |
2298 | 298 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
299 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 300 |
"/ already blocked |
301 |
^ super grow:newSize. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
302 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
303 |
|
2298 | 304 |
[ |
2910 | 305 |
super grow:newSize |
2298 | 306 |
] valueNowOrOnUnwindDo:[ |
2910 | 307 |
OperatingSystem unblockInterrupts |
2298 | 308 |
]. |
309 |
||
310 |
"Created: 28.1.1997 / 23:41:39 / cg" |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
311 |
"Modified: 29.1.1997 / 15:10:12 / cg" |
2298 | 312 |
! |
313 |
||
609 | 314 |
keyContainerOfSize:n |
315 |
"return a container for keys of size n. |
|
2298 | 316 |
use WeakArrays here, but dont make me a depenent of it." |
609 | 317 |
|
318 |
|w| |
|
319 |
||
320 |
w := WeakArray new:n. |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
321 |
w addDependent:self. |
609 | 322 |
^ w |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
323 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
324 |
"Modified: 7.1.1997 / 17:01:15 / stefan" |
2298 | 325 |
"Modified: 29.1.1997 / 14:18:49 / cg" |
326 |
! |
|
327 |
||
328 |
rehash |
|
329 |
"grow the receiver. |
|
330 |
Redefined to block interrupts, to avoid trouble when dependencies |
|
331 |
are added within interrupting high prio processes." |
|
332 |
||
333 |
"/ 'rehash' printCR. |
|
334 |
||
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
335 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 336 |
"/ already blocked |
337 |
^ super rehash. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
338 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
339 |
|
2298 | 340 |
[ |
2910 | 341 |
super rehash |
2298 | 342 |
] valueNowOrOnUnwindDo:[ |
2910 | 343 |
OperatingSystem unblockInterrupts |
2298 | 344 |
]. |
345 |
||
346 |
"Created: 29.1.1997 / 11:39:42 / cg" |
|
347 |
"Modified: 29.1.1997 / 14:18:52 / cg" |
|
348 |
! |
|
349 |
||
350 |
setTally:count |
|
351 |
"grow the receiver. |
|
352 |
Redefined to block interrupts, to avoid trouble when dependencies |
|
353 |
are added within interrupting high prio processes." |
|
354 |
||
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
355 |
"/ 'setTally:' printCR. |
2298 | 356 |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
357 |
(OperatingSystem blockInterrupts) ifTrue:[ |
2910 | 358 |
"/ already blocked |
359 |
^ super setTally:count. |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
360 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
361 |
|
2298 | 362 |
[ |
2910 | 363 |
super setTally:count |
2298 | 364 |
] valueNowOrOnUnwindDo:[ |
2910 | 365 |
OperatingSystem unblockInterrupts |
2298 | 366 |
]. |
367 |
||
368 |
"Created: 29.1.1997 / 11:40:12 / cg" |
|
2303
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
369 |
"Modified: 29.1.1997 / 15:11:11 / cg" |
609 | 370 |
! ! |
371 |
||
2741 | 372 |
!WeakIdentityDictionary methodsFor:'testing'! |
373 |
||
374 |
includes:anObject |
|
375 |
"redefined to block interrupts |
|
376 |
(avoid change of the dictionary while accessing)" |
|
377 |
||
378 |
|val| |
|
379 |
||
380 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
2910 | 381 |
"/ already blocked |
382 |
^ super includes:anObject. |
|
2741 | 383 |
]. |
384 |
||
385 |
[ |
|
2910 | 386 |
val := super includes:anObject. |
2741 | 387 |
] valueNowOrOnUnwindDo:[ |
2910 | 388 |
OperatingSystem unblockInterrupts. |
2741 | 389 |
]. |
390 |
^ val |
|
391 |
||
392 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
393 |
"Modified: 1.7.1997 / 10:45:52 / cg" |
|
394 |
"Created: 1.7.1997 / 10:47:13 / cg" |
|
395 |
! |
|
396 |
||
397 |
includesKey:key |
|
398 |
"redefined to block interrupts |
|
399 |
(avoid change of the dictionary while accessing)" |
|
400 |
||
401 |
|val| |
|
402 |
||
403 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
2910 | 404 |
"/ already blocked |
405 |
^ super includesKey:key. |
|
2741 | 406 |
]. |
407 |
||
408 |
[ |
|
2910 | 409 |
val := super includesKey:key. |
2741 | 410 |
] valueNowOrOnUnwindDo:[ |
2910 | 411 |
OperatingSystem unblockInterrupts. |
2741 | 412 |
]. |
413 |
^ val |
|
414 |
||
415 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
416 |
"Created: 1.7.1997 / 10:45:14 / cg" |
|
417 |
"Modified: 1.7.1997 / 10:45:52 / cg" |
|
418 |
! ! |
|
419 |
||
635 | 420 |
!WeakIdentityDictionary class methodsFor:'documentation'! |
421 |
||
422 |
version |
|
4350 | 423 |
^ '$Header: /cvs/stx/stx/libbasic/WeakIdentityDictionary.st,v 1.34 1999-07-07 18:41:04 cg Exp $' |
635 | 424 |
! ! |