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