208 ] |
208 ] |
209 ! ! |
209 ! ! |
210 |
210 |
211 !WeakIdentitySet methodsFor:'private'! |
211 !WeakIdentitySet methodsFor:'private'! |
212 |
212 |
|
213 findKeyOrNil:key |
|
214 "Look for the key in the receiver. |
|
215 If it is found, return return the index of the first unused slot. |
|
216 Grow the receiver, if key was not found, and no unused slots were present" |
|
217 |
|
218 |index "{ Class:SmallInteger }" |
|
219 length "{ Class:SmallInteger }" |
|
220 startIndex probe |
|
221 delIndex "{ Class:SmallInteger }" |
|
222 wasBlocked| |
|
223 |
|
224 wasBlocked := OperatingSystem blockInterrupts. |
|
225 |
|
226 wasBlocked ifFalse:[ |
|
227 "/ may never be entered with interrupts enabled |
|
228 self error:'oops - unblocked call of findKeyOrNil' |
|
229 ]. |
|
230 |
|
231 [ |
|
232 delIndex := 0. |
|
233 |
|
234 length := keyArray basicSize. |
|
235 index := key identityHash. |
|
236 index < 16r1FFFFFFF ifTrue:[ |
|
237 index := index * 2 |
|
238 ]. |
|
239 |
|
240 index := index \\ length + 1. |
|
241 startIndex := index. |
|
242 |
|
243 [true] whileTrue:[ |
|
244 probe := keyArray basicAt:index. |
|
245 key == probe ifTrue:[^ index]. |
|
246 probe isNil ifTrue:[ |
|
247 delIndex == 0 ifTrue:[^ index]. |
|
248 keyArray basicAt:delIndex put:nil. |
|
249 ^ delIndex |
|
250 ]. |
|
251 |
|
252 probe == 0 ifTrue:[ |
|
253 probe := DeletedEntry. |
|
254 keyArray basicAt:index put:probe. |
|
255 tally := tally - 1. |
|
256 ]. |
|
257 delIndex == 0 ifTrue:[ |
|
258 probe == DeletedEntry ifTrue:[ |
|
259 delIndex := index |
|
260 ] |
|
261 ]. |
|
262 |
|
263 index == length ifTrue:[ |
|
264 index := 1 |
|
265 ] ifFalse:[ |
|
266 index := index + 1 |
|
267 ]. |
|
268 index == startIndex ifTrue:[ |
|
269 delIndex ~~ 0 ifTrue:[ |
|
270 keyArray basicAt:delIndex put:nil. |
|
271 ^ delIndex |
|
272 ]. |
|
273 ^ self grow findKeyOrNil:key |
|
274 ]. |
|
275 ] |
|
276 ] valueNowOrOnUnwindDo:[ |
|
277 wasBlocked ifFalse:[ |
|
278 OperatingSystem unblockInterrupts |
|
279 ] |
|
280 ] |
|
281 |
|
282 "Created: 29.1.1997 / 21:43:57 / cg" |
|
283 "Modified: 29.1.1997 / 22:09:55 / cg" |
|
284 ! |
|
285 |
213 keyContainerOfSize:n |
286 keyContainerOfSize:n |
214 "return a container for keys and values of size n. |
287 "return a container for keys and values of size n. |
215 use WeakArrays here." |
288 use WeakArrays here." |
216 |
289 |
217 |w| |
290 |w| |