223 If it is found, return return the index, otherwise |
225 If it is found, return return the index, otherwise |
224 the index of the first unused slot. |
226 the index of the first unused slot. |
225 Grow the receiver, if key was not found, and no unused slots were present. |
227 Grow the receiver, if key was not found, and no unused slots were present. |
226 |
228 |
227 Warning: an empty slot MUST be filled by the sender - it is only to be sent |
229 Warning: an empty slot MUST be filled by the sender - it is only to be sent |
228 by at:put: / add: - like methods." |
230 by at:put: / add: - like methods." |
229 |
231 |
230 |index "{ Class:SmallInteger }" |
232 |index "{ Class:SmallInteger }" |
231 length "{ Class:SmallInteger }" |
233 length "{ Class:SmallInteger }" |
232 startIndex probe |
234 startIndex probe |
233 delIndex "{ Class:SmallInteger }"| |
235 delIndex "{ Class:SmallInteger }"| |
234 |
236 |
235 (OperatingSystem blockInterrupts) ifFalse:[ |
237 (OperatingSystem blockInterrupts) ifFalse:[ |
236 "/ |
238 "/ |
237 "/ may never be entered with interrupts enabled |
239 "/ may never be entered with interrupts enabled |
238 "/ |
240 "/ |
239 OperatingSystem unblockInterrupts. |
241 OperatingSystem unblockInterrupts. |
240 self error:'unblocked call of findKeyOrNil'. |
242 self error:'unblocked call of findKeyOrNil'. |
241 ]. |
243 ]. |
242 |
244 |
243 delIndex := 0. |
245 delIndex := 0. |
244 |
246 |
245 length := keyArray basicSize. |
247 length := keyArray basicSize. |
246 startIndex := index := self initialIndexForKey:key. |
248 startIndex := index := self initialIndexForKey:key. |
247 |
249 |
248 [ |
250 [ |
249 probe := keyArray basicAt:index. |
251 probe := keyArray basicAt:index. |
250 key == probe ifTrue:[^ index]. |
252 key == probe ifTrue:[^ index]. |
251 probe isNil ifTrue:[ |
253 probe isNil ifTrue:[ |
252 delIndex == 0 ifTrue:[^ index]. |
254 delIndex == 0 ifTrue:[^ index]. |
253 keyArray basicAt:delIndex put:nil. |
255 keyArray basicAt:delIndex put:nil. |
254 ^ delIndex |
256 ^ delIndex |
255 ]. |
257 ]. |
256 |
258 |
257 probe class == SmallInteger ifTrue:[ |
259 probe class == SmallInteger ifTrue:[ |
258 probe := DeletedEntry. |
260 probe := DeletedEntry. |
259 keyArray basicAt:index put:probe. |
261 keyArray basicAt:index put:probe. |
260 tally := tally - 1. |
262 tally := tally - 1. |
261 ]. |
263 ]. |
262 delIndex == 0 ifTrue:[ |
264 delIndex == 0 ifTrue:[ |
263 probe == DeletedEntry ifTrue:[ |
265 probe == DeletedEntry ifTrue:[ |
264 delIndex := index |
266 delIndex := index |
265 ] |
267 ] |
266 ]. |
268 ]. |
267 |
269 |
268 index == length ifTrue:[ |
270 index == length ifTrue:[ |
269 index := 1 |
271 index := 1 |
270 ] ifFalse:[ |
272 ] ifFalse:[ |
271 index := index + 1 |
273 index := index + 1 |
272 ]. |
274 ]. |
273 index == startIndex ifTrue:[ |
275 index == startIndex ifTrue:[ |
274 delIndex ~~ 0 ifTrue:[ |
276 delIndex ~~ 0 ifTrue:[ |
275 keyArray basicAt:delIndex put:nil. |
277 keyArray basicAt:delIndex put:nil. |
276 ^ delIndex |
278 ^ delIndex |
277 ]. |
279 ]. |
278 ^ self grow findKeyOrNil:key |
280 self grow. |
279 ]. |
281 length := keyArray basicSize. |
|
282 startIndex := index := self initialIndexForKey:key. |
|
283 ]. |
|
284 ] loop. |
|
285 |
|
286 "Modified: 30.1.1997 / 15:04:38 / cg" |
|
287 ! |
|
288 |
|
289 findKeyOrNilOrDeletedEntry:key |
|
290 "Look for the key in the receiver. |
|
291 If it is found, return return the index, otherwise |
|
292 the index of the first unused slot. |
|
293 Grow the receiver, if key was not found, and no unused slots were present" |
|
294 |
|
295 |index "{ Class:SmallInteger }" |
|
296 length "{ Class:SmallInteger }" |
|
297 startIndex probe |
|
298 delIndex "{ Class:SmallInteger }"| |
|
299 |
|
300 (OperatingSystem blockInterrupts) ifFalse:[ |
|
301 "/ |
|
302 "/ may never be entered with interrupts enabled |
|
303 "/ |
|
304 OperatingSystem unblockInterrupts. |
|
305 self error:'unblocked call of findKeyOrNil'. |
|
306 ]. |
|
307 |
|
308 delIndex := 0. |
|
309 |
|
310 length := keyArray basicSize. |
|
311 startIndex := index := self initialIndexForKey:key. |
|
312 |
|
313 [ |
|
314 probe := keyArray basicAt:index. |
|
315 key == probe ifTrue:[^ index]. |
|
316 probe isNil ifTrue:[ |
|
317 delIndex == 0 ifTrue:[^ index]. |
|
318 ^ delIndex |
|
319 ]. |
|
320 |
|
321 probe class == SmallInteger ifTrue:[ |
|
322 probe := DeletedEntry. |
|
323 keyArray basicAt:index put:probe. |
|
324 tally := tally - 1. |
|
325 ]. |
|
326 delIndex == 0 ifTrue:[ |
|
327 probe == DeletedEntry ifTrue:[ |
|
328 delIndex := index |
|
329 ] |
|
330 ]. |
|
331 |
|
332 index == length ifTrue:[ |
|
333 index := 1 |
|
334 ] ifFalse:[ |
|
335 index := index + 1 |
|
336 ]. |
|
337 index == startIndex ifTrue:[ |
|
338 delIndex ~~ 0 ifTrue:[ |
|
339 ^ delIndex |
|
340 ]. |
|
341 self grow. |
|
342 length := keyArray basicSize. |
|
343 startIndex := index := self initialIndexForKey:key. |
|
344 ]. |
280 ] loop. |
345 ] loop. |
281 |
346 |
282 "Modified: 30.1.1997 / 15:04:38 / cg" |
347 "Modified: 30.1.1997 / 15:04:38 / cg" |
283 ! |
348 ! |
284 |
349 |