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