author | Jan Vrany <jan.vrany@labware.com> |
Wed, 22 Mar 2023 13:57:18 +0000 | |
branch | jv |
changeset 25445 | 1623217d2268 |
parent 23107 | 40173e082cbc |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
23107 | 3 |
COPYRIGHT (c) 2017 Jan Vrany |
358 | 4 |
All Rights Reserved |
6 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
6233 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
18333
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
15 |
"{ NameSpace: Smalltalk }" |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
16 |
|
6 | 17 |
IdentityDictionary subclass:#WeakIdentityDictionary |
1054 | 18 |
instanceVariableNames:'' |
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
4350 | 21 |
category:'Collections-Weak' |
6 | 22 |
! |
23 |
||
10 | 24 |
!WeakIdentityDictionary class methodsFor:'documentation'! |
25 |
||
88 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
23107 | 29 |
COPYRIGHT (c) 2017 Jan Vrany |
358 | 30 |
All Rights Reserved |
88 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
10 | 41 |
documentation |
42 |
" |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
43 |
WeakIdentityDictionaries behave like IdentityDictionaries, |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
44 |
as long as the keys are still referenced by some |
1263 | 45 |
other (non-weak) object. |
46 |
However, once the last non-weak reference ceases to exist, |
|
47 |
the object will be automatically removed from the Weakcollection |
|
48 |
(with some delay: it will be removed after the next garbage collect). |
|
49 |
||
50 |
This class was added to support keeping track of dependents without |
|
88 | 51 |
keeping the values alive - values simply become nil when no one else |
52 |
references it. The original dependency mechanism used a regular Dictionary, |
|
53 |
which usually leads to a lot of garbage being kept due to a forgotten |
|
54 |
release. Using a WeakDictionary may be incompatible to ST-80 but is much |
|
55 |
more comfortable, since no manual release of dependents is needed. |
|
1263 | 56 |
|
2306 | 57 |
[Warning:] |
58 |
If you use this, be very careful since the collections size changes |
|
59 |
'magically' - for example, testing for being nonEmpty and then |
|
60 |
removing the first element may fail, since the element may vanish inbetween. |
|
61 |
In general, never trust the value as returned by the size/isEmpty messages. |
|
2260 | 62 |
|
63 |
||
1290 | 64 |
[author:] |
2910 | 65 |
Claus Gittinger |
1290 | 66 |
|
1263 | 67 |
[See also:] |
2910 | 68 |
WeakArray WeakValueDictionary WeakIdentitySet |
10 | 69 |
" |
70 |
! ! |
|
71 |
||
21006 | 72 |
!WeakIdentityDictionary methodsFor:'accessing'! |
20990 | 73 |
|
74 |
keys |
|
75 |
"return a collection containing all valid keys of the receiver" |
|
76 |
||
77 |
|keySet| |
|
78 |
||
79 |
keySet := self emptyCollectionForKeys. |
|
80 |
keyArray validElementsDo:[:key | |
|
81 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
|
82 |
key == NilEntry ifTrue:[ |
|
83 |
keySet add:nil. |
|
84 |
] ifFalse:[ |
|
85 |
keySet add:key. |
|
86 |
] |
|
87 |
] |
|
88 |
]. |
|
89 |
^ keySet |
|
90 |
! ! |
|
91 |
||
359 | 92 |
!WeakIdentityDictionary methodsFor:'adding & removing'! |
93 |
||
2298 | 94 |
at:key ifAbsent:exceptionBlock |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
95 |
"redefined to block interrupts |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
96 |
(avoid change of the dictionary while accessing)" |
2298 | 97 |
|
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
|
98 |
|val| |
2298 | 99 |
|
20166 | 100 |
key class == SmallInteger ifTrue:[ |
101 |
"SmallIntegers cannot be stored into a WeakArray" |
|
102 |
^ exceptionBlock value. |
|
103 |
]. |
|
104 |
||
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
|
105 |
(OperatingSystem blockInterrupts) ifTrue:[ |
20166 | 106 |
"/ already blocked |
107 |
^ 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
|
108 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
109 |
|
2298 | 110 |
[ |
20166 | 111 |
val := super at:key ifAbsent:exceptionBlock. |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
112 |
] ensure:[ |
20166 | 113 |
OperatingSystem unblockInterrupts. |
2298 | 114 |
]. |
115 |
^ val |
|
116 |
||
117 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
118 |
"Modified: 1.7.1997 / 10:45:47 / cg" |
2298 | 119 |
! |
120 |
||
19193 | 121 |
at:key ifAbsentPut:replacementBlock |
122 |
"redefined to block interrupts |
|
123 |
(avoid change of the dictionary while accessing)" |
|
124 |
||
125 |
|val| |
|
126 |
||
20166 | 127 |
key class == SmallInteger ifTrue:[ |
128 |
"SmallIntegers cannot be stored into a WeakArray" |
|
129 |
self error:'WeakidentityDictionary: cannot store a SmallInteger'. |
|
130 |
]. |
|
131 |
||
19193 | 132 |
(OperatingSystem blockInterrupts) ifTrue:[ |
133 |
"/ already blocked |
|
134 |
^ super at:key ifAbsentPut:replacementBlock. |
|
135 |
]. |
|
136 |
||
137 |
[ |
|
138 |
val := super at:key ifAbsentPut:replacementBlock. |
|
139 |
] ensure:[ |
|
140 |
OperatingSystem unblockInterrupts. |
|
141 |
]. |
|
142 |
^ val |
|
143 |
! |
|
144 |
||
1256 | 145 |
at:key put:anObject |
146 |
"add the argument anObject under key, aKey to the receiver. |
|
147 |
Return anObject (sigh). |
|
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
148 |
Redefined to block interrupts, to avoid trouble when dependencies |
1256 | 149 |
are added within interrupting high prio processes." |
150 |
||
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
|
151 |
|val| |
359 | 152 |
|
20166 | 153 |
key class == SmallInteger ifTrue:[ |
154 |
"SmallIntegers cannot be stored into a WeakArray" |
|
155 |
self error:'WeakidentityDictionary: cannot store a SmallInteger'. |
|
156 |
]. |
|
157 |
||
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
|
158 |
(OperatingSystem blockInterrupts) ifTrue:[ |
20166 | 159 |
"/ already blocked |
160 |
^ 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
|
161 |
]. |
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 |
|
1790 | 163 |
[ |
20166 | 164 |
val := super at:key put:anObject. |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
165 |
] ensure:[ |
20166 | 166 |
OperatingSystem unblockInterrupts. |
1790 | 167 |
]. |
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
|
168 |
^ val |
1223 | 169 |
|
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
170 |
"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
|
171 |
"Modified: 29.1.1997 / 15:08:45 / cg" |
359 | 172 |
! |
173 |
||
174 |
removeKey:aKey ifAbsent:aBlock |
|
1256 | 175 |
"remove the association under aKey from the collection, |
2910 | 176 |
return the value previously stored there. |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
177 |
If it was not in the collection return the result |
1256 | 178 |
from evaluating aBlock. |
179 |
||
180 |
Redefined to avoid synchronization problems, in case |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
181 |
of interrupts (otherwise, there could be some other operation |
1256 | 182 |
on the receiver done by another process, which garbles my contents)." |
1054 | 183 |
|
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
|
184 |
|ret| |
359 | 185 |
|
20166 | 186 |
aKey class == SmallInteger ifTrue:[ |
187 |
"SmallIntegers cannot be stored into a WeakArray" |
|
188 |
^ aBlock value. |
|
189 |
]. |
|
190 |
||
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 |
(OperatingSystem blockInterrupts) ifTrue:[ |
20166 | 192 |
"/ already blocked |
193 |
^ 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
|
194 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
195 |
|
359 | 196 |
[ |
20166 | 197 |
ret := super removeKey:aKey ifAbsent:aBlock |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
198 |
] ensure:[ |
20166 | 199 |
OperatingSystem unblockInterrupts |
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
200 |
]. |
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
201 |
^ ret |
1054 | 202 |
|
1343
b0ee705c63e0
Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents:
1290
diff
changeset
|
203 |
"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
|
204 |
"Modified: 29.1.1997 / 15:09:11 / cg" |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
205 |
! |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
206 |
|
16513 | 207 |
safeRemoveKey:key |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
208 |
"redefined to block interrupts |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
209 |
(avoid change of the dictionary while accessing)" |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
210 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
211 |
|val| |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
212 |
|
20166 | 213 |
key class == SmallInteger ifTrue:[ |
214 |
"SmallIntegers cannot be stored into a WeakArray" |
|
215 |
^ nil. |
|
216 |
]. |
|
217 |
||
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
218 |
(OperatingSystem blockInterrupts) ifTrue:[ |
20166 | 219 |
"/ already blocked |
220 |
^ super safeRemoveKey:key. |
|
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
221 |
]. |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
222 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
223 |
[ |
20166 | 224 |
val := super safeRemoveKey:key. |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
225 |
] ensure:[ |
20166 | 226 |
OperatingSystem unblockInterrupts. |
2738
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
227 |
]. |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
228 |
^ val |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
229 |
|
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
230 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
231 |
"Modified: 1.7.1997 / 10:45:52 / cg" |
2546e06df154
more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents:
2329
diff
changeset
|
232 |
"Created: 1.7.1997 / 10:46:34 / cg" |
359 | 233 |
! ! |
234 |
||
10 | 235 |
!WeakIdentityDictionary methodsFor:'element disposal'! |
236 |
||
6309 | 237 |
clearDeadSlots |
20702 | 238 |
|wasBlocked anyChange| |
6309 | 239 |
|
240 |
" |
|
241 |
have to block here - dispose may be done at a low priority |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
242 |
from the background finalizer. If new items are added by a |
6309 | 243 |
higher prio process, the dictionary might get corrupted otherwise |
244 |
" |
|
245 |
wasBlocked := OperatingSystem blockInterrupts. |
|
20702 | 246 |
anyChange := false. |
6469 | 247 |
[ |
20702 | 248 |
keyArray |
249 |
forAllDeadIndicesDo:[:idx | |
|
250 |
valueArray basicAt:idx put:nil. |
|
251 |
tally := tally - 1. |
|
252 |
anyChange := true. |
|
253 |
] |
|
254 |
replacingCorpsesWith:DeletedEntry. |
|
6469 | 255 |
] ensure:[ |
20702 | 256 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6469 | 257 |
]. |
20702 | 258 |
anyChange ifTrue:[ |
259 |
self changed:#ElementExpired |
|
260 |
]. |
|
6309 | 261 |
|
262 |
"Modified: / 13.12.2001 / 14:18:17 / martin" |
|
263 |
! |
|
264 |
||
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
265 |
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
|
266 |
"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
|
267 |
disposed keys." |
6 | 268 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
269 |
something == #ElementExpired ifTrue:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
270 |
self clearDeadSlots. |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
271 |
] |
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
272 |
|
6309 | 273 |
"Created: / 7.1.1997 / 16:59:30 / stefan" |
274 |
"Modified: / 13.12.2001 / 14:17:58 / martin" |
|
6 | 275 |
! ! |
609 | 276 |
|
20992 | 277 |
!WeakIdentityDictionary methodsFor:'enumerating'! |
278 |
||
279 |
keysDo:aBlock |
|
280 |
"evaluate aBlock for each registered object" |
|
281 |
||
282 |
"#Dictionary>>keysDo: would not work, since the keyArray instvar may change if |
|
283 |
elements are unregistered while looping." |
|
284 |
||
285 |
^ keyArray validElementsDo:[:each| |
|
286 |
each ~~ DeletedEntry ifTrue:[ |
|
287 |
each == NilEntry ifTrue:[ |
|
288 |
aBlock value:nil. |
|
289 |
] ifFalse:[ |
|
290 |
aBlock value:each. |
|
291 |
] |
|
292 |
]. |
|
293 |
] |
|
294 |
! ! |
|
295 |
||
609 | 296 |
!WeakIdentityDictionary methodsFor:'private'! |
297 |
||
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
298 |
findKeyOrNil:key |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
299 |
"Look for the key in the receiver. |
2988 | 300 |
If it is found, return the index, |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
301 |
otherwise the index of the first unused slot. |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
302 |
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
|
303 |
|
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
304 |
Warning: an empty slot MUST be filled by the sender - it is only to be sent |
20037 | 305 |
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
|
306 |
|
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
307 |
|index "{ Class:SmallInteger }" |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
308 |
length "{ Class:SmallInteger }" |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
309 |
startIndex probe |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
310 |
delIndex "{ Class:SmallInteger }"| |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
311 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
312 |
(OperatingSystem blockInterrupts) ifFalse:[ |
20037 | 313 |
"/ |
314 |
"/ may never be entered with interrupts enabled |
|
315 |
"/ |
|
316 |
OperatingSystem unblockInterrupts. |
|
317 |
self error:'unblocked call of findKeyOrNil'. |
|
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
318 |
]. |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
319 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
320 |
delIndex := 0. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
321 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
322 |
length := keyArray basicSize. |
6953
6b3a197638f0
invoke hash/idHash only in one place (initialIndexFor..)
Claus Gittinger <cg@exept.de>
parents:
6469
diff
changeset
|
323 |
startIndex := index := self initialIndexForKey:key. |
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
324 |
|
16244 | 325 |
[ |
20037 | 326 |
probe := keyArray basicAt:index. |
327 |
key == probe ifTrue:[^ index]. |
|
328 |
probe isNil ifTrue:[ |
|
329 |
delIndex == 0 ifTrue:[^ index]. |
|
330 |
keyArray basicAt:delIndex put:nil. |
|
331 |
^ delIndex |
|
332 |
]. |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
333 |
|
20037 | 334 |
probe class == SmallInteger ifTrue:[ |
335 |
probe := DeletedEntry. |
|
336 |
keyArray basicAt:index put:probe. |
|
337 |
valueArray basicAt:index put:nil. |
|
338 |
tally := tally - 1. |
|
339 |
]. |
|
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
340 |
|
20037 | 341 |
(delIndex == 0 and:[probe == DeletedEntry]) ifTrue:[ |
342 |
delIndex := index |
|
343 |
]. |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
344 |
|
20037 | 345 |
index == length ifTrue:[ |
346 |
index := 1 |
|
347 |
] ifFalse:[ |
|
348 |
index := index + 1 |
|
349 |
]. |
|
350 |
index == startIndex ifTrue:[ |
|
351 |
delIndex ~~ 0 ifTrue:[ |
|
352 |
keyArray basicAt:delIndex put:nil. |
|
353 |
^ delIndex |
|
354 |
]. |
|
355 |
self grow. |
|
356 |
length := keyArray basicSize. |
|
357 |
startIndex := index := self initialIndexForKey:key. |
|
358 |
]. |
|
16244 | 359 |
] loop. |
2315
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
360 |
|
2329
937fc97d5544
must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
361 |
"Modified: 30.1.1997 / 15:04:34 / cg" |
2988 | 362 |
"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
|
363 |
! |
a9ff2fda8bae
mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents:
2306
diff
changeset
|
364 |
|
20237 | 365 |
findKeyOrNilOrDeletedEntry:key |
366 |
"Look for the key in the receiver. |
|
367 |
If it is found, return the index, |
|
368 |
otherwise the index of the first unused slot. |
|
369 |
Grow the receiver, if key was not found, and no unused slots were present." |
|
370 |
||
371 |
|index "{ Class:SmallInteger }" |
|
372 |
length "{ Class:SmallInteger }" |
|
373 |
startIndex probe |
|
374 |
delIndex "{ Class:SmallInteger }"| |
|
375 |
||
376 |
(OperatingSystem blockInterrupts) ifFalse:[ |
|
377 |
"/ |
|
378 |
"/ may never be entered with interrupts enabled |
|
379 |
"/ |
|
380 |
OperatingSystem unblockInterrupts. |
|
381 |
self error:'unblocked call of findKeyOrNil'. |
|
382 |
]. |
|
383 |
||
384 |
delIndex := 0. |
|
385 |
||
386 |
length := keyArray basicSize. |
|
387 |
startIndex := index := self initialIndexForKey:key. |
|
388 |
||
389 |
[ |
|
390 |
probe := keyArray basicAt:index. |
|
391 |
key == probe ifTrue:[^ index]. |
|
392 |
probe isNil ifTrue:[ |
|
393 |
delIndex == 0 ifTrue:[^ index]. |
|
394 |
^ delIndex |
|
395 |
]. |
|
396 |
||
397 |
probe class == SmallInteger ifTrue:[ |
|
398 |
probe := DeletedEntry. |
|
399 |
keyArray basicAt:index put:probe. |
|
400 |
valueArray basicAt:index put:nil. |
|
401 |
tally := tally - 1. |
|
402 |
]. |
|
403 |
||
404 |
(delIndex == 0 and:[probe == DeletedEntry]) ifTrue:[ |
|
405 |
delIndex := index |
|
406 |
]. |
|
407 |
||
408 |
index == length ifTrue:[ |
|
409 |
index := 1 |
|
410 |
] ifFalse:[ |
|
411 |
index := index + 1 |
|
412 |
]. |
|
413 |
index == startIndex ifTrue:[ |
|
414 |
delIndex ~~ 0 ifTrue:[ |
|
415 |
^ delIndex |
|
416 |
]. |
|
417 |
self grow. |
|
418 |
length := keyArray basicSize. |
|
419 |
startIndex := index := self initialIndexForKey:key. |
|
420 |
]. |
|
421 |
] loop. |
|
422 |
||
423 |
"Modified: 30.1.1997 / 15:04:34 / cg" |
|
424 |
"Modified: 1.10.1997 / 11:25:32 / stefan" |
|
425 |
! |
|
426 |
||
2298 | 427 |
grow:newSize |
22129
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
428 |
"Grow the receiver to make space for at least newSize elements. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
429 |
To do this, we have to rehash into the new arrays. (which is done |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
430 |
by re-adding all elements to a new, empty key/value array pair). |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
431 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
432 |
Redefined here to avoid higher-prio process to modify the receiver while |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
433 |
grwoing and to handle corpses. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
434 |
" |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
435 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
436 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
437 |
| key deletedEntry oldKeyArray oldValueArray n |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
438 |
oldSize "{ Class:SmallInteger }" |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
439 |
newIndex "{ Class:SmallInteger }" |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
440 |
wasBlocked |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
441 |
anyDead | |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
442 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
443 |
oldKeyArray := keyArray. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
444 |
oldValueArray := valueArray. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
445 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
446 |
n := self class goodSizeFrom:newSize. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
447 |
oldSize := oldKeyArray size. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
448 |
n == oldSize ifTrue:[^ self]. |
2298 | 449 |
|
22129
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
450 |
keyArray := self keyContainerOfSize:n. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
451 |
valueArray := self valueContainerOfSize:n. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
452 |
|
2298 | 453 |
|
22129
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
454 |
deletedEntry := DeletedEntry. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
455 |
anyDead := false. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
456 |
wasBlocked := OperatingSystem blockInterrupts. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
457 |
1 to:oldSize do:[:index | |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
458 |
key := oldKeyArray basicAt:index. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
459 |
(key notNil and:[key ~~ deletedEntry]) ifTrue:[ |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
460 |
key class == SmallInteger ifTrue:[ |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
461 |
"/ Oops, we found a corpse, make a note |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
462 |
"/ and continue. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
463 |
anyDead := true. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
464 |
] ifFalse:[ |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
465 |
newIndex := self findNil:key. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
466 |
keyArray basicAt:newIndex put:key. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
467 |
valueArray basicAt:newIndex put:(oldValueArray basicAt:index). |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
468 |
]. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
469 |
] |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
470 |
]. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
471 |
wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ]. |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
472 |
anyDead ifTrue:[ |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
473 |
self changed:#ElementExpired |
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
|
474 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
475 |
|
22129
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
476 |
"Created: / 28-01-1997 / 23:41:39 / cg" |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
477 |
"Modified: / 29-01-1997 / 15:10:12 / cg" |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
478 |
"Modified: / 31-07-2017 / 09:16:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2298 | 479 |
! |
480 |
||
18333
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
481 |
initializeForCapacity:minSize |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
482 |
"reset the receiver's contents. |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
483 |
Redefined to block interrupts, to avoid trouble when dependencies |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
484 |
are added within interrupting high prio processes." |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
485 |
|
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
486 |
"/ 'setTally:' printCR. |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
487 |
|
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
488 |
(OperatingSystem blockInterrupts) ifTrue:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
489 |
"/ already blocked |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
490 |
super initializeForCapacity:minSize. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
491 |
^ self. |
18333
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
492 |
]. |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
493 |
|
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
494 |
[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
495 |
super initializeForCapacity:minSize |
18333
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
496 |
] ensure:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
497 |
OperatingSystem unblockInterrupts |
18333
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
498 |
]. |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
499 |
|
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
500 |
"Created: 29.1.1997 / 11:40:12 / cg" |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
501 |
"Modified: 29.1.1997 / 15:11:11 / cg" |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
502 |
! |
854cf4f00536
class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents:
16513
diff
changeset
|
503 |
|
609 | 504 |
keyContainerOfSize:n |
505 |
"return a container for keys of size n. |
|
20037 | 506 |
use WeakArrays here." |
609 | 507 |
|
508 |
|w| |
|
509 |
||
510 |
w := WeakArray new:n. |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
511 |
w addDependent:self. |
609 | 512 |
^ w |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
513 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
2027
diff
changeset
|
514 |
"Modified: 7.1.1997 / 17:01:15 / stefan" |
2298 | 515 |
"Modified: 29.1.1997 / 14:18:49 / cg" |
516 |
! |
|
517 |
||
518 |
rehash |
|
519 |
"grow the receiver. |
|
520 |
Redefined to block interrupts, to avoid trouble when dependencies |
|
521 |
are added within interrupting high prio processes." |
|
522 |
||
523 |
"/ 'rehash' printCR. |
|
524 |
||
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
|
525 |
(OperatingSystem blockInterrupts) ifTrue:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
526 |
"/ already blocked |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
527 |
super rehash. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
528 |
^ self. |
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
|
529 |
]. |
f19df2d4c238
avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents:
2298
diff
changeset
|
530 |
|
2298 | 531 |
[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
532 |
super rehash |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
533 |
] ensure:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
534 |
OperatingSystem unblockInterrupts |
2298 | 535 |
]. |
536 |
||
537 |
"Created: 29.1.1997 / 11:39:42 / cg" |
|
538 |
"Modified: 29.1.1997 / 14:18:52 / cg" |
|
609 | 539 |
! ! |
540 |
||
2741 | 541 |
!WeakIdentityDictionary methodsFor:'testing'! |
542 |
||
543 |
includes:anObject |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
544 |
"redefined to block interrupts |
2741 | 545 |
(avoid change of the dictionary while accessing)" |
546 |
||
547 |
|val| |
|
548 |
||
549 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
550 |
"/ already blocked |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
551 |
^ super includes:anObject. |
2741 | 552 |
]. |
553 |
||
554 |
[ |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
555 |
val := super includes:anObject. |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
556 |
] ensure:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
557 |
OperatingSystem unblockInterrupts. |
2741 | 558 |
]. |
559 |
^ val |
|
560 |
||
561 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
562 |
"Modified: 1.7.1997 / 10:45:52 / cg" |
|
563 |
"Created: 1.7.1997 / 10:47:13 / cg" |
|
564 |
! |
|
565 |
||
566 |
includesKey:key |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
567 |
"redefined to block interrupts |
2741 | 568 |
(avoid change of the dictionary while accessing)" |
569 |
||
570 |
|val| |
|
571 |
||
20166 | 572 |
key class == SmallInteger ifTrue:[ |
573 |
"SmallIntegers cannot be stored into a WeakArray" |
|
574 |
^ false. |
|
575 |
]. |
|
576 |
||
2741 | 577 |
(OperatingSystem blockInterrupts) ifTrue:[ |
20166 | 578 |
"/ already blocked |
579 |
^ super includesKey:key. |
|
2741 | 580 |
]. |
581 |
||
582 |
[ |
|
20166 | 583 |
val := super includesKey:key. |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6309
diff
changeset
|
584 |
] ensure:[ |
20166 | 585 |
OperatingSystem unblockInterrupts. |
2741 | 586 |
]. |
587 |
^ val |
|
588 |
||
589 |
"Modified: 6.5.1996 / 12:22:26 / stefan" |
|
590 |
"Created: 1.7.1997 / 10:45:14 / cg" |
|
591 |
"Modified: 1.7.1997 / 10:45:52 / cg" |
|
9243 | 592 |
! |
593 |
||
594 |
isWeakCollection |
|
595 |
"return true, if the receiver has weak references to its elements." |
|
596 |
||
597 |
^ true |
|
2741 | 598 |
! ! |
599 |
||
635 | 600 |
!WeakIdentityDictionary class methodsFor:'documentation'! |
601 |
||
602 |
version |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18333
diff
changeset
|
603 |
^ '$Header$' |
20992 | 604 |
! |
605 |
||
606 |
version_CVS |
|
607 |
^ '$Header$' |
|
22129
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
608 |
! |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
609 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
610 |
version_HG |
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
611 |
|
697c819c7674
Fixed a baaad bug in `WeakIdentityDictionary` w.r.t growing
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21027
diff
changeset
|
612 |
^ '$Changeset: <not expanded> $' |
635 | 613 |
! ! |
16244 | 614 |