author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 15:23:19 +0100 | |
changeset 624 | f09ad5cf21d4 |
parent 606 | 7a9ab63a6757 |
child 629 | 2ceefe9b5a19 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
||
13 |
SequenceableCollection subclass:#OrderedCollection |
|
159 | 14 |
instanceVariableNames:'contentsArray firstIndex lastIndex' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Collections-Sequenceable' |
|
1 | 18 |
! |
19 |
||
33 | 20 |
!OrderedCollection class methodsFor:'documentation'! |
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
33 | 36 |
documentation |
37 |
" |
|
68 | 38 |
OrderedCollection have ordered elements. Insertion and removal at both ends |
39 |
is possible - therefore they can be used for queues and stacks. |
|
1 | 40 |
|
68 | 41 |
Instance variables: |
1 | 42 |
|
68 | 43 |
contentsArray <Array> the actual contents |
44 |
firstIndex <SmallInteger> index of first valid element |
|
45 |
lastIndex <SmallInteger> index of last valid element |
|
33 | 46 |
" |
606 | 47 |
! |
48 |
||
49 |
version |
|
50 |
^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.37 1995-11-23 01:19:14 cg Exp $' |
|
33 | 51 |
! ! |
1 | 52 |
|
53 |
!OrderedCollection class methodsFor:'instance creation'! |
|
54 |
||
55 |
new |
|
56 |
"create a new OrderedCollection" |
|
57 |
||
58 |
^ (self basicNew) initContents:10 |
|
293 | 59 |
! |
60 |
||
606 | 61 |
new:size |
62 |
"create a new OrderedCollection" |
|
63 |
||
64 |
^ (self basicNew) initContents:(size max:3) |
|
293 | 65 |
! ! |
66 |
||
606 | 67 |
!OrderedCollection methodsFor:'accessing'! |
1 | 68 |
|
606 | 69 |
at:anInteger |
70 |
"return the element at index, anInteger" |
|
1 | 71 |
|
606 | 72 |
|idx| |
387 | 73 |
|
606 | 74 |
idx := anInteger + firstIndex - 1. |
75 |
((anInteger < 1) or:[idx > lastIndex]) ifTrue:[ |
|
76 |
^ self subscriptBoundsError:anInteger |
|
77 |
] ifFalse:[ |
|
78 |
^ contentsArray at:idx |
|
79 |
] |
|
360 | 80 |
! |
81 |
||
606 | 82 |
at:anInteger put:anObject |
83 |
"set the element at index, to be anInteger" |
|
1 | 84 |
|
606 | 85 |
|idx| |
1 | 86 |
|
606 | 87 |
idx := anInteger + firstIndex - 1. |
88 |
((anInteger < 1) or:[idx > lastIndex]) ifTrue:[ |
|
89 |
^ self subscriptBoundsError:anInteger |
|
90 |
] ifFalse:[ |
|
91 |
^ contentsArray at:idx put:anObject |
|
92 |
] |
|
202 | 93 |
! |
94 |
||
606 | 95 |
first |
96 |
"return the first element" |
|
1 | 97 |
|
606 | 98 |
firstIndex <= lastIndex ifTrue:[ |
99 |
^ contentsArray at:firstIndex |
|
1 | 100 |
]. |
606 | 101 |
"error if collection is empty" |
102 |
^ self emptyCollectionError |
|
2 | 103 |
|
93 | 104 |
" |
606 | 105 |
(OrderedCollection withAll:#(1 2 3 4 5)) first |
106 |
(SortedCollection withAll:#(5 4 3 2 1)) first |
|
93 | 107 |
" |
13 | 108 |
! |
109 |
||
606 | 110 |
last |
111 |
"return the last element" |
|
68 | 112 |
|
606 | 113 |
firstIndex <= lastIndex ifTrue:[ |
114 |
^ contentsArray at:lastIndex |
|
115 |
]. |
|
116 |
"error if collection is empty" |
|
117 |
^ self emptyCollectionError |
|
68 | 118 |
|
93 | 119 |
" |
606 | 120 |
(OrderedCollection withAll:#(1 2 3 4 5)) last |
121 |
(SortedCollection withAll:#(5 4 3 2 1)) last |
|
93 | 122 |
" |
1 | 123 |
! ! |
124 |
||
125 |
!OrderedCollection methodsFor:'adding & removing'! |
|
126 |
||
606 | 127 |
add:anObject |
128 |
"add the argument, anObject to the end of the collection |
|
129 |
Return the argument, anObject." |
|
130 |
||
131 |
|idx "{ Class:SmallInteger }"| |
|
1 | 132 |
|
606 | 133 |
idx := lastIndex. |
1 | 134 |
|
606 | 135 |
(idx == contentsArray size) ifTrue:[ |
136 |
self makeRoomAtLast. |
|
137 |
idx := lastIndex. |
|
42 | 138 |
]. |
606 | 139 |
idx := lastIndex := idx + 1. |
140 |
contentsArray at:idx put:anObject. |
|
141 |
"/ lastIndex := idx. |
|
1 | 142 |
^ anObject |
42 | 143 |
|
348 | 144 |
" |
606 | 145 |
|c| |
146 |
c := #(4 3 2 1) asOrderedCollection. |
|
147 |
c add:'here' |
|
348 | 148 |
" |
1 | 149 |
! |
150 |
||
606 | 151 |
add:newObject after:oldObject |
152 |
"insert the argument, newObject after oldObject. |
|
153 |
If oldObject is not in the receiver, report an error, |
|
154 |
otherwise return the argument, anObject." |
|
1 | 155 |
|
606 | 156 |
|idx| |
1 | 157 |
|
606 | 158 |
idx := self indexOf:oldObject. |
159 |
idx ~~ 0 ifTrue:[ |
|
160 |
^ self add:newObject beforeIndex:(idx + 1). |
|
42 | 161 |
]. |
606 | 162 |
self errorValueNotFound:oldObject |
42 | 163 |
|
348 | 164 |
" |
606 | 165 |
|c| |
166 |
c := #(4 3 2 1) asOrderedCollection. |
|
167 |
c add:'here' after:3. |
|
168 |
" |
|
169 |
" |
|
170 |
|c| |
|
171 |
c := #(4 3 2 1) asOrderedCollection. |
|
172 |
c add:'here' after:1. |
|
173 |
" |
|
174 |
" |
|
175 |
|c| |
|
176 |
c := #(4 3 2 1) asOrderedCollection. |
|
177 |
c add:'here' after:5 |
|
178 |
" |
|
179 |
! |
|
180 |
||
181 |
add:anObject afterIndex:index |
|
182 |
"insert the argument, anObject to become located at index. |
|
183 |
Return the argument, anObject." |
|
184 |
||
185 |
^ self add:anObject beforeIndex:(index + 1) |
|
186 |
||
187 |
" |
|
188 |
|c| |
|
189 |
c := #(4 3 2 1) asOrderedCollection. |
|
190 |
c add:'here' afterIndex:4 |
|
348 | 191 |
" |
192 |
! |
|
193 |
||
606 | 194 |
add:newObject before:oldObject |
195 |
"insert the argument, newObject before oldObject. |
|
196 |
If oldObject is not in the receiver, report an error, |
|
197 |
otherwise return the argument, anObject." |
|
348 | 198 |
|
606 | 199 |
|idx| |
348 | 200 |
|
606 | 201 |
idx := self indexOf:oldObject. |
202 |
idx ~~ 0 ifTrue:[ |
|
203 |
^ self add:newObject beforeIndex:idx. |
|
348 | 204 |
]. |
606 | 205 |
self errorValueNotFound:oldObject |
348 | 206 |
|
207 |
" |
|
606 | 208 |
|c| |
209 |
c := #(4 3 2 1) asOrderedCollection. |
|
210 |
c add:'here' before:3. |
|
211 |
c add:'here' before:5 |
|
348 | 212 |
" |
213 |
! |
|
214 |
||
606 | 215 |
add:anObject beforeIndex:index |
216 |
"insert the argument, anObject to become located at index. |
|
217 |
Return the argument, anObject." |
|
348 | 218 |
|
606 | 219 |
self makeRoomAtIndex:(index - firstIndex + 1). |
220 |
contentsArray at:(index - firstIndex + 1) put:anObject. |
|
348 | 221 |
|
222 |
" |
|
606 | 223 |
|c| |
224 |
c := #(4 3 2 1) asOrderedCollection. |
|
225 |
c add:'here' beforeIndex:3 |
|
226 |
" |
|
227 |
" |
|
228 |
|c| |
|
229 |
c := #(4 3 2 1) asOrderedCollection. |
|
230 |
c add:'here' beforeIndex:1 |
|
231 |
" |
|
232 |
" |
|
233 |
|c| |
|
234 |
c := #(4 3 2 1) asOrderedCollection. |
|
235 |
c add:'here' beforeIndex:5 |
|
348 | 236 |
" |
1 | 237 |
! |
238 |
||
606 | 239 |
addFirst:anObject |
240 |
"add the argument, anObject to the beginning of the collection. |
|
241 |
Return the argument, anObject." |
|
56 | 242 |
|
606 | 243 |
(firstIndex == 1) ifTrue:[ |
244 |
self makeRoomAtFront |
|
348 | 245 |
]. |
606 | 246 |
firstIndex := firstIndex - 1. |
247 |
contentsArray at:firstIndex put:anObject. |
|
248 |
^ anObject |
|
56 | 249 |
|
250 |
" |
|
606 | 251 |
|c| |
252 |
c := #(1 2 3 4) asOrderedCollection. |
|
253 |
c addFirst:'here'. |
|
254 |
c |
|
255 |
" |
|
256 |
||
257 |
" |
|
258 |
|c| |
|
259 |
c := #() asOrderedCollection. |
|
260 |
c addFirst:'here'. |
|
261 |
c |
|
56 | 262 |
" |
263 |
! |
|
264 |
||
1 | 265 |
remove:anObject ifAbsent:exceptionBlock |
407 | 266 |
"remove the first occurrence of anObject from the collection |
267 |
and return it. |
|
268 |
If its not in the receiver collection, return the value of exceptionBlock." |
|
1 | 269 |
|
270 |
|index "{ Class:SmallInteger }"| |
|
271 |
||
272 |
index := firstIndex. |
|
273 |
[index <= lastIndex] whileTrue:[ |
|
159 | 274 |
anObject = (contentsArray at:index) ifTrue:[ |
329 | 275 |
contentsArray |
276 |
replaceFrom:index |
|
277 |
to:(contentsArray size - 1) |
|
278 |
with:contentsArray |
|
279 |
startingAt:(index + 1). |
|
159 | 280 |
contentsArray at:lastIndex put:nil. |
281 |
lastIndex := lastIndex - 1. |
|
282 |
firstIndex > lastIndex ifTrue:[ |
|
283 |
"reset to avoid ever growing" |
|
284 |
firstIndex := 1. |
|
285 |
lastIndex := 0 |
|
286 |
]. |
|
287 |
^ anObject |
|
288 |
]. |
|
289 |
index := index + 1 |
|
1 | 290 |
]. |
291 |
^ exceptionBlock value |
|
348 | 292 |
|
293 |
" |
|
294 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection remove:3 ifAbsent:'oops' |
|
295 |
#(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:'oops' |
|
296 |
" |
|
1 | 297 |
! |
298 |
||
114 | 299 |
removeAll |
300 |
"remove all elements from the collection." |
|
301 |
||
302 |
self initContents:10 |
|
303 |
! |
|
304 |
||
348 | 305 |
removeAllSuchThat:aBlock |
306 |
"remove all elements that meet a test criteria as specified in aBlock. |
|
307 |
The argument, aBlock is evaluated for successive elements and all those, |
|
308 |
for which it returns true, are removed." |
|
309 |
||
310 |
"/ this is a q&d implementation (slow). |
|
311 |
"/ it should be rewritten to |
|
312 |
||
313 |
|runIndex removed element| |
|
314 |
||
315 |
removed := self species new. |
|
316 |
||
317 |
runIndex := 1. |
|
318 |
[runIndex <= self size] whileTrue:[ |
|
319 |
element := self at:runIndex. |
|
320 |
(aBlock value:element) ifTrue:[ |
|
321 |
removed add:element. |
|
322 |
self removeAtIndex:runIndex |
|
323 |
] ifFalse:[ |
|
324 |
runIndex := runIndex + 1 |
|
325 |
] |
|
326 |
]. |
|
327 |
^ removed |
|
328 |
||
329 |
" |
|
330 |
|coll| |
|
331 |
||
332 |
coll := OrderedCollection withAll:(1 to:10). |
|
333 |
Transcript showCr:(coll removeAllSuchThat:[:el | el even]). |
|
334 |
Transcript showCr:coll |
|
335 |
" |
|
336 |
! |
|
337 |
||
606 | 338 |
removeFirst |
339 |
"remove the first element from the collection; return the element" |
|
202 | 340 |
|
606 | 341 |
|anObject | |
13 | 342 |
|
606 | 343 |
firstIndex > lastIndex ifTrue:[ |
344 |
"error if collection is empty" |
|
345 |
^ self emptyCollectionError. |
|
346 |
]. |
|
347 |
anObject := contentsArray at:firstIndex. |
|
348 |
contentsArray at:firstIndex put:nil. |
|
349 |
firstIndex := firstIndex + 1. |
|
1 | 350 |
|
606 | 351 |
firstIndex > lastIndex ifTrue:[ |
352 |
"reset to avoid ever growing" |
|
353 |
firstIndex := 1. |
|
354 |
lastIndex := 0 |
|
1 | 355 |
]. |
356 |
^ anObject |
|
13 | 357 |
|
358 |
" |
|
606 | 359 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself |
360 |
OrderedCollection new removeFirst |
|
361 |
(SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself |
|
93 | 362 |
" |
606 | 363 |
! |
364 |
||
365 |
removeFirst:n |
|
366 |
"remove the first n elements from the collection; |
|
367 |
return the elements in an Array" |
|
368 |
||
369 |
|mySize ret| |
|
370 |
||
371 |
mySize := self size. |
|
372 |
mySize < n ifTrue:[ |
|
373 |
"error if collection has not enough elements" |
|
374 |
^ self notEnoughElementsError. |
|
375 |
]. |
|
376 |
||
377 |
ret := Array new:n. |
|
378 |
ret replaceFrom:1 to:n with:contentsArray startingAt:firstIndex. |
|
379 |
"/ |
|
380 |
"/ nil-out contents array, to not keep elements from being GC'd |
|
381 |
"/ |
|
382 |
contentsArray from:firstIndex to:firstIndex + n - 1 put:nil. |
|
383 |
firstIndex := firstIndex + n. |
|
384 |
||
385 |
firstIndex > lastIndex ifTrue:[ |
|
386 |
"reset to avoid ever growing" |
|
387 |
firstIndex := 1. |
|
388 |
lastIndex := 0 |
|
389 |
]. |
|
390 |
^ ret |
|
93 | 391 |
|
392 |
" |
|
606 | 393 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:2; yourself |
394 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:0; yourself |
|
395 |
OrderedCollection new removeFirst:2 |
|
396 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:6 |
|
397 |
(SortedCollection withAll:#(5 4 3 2 1)) removeFirst:2; yourself |
|
13 | 398 |
" |
1 | 399 |
! |
400 |
||
606 | 401 |
removeFromIndex:startIndex toIndex:stopIndex |
402 |
"remove the elements stored under startIndex up to and including |
|
403 |
the elements under stopIndex. |
|
404 |
Return the receiver. |
|
405 |
Returning the receiver here is a historic leftover - it may change. |
|
406 |
Please use yourself in a cascade, if you need the receivers value |
|
407 |
when using this method." |
|
408 |
||
409 |
|nDeleted| |
|
1 | 410 |
|
606 | 411 |
(startIndex < 1 |
412 |
or:[stopIndex > self size]) ifTrue:[ |
|
413 |
^ self notEnoughElementsError |
|
414 |
]. |
|
415 |
nDeleted := stopIndex - startIndex + 1. |
|
416 |
contentsArray |
|
417 |
replaceFrom:(firstIndex + startIndex - 1) |
|
418 |
to:(lastIndex - nDeleted) |
|
419 |
with:contentsArray |
|
420 |
startingAt:(firstIndex + stopIndex). |
|
421 |
||
422 |
contentsArray |
|
423 |
from:(lastIndex - nDeleted + 1) |
|
424 |
to:lastIndex |
|
425 |
put:nil. |
|
426 |
||
427 |
lastIndex := lastIndex - nDeleted. |
|
428 |
firstIndex > lastIndex ifTrue:[ |
|
429 |
"reset to avoid ever growing" |
|
430 |
firstIndex := 1. |
|
431 |
lastIndex := 0 |
|
432 |
] |
|
13 | 433 |
|
434 |
" |
|
606 | 435 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:3 toIndex:6 |
436 |
#(1 2 3 4 5) asOrderedCollection removeFromIndex:3 toIndex:6 |
|
217 | 437 |
" |
438 |
! |
|
439 |
||
606 | 440 |
removeLast |
441 |
"remove the last element from the collection; return the element" |
|
442 |
||
443 |
|anObject | |
|
217 | 444 |
|
606 | 445 |
firstIndex > lastIndex ifTrue:[ |
446 |
"error if collection is empty" |
|
447 |
^ self emptyCollectionError. |
|
448 |
]. |
|
449 |
anObject := contentsArray at:lastIndex. |
|
450 |
contentsArray at:lastIndex put:nil. |
|
451 |
lastIndex := lastIndex - 1. |
|
452 |
||
453 |
firstIndex > lastIndex ifTrue:[ |
|
454 |
"reset to avoid ever growing" |
|
455 |
firstIndex := 1. |
|
456 |
lastIndex := 0 |
|
457 |
]. |
|
458 |
^ anObject |
|
217 | 459 |
|
460 |
" |
|
606 | 461 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast; yourself |
462 |
OrderedCollection new removeLast |
|
463 |
(SortedCollection withAll:#(5 4 3 2 1)) removeLast; yourself |
|
217 | 464 |
" |
13 | 465 |
! |
466 |
||
606 | 467 |
removeLast:n |
468 |
"remove the last n elements from the collection; |
|
469 |
return the elements in an Array" |
|
470 |
||
471 |
|mySize ret| |
|
472 |
||
473 |
mySize := self size. |
|
474 |
mySize < n ifTrue:[ |
|
475 |
"error if collection has not enough elements" |
|
476 |
^ self notEnoughElementsError. |
|
477 |
]. |
|
13 | 478 |
|
606 | 479 |
ret := Array new:n. |
480 |
ret replaceFrom:1 to:n with:contentsArray startingAt:lastIndex - n + 1. |
|
481 |
"/ |
|
482 |
"/ nil-out contents array, to not keep elements from being GC'd |
|
483 |
"/ |
|
484 |
contentsArray from:lastIndex - n + 1 to:lastIndex put:nil. |
|
485 |
lastIndex := lastIndex - n. |
|
13 | 486 |
|
606 | 487 |
firstIndex > lastIndex ifTrue:[ |
488 |
"reset to avoid ever growing" |
|
489 |
firstIndex := 1. |
|
490 |
lastIndex := 0 |
|
13 | 491 |
]. |
606 | 492 |
^ ret |
13 | 493 |
|
494 |
" |
|
606 | 495 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast:2; yourself |
496 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast:0; yourself |
|
497 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast:6; yourself |
|
498 |
(SortedCollection withAll:#(5 4 3 2 1)) removeLast:2; yourself |
|
13 | 499 |
" |
1 | 500 |
! ! |
501 |
||
606 | 502 |
!OrderedCollection methodsFor:'converting'! |
1 | 503 |
|
606 | 504 |
asOrderedCollection |
505 |
"return the receiver as an ordered collection" |
|
1 | 506 |
|
606 | 507 |
"could be an instance of a subclass..." |
508 |
self class == OrderedCollection ifTrue:[ |
|
509 |
^ self |
|
510 |
]. |
|
511 |
^ super asOrderedCollection |
|
1 | 512 |
! ! |
513 |
||
606 | 514 |
!OrderedCollection methodsFor:'copying'! |
13 | 515 |
|
606 | 516 |
, aCollection |
517 |
"return a new collection formed from concatenating the receiver with |
|
518 |
the argument" |
|
1 | 519 |
|
606 | 520 |
|newCollection| |
1 | 521 |
|
606 | 522 |
newCollection := self copyEmpty:(self size + aCollection size). |
523 |
self do:[:element | |
|
524 |
newCollection add:element |
|
42 | 525 |
]. |
606 | 526 |
aCollection do:[:element | |
527 |
newCollection add:element |
|
528 |
]. |
|
529 |
^ newCollection |
|
42 | 530 |
|
253 | 531 |
" |
606 | 532 |
#(1 2 3) asOrderedCollection , #(4 5 6) asOrderedCollection |
533 |
#(1 2 3) asSortedCollection , #(99 101 100) asSortedCollection |
|
253 | 534 |
" |
42 | 535 |
! |
536 |
||
606 | 537 |
copy |
538 |
"return a new OrderedCollection containing the elements of the receiver." |
|
539 |
||
540 |
"redefinition is a consequence of the implementation with a |
|
541 |
separate array - otherwise we get a shallow copy of the |
|
542 |
contents array, which is not what we want here" |
|
543 |
||
544 |
^ self copyFrom:1 to:self size |
|
545 |
! |
|
546 |
||
547 |
copyEmpty |
|
548 |
"return a copy of the receiver without any elements." |
|
549 |
||
550 |
^ self copyEmpty:10 |
|
551 |
! |
|
552 |
||
553 |
copyFrom:start to:stop |
|
554 |
"return a new OrderedCollection containing the elements |
|
555 |
from start to stop." |
|
42 | 556 |
|
606 | 557 |
|newCollection sz| |
558 |
||
559 |
sz := stop - start + 1. |
|
560 |
newCollection := self copyEmptyAndGrow:sz. "must grow, otherwise replace fails" |
|
561 |
newCollection replaceFrom:1 to:sz with:self startingAt:start. |
|
562 |
^ newCollection |
|
563 |
! |
|
564 |
||
565 |
copyWith:newElement |
|
566 |
"return a new collection containing the receivers elements |
|
567 |
and the single new element, newElement. |
|
568 |
This is different from concatentation, which expects another collection |
|
569 |
as argument, but equivalent to copy-and-addLast." |
|
570 |
||
571 |
|newCollection mySize newSize| |
|
572 |
||
573 |
mySize := self size. |
|
574 |
newSize := mySize + 1. |
|
575 |
newCollection := self copyEmptyAndGrow:newSize. "must grow, otherwise replace fails" |
|
576 |
newCollection replaceFrom:1 to:mySize with:self startingAt:1. |
|
577 |
newCollection at:newSize put:newElement. |
|
578 |
^newCollection |
|
42 | 579 |
|
253 | 580 |
" |
606 | 581 |
#(1 2 3 4 5) copyWith:$a |
582 |
'abcdefg' copyWith:$h |
|
583 |
'abcdefg' copyWith:'123' -- will fail: string cannot be stored into string |
|
584 |
'abcdefg' copyWith:1 -- will fail: integer cannot be stored into string |
|
585 |
" |
|
586 |
! |
|
587 |
||
588 |
postCopy |
|
589 |
"have to copy the contentsArray too" |
|
590 |
||
591 |
contentsArray := contentsArray shallowCopy |
|
592 |
! ! |
|
593 |
||
594 |
!OrderedCollection methodsFor:'enumerating'! |
|
595 |
||
596 |
collect:aBlock |
|
597 |
"evaluate the argument, aBlock for every element in the collection |
|
598 |
and return a collection of the results" |
|
599 |
||
600 |
|newCollection |
|
601 |
start "{ Class:SmallInteger }" |
|
602 |
stop "{ Class:SmallInteger }" | |
|
603 |
||
604 |
newCollection := self copyEmpty:(self size). |
|
605 |
stop := lastIndex. |
|
606 |
start := firstIndex. |
|
607 |
start to:stop do:[:index | |
|
608 |
newCollection add:(aBlock value:(contentsArray at:index)). |
|
609 |
]. |
|
610 |
^ newCollection |
|
611 |
||
253 | 612 |
" |
606 | 613 |
#(1 2 3 4) asOrderedCollection collect:[:i | i * i] |
614 |
#(1 2 3 4) asOrderedCollection collect:[:i | i even] |
|
615 |
" |
|
616 |
! |
|
617 |
||
618 |
do:aBlock |
|
619 |
"evaluate the argument, aBlock for every element in the collection." |
|
620 |
||
621 |
contentsArray from:firstIndex to:lastIndex do:aBlock |
|
622 |
! |
|
623 |
||
624 |
keysAndValuesDo:aTwoArgBlock |
|
625 |
"evaluate the argument, aBlock for every element in the collection, |
|
626 |
passing both index and element as arguments." |
|
627 |
||
628 |
|start "{ Class:SmallInteger }" |
|
629 |
stop "{ Class:SmallInteger }" | |
|
630 |
||
631 |
stop := lastIndex. |
|
632 |
start := firstIndex. |
|
633 |
start to:stop do:[:index | |
|
634 |
aTwoArgBlock value:index value:(contentsArray at:index) |
|
635 |
] |
|
636 |
||
637 |
" |
|
638 |
#(10 20 30 40) asOrderedCollection keysAndValuesDo:[:index :value | |
|
639 |
Transcript show:index; show:' '; showCr:value |
|
640 |
] |
|
641 |
" |
|
642 |
! |
|
643 |
||
644 |
reverseDo:aBlock |
|
645 |
"evaluate the argument, aBlock for every element in the collection |
|
646 |
procesing elements in reverse direction (i.e. starting with the last)" |
|
647 |
||
648 |
contentsArray from:firstIndex to:lastIndex reverseDo:aBlock |
|
1 | 649 |
! ! |
650 |
||
56 | 651 |
!OrderedCollection methodsFor:'filling & replacing'! |
13 | 652 |
|
653 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
654 |
"redefined - can be done faster" |
|
655 |
||
656 |
|end| |
|
657 |
||
658 |
end := stop + firstIndex - 1. |
|
659 |
((start >= 1) and:[end <= lastIndex]) ifTrue:[ |
|
293 | 660 |
aCollection class == self class ifTrue:[ |
661 |
contentsArray |
|
662 |
replaceFrom:(start + firstIndex - 1) |
|
663 |
to:end |
|
664 |
with:aCollection contentsArray |
|
665 |
startingAt:(repStart + aCollection firstIndex - 1). |
|
666 |
] ifFalse:[ |
|
667 |
contentsArray |
|
668 |
replaceFrom:(start + firstIndex - 1) |
|
669 |
to:end |
|
670 |
with:aCollection |
|
671 |
startingAt:repStart. |
|
672 |
]. |
|
159 | 673 |
^ self |
13 | 674 |
]. |
675 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
293 | 676 |
|
677 |
" |
|
678 |
|c| |
|
679 |
||
680 |
c := #(1 2 3 4 5 6) asOrderedCollection. |
|
681 |
c replaceFrom:3 to:6 with:c startingAt:2. |
|
682 |
c |
|
683 |
" |
|
684 |
" |
|
685 |
|c| |
|
686 |
||
687 |
c := #(1 2 3 4 5 6) asOrderedCollection. |
|
688 |
c replaceFrom:3 to:5 with:c startingAt:4. |
|
689 |
c |
|
690 |
" |
|
13 | 691 |
! ! |
692 |
||
606 | 693 |
!OrderedCollection methodsFor:'grow & shrink'! |
77 | 694 |
|
606 | 695 |
grow:newSize |
696 |
"grow the receiver to newSize" |
|
77 | 697 |
|
606 | 698 |
|oldSize newContents oldLast newLast| |
77 | 699 |
|
606 | 700 |
oldSize := lastIndex - firstIndex + 1. |
701 |
newSize ~~ oldSize ifTrue:[ |
|
702 |
newLast := firstIndex + newSize - 1. |
|
703 |
newSize < oldSize ifTrue:[ |
|
704 |
oldLast := lastIndex. |
|
705 |
lastIndex := newLast. |
|
706 |
" |
|
707 |
nil out rest, to give GC a chance to reclaim things |
|
708 |
" |
|
709 |
contentsArray from:lastIndex + 1 to:oldLast put:nil. |
|
710 |
] ifFalse:[ |
|
711 |
newLast <= contentsArray size ifTrue:[ |
|
712 |
lastIndex := newLast. |
|
713 |
^ self |
|
714 |
]. |
|
77 | 715 |
|
606 | 716 |
newContents := Array basicNew:newSize. |
717 |
newContents replaceFrom:1 to:oldSize with:contentsArray startingAt:firstIndex. |
|
718 |
contentsArray := newContents. |
|
719 |
firstIndex := 1. |
|
720 |
lastIndex := newSize |
|
721 |
] |
|
722 |
] |
|
723 |
! ! |
|
77 | 724 |
|
606 | 725 |
!OrderedCollection methodsFor:'inspecting'! |
726 |
||
727 |
inspectorClass |
|
728 |
"redefined to launch an OrderedCollectionInspector |
|
729 |
(instead of the default InspectorView)." |
|
730 |
||
731 |
^ OrderedCollectionInspectorView |
|
77 | 732 |
|
733 |
" |
|
606 | 734 |
(OrderedCollection withAll:#(3 2 1)) inspect |
735 |
(OrderedCollection withAll:#(3 2 1)) removeFirst; yourself; inspect |
|
736 |
#(0 8 15 3 99 2) asSortedCollection inspect |
|
77 | 737 |
" |
738 |
! ! |
|
739 |
||
1 | 740 |
!OrderedCollection methodsFor:'private'! |
741 |
||
606 | 742 |
initContents:size |
743 |
"setup the receiver-collection to hold size entries" |
|
33 | 744 |
|
606 | 745 |
contentsArray := Array basicNew:size. |
746 |
firstIndex := 1. |
|
747 |
lastIndex := 0 |
|
1 | 748 |
! |
749 |
||
750 |
makeRoomAtFront |
|
282 | 751 |
"grow/shift the contents for more room at the beginning. |
752 |
Does not change the logical size. |
|
753 |
i.e. |
|
754 |
#(1 2 3 4 5 6) -> #(nil 1 2 3 4 5 6)" |
|
1 | 755 |
|
756 |
|newContents |
|
33 | 757 |
oldSize "{ Class:SmallInteger }" |
758 |
newSize "{ Class:SmallInteger }" |
|
759 |
startIndex "{ Class:SmallInteger }" |
|
760 |
sz "{ Class:SmallInteger }"| |
|
1 | 761 |
|
762 |
oldSize := contentsArray size. |
|
506
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
763 |
sz := lastIndex - firstIndex + 1. |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
764 |
|
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
765 |
((oldSize == 0) or:[sz == 0]) ifTrue:[ |
253 | 766 |
contentsArray := Array basicNew:3. |
159 | 767 |
firstIndex := 2. lastIndex := 1. |
768 |
^ self |
|
93 | 769 |
]. |
770 |
||
329 | 771 |
" |
772 |
if there is lots of room at the end (> 50%), |
|
773 |
shift instead of growing. This helps collections |
|
774 |
which get elements removed at the end and added at front. |
|
775 |
" |
|
33 | 776 |
oldSize > (sz * 2) ifTrue:[ |
508 | 777 |
startIndex := oldSize // 4. |
778 |
startIndex > 1 ifTrue:[ |
|
506
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
779 |
contentsArray |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
780 |
replaceFrom:startIndex |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
781 |
to:startIndex + sz - 1 |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
782 |
with:contentsArray |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
783 |
startingAt:1. |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
784 |
contentsArray from:1 to:(startIndex - 1) put:nil. |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
785 |
firstIndex := startIndex. |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
786 |
lastIndex := startIndex + sz - 1. |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
787 |
^ self |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
788 |
] |
33 | 789 |
]. |
2 | 790 |
newSize := oldSize * 2. |
329 | 791 |
newSize == 0 ifTrue:[ newSize := 3]. |
253 | 792 |
newContents := Array basicNew:newSize. |
77 | 793 |
newContents |
159 | 794 |
replaceFrom:(oldSize + 1) |
795 |
to:newSize |
|
796 |
with:contentsArray |
|
797 |
startingAt:1. |
|
1 | 798 |
contentsArray := newContents. |
799 |
firstIndex := firstIndex + oldSize. |
|
800 |
lastIndex := lastIndex + oldSize |
|
506
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
801 |
|
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
802 |
"Created: 8.11.1995 / 12:47:49 / cg" |
1 | 803 |
! |
804 |
||
805 |
makeRoomAtIndex:index |
|
806 |
"grow the contents for inserting at index |
|
282 | 807 |
Changes the logical size. |
1 | 808 |
i.e. |
809 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:3 -> #(1 2 nil 3 4 5 6) |
|
810 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:1 -> #(nil 1 2 3 4 5 6) |
|
811 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:7 -> #(1 2 3 4 5 6 nil)" |
|
812 |
||
813 |
|newContents |
|
814 |
newSize "{ Class:SmallInteger }" |
|
815 |
oldSize "{ Class:SmallInteger }" | |
|
816 |
||
817 |
oldSize := contentsArray size. |
|
68 | 818 |
((firstIndex > 1) and:[firstIndex > (oldSize // 4)]) ifTrue:[ |
159 | 819 |
"there is room (>25%) at the beginning" |
33 | 820 |
|
159 | 821 |
index == 1 ifFalse:[ |
822 |
contentsArray |
|
823 |
replaceFrom:(firstIndex - 1) |
|
824 |
to:(index - 1) |
|
825 |
with:contentsArray |
|
826 |
startingAt:firstIndex. |
|
827 |
contentsArray at:index put:nil. |
|
828 |
]. |
|
829 |
firstIndex := firstIndex - 1. |
|
830 |
^ self |
|
33 | 831 |
]. |
832 |
lastIndex < (oldSize * 3 // 4) ifTrue:[ |
|
159 | 833 |
"there is room (>25%) at the end" |
33 | 834 |
|
159 | 835 |
index == (lastIndex + 1) ifFalse:[ |
836 |
contentsArray |
|
837 |
replaceFrom:(index + 1) |
|
838 |
to:(lastIndex + 1) |
|
839 |
with:contentsArray |
|
840 |
startingAt:index. |
|
841 |
contentsArray at:index put:nil |
|
842 |
]. |
|
843 |
lastIndex := lastIndex + 1. |
|
844 |
^ self |
|
33 | 845 |
]. |
846 |
||
847 |
newSize := oldSize * 2. |
|
253 | 848 |
newContents := Array basicNew:newSize. |
329 | 849 |
index ~~ 1 ifTrue:[ |
850 |
newContents |
|
851 |
replaceFrom:1 |
|
852 |
to:index-1 |
|
853 |
with:contentsArray |
|
854 |
startingAt:1. |
|
1 | 855 |
]. |
329 | 856 |
index ~~ newSize ifTrue:[ |
159 | 857 |
newContents |
858 |
replaceFrom:index + 1 |
|
859 |
to:oldSize + 1 |
|
860 |
with:contentsArray |
|
861 |
startingAt:index. |
|
1 | 862 |
]. |
863 |
contentsArray := newContents. |
|
864 |
lastIndex := lastIndex + 1 |
|
865 |
! |
|
866 |
||
606 | 867 |
makeRoomAtLast |
868 |
"grow/shift the contents for more room at the end. |
|
869 |
Does not change the logical size. |
|
870 |
i.e. |
|
871 |
#(1 2 3 4 5 6) -> #(1 2 3 4 5 6 nil)" |
|
872 |
||
873 |
|newContents |
|
874 |
oldSize "{ Class:SmallInteger }" |
|
875 |
newSize "{ Class:SmallInteger }" |
|
876 |
startIndex "{ Class:SmallInteger }" |
|
877 |
sz "{ Class:SmallInteger }"| |
|
878 |
||
879 |
oldSize := contentsArray size. |
|
880 |
sz := lastIndex - firstIndex + 1. |
|
881 |
||
882 |
" |
|
883 |
if there is lots of room at the beginning (> 50%), |
|
884 |
shift instead of growing. This helps collections which get |
|
885 |
elements removed at front and added at the end. |
|
886 |
" |
|
887 |
oldSize > (sz * 2) ifTrue:[ |
|
888 |
startIndex := firstIndex // 4. |
|
889 |
startIndex == 0 ifTrue:[ |
|
890 |
startIndex := 1 |
|
891 |
]. |
|
892 |
contentsArray |
|
893 |
replaceFrom:startIndex |
|
894 |
to:startIndex + sz - 1 |
|
895 |
with:contentsArray |
|
896 |
startingAt:firstIndex. |
|
897 |
contentsArray from:startIndex + sz to:lastIndex put:nil. |
|
898 |
firstIndex := startIndex. |
|
899 |
lastIndex := startIndex + sz - 1. |
|
900 |
^ self |
|
901 |
]. |
|
902 |
newSize := oldSize * 2. |
|
903 |
newSize == 0 ifTrue:[newSize := 3]. |
|
904 |
newContents := Array basicNew:newSize. |
|
905 |
newContents |
|
906 |
replaceFrom:1 |
|
907 |
to:oldSize |
|
908 |
with:contentsArray |
|
909 |
startingAt:1. |
|
910 |
contentsArray := newContents |
|
911 |
! |
|
912 |
||
913 |
setFirstIndex:newFirstIndex lastIndex:newLastIndex |
|
914 |
"set first and last index" |
|
915 |
||
916 |
firstIndex := newFirstIndex. |
|
917 |
lastIndex := newLastIndex. |
|
918 |
! ! |
|
919 |
||
920 |
!OrderedCollection methodsFor:'private accessing'! |
|
921 |
||
922 |
contentsArray |
|
923 |
^ contentsArray |
|
924 |
! |
|
925 |
||
926 |
firstIndex |
|
927 |
^ firstIndex |
|
928 |
! ! |
|
929 |
||
930 |
!OrderedCollection methodsFor:'queries'! |
|
931 |
||
932 |
capacity |
|
933 |
"return the number of elements, that the receiver is |
|
934 |
prepared to take. |
|
935 |
Not used by the system; added for ST-80 compatibility." |
|
936 |
||
937 |
^ contentsArray size |
|
938 |
! |
|
939 |
||
940 |
isEmpty |
|
941 |
"return true, if the receiver has no elements" |
|
942 |
||
943 |
^ lastIndex < firstIndex |
|
944 |
! |
|
945 |
||
946 |
isFixedSize |
|
947 |
"return true if the receiver cannot grow - this will vanish once |
|
948 |
Arrays and Strings learn how to grow ..." |
|
40 | 949 |
|
606 | 950 |
^ false |
951 |
! |
|
952 |
||
953 |
notEmpty |
|
954 |
"return true, if the receiver has any elements" |
|
955 |
||
956 |
^ lastIndex >= firstIndex |
|
957 |
! |
|
958 |
||
959 |
size |
|
960 |
"return the number of elements in the collection" |
|
961 |
||
962 |
^ lastIndex - firstIndex + 1 |
|
963 |
! ! |
|
964 |
||
965 |
!OrderedCollection methodsFor:'searching'! |
|
966 |
||
967 |
after:anObject |
|
968 |
"return the element, after anObject. |
|
969 |
If anObject is not in the receiver, report an error." |
|
970 |
||
971 |
^ self after:anObject ifAbsent:[self errorValueNotFound:anObject] |
|
972 |
||
973 |
" |
|
974 |
#(4 3 2 1) asOrderedCollection after:3. |
|
975 |
#(4 3 2 1) asOrderedCollection after:5 |
|
976 |
#(4 3 2 1) asOrderedCollection after:1 |
|
977 |
" |
|
978 |
! |
|
979 |
||
980 |
after:anObject ifAbsent:exceptionBlock |
|
981 |
"return the element after the argument anObject, nil if there is none. |
|
982 |
If anObject is not in the receiver, return the result from evaluating exceptionBlock." |
|
983 |
||
984 |
|idx| |
|
985 |
||
986 |
idx := self indexOf:anObject. |
|
987 |
idx ~~ 0 ifTrue:[ |
|
988 |
idx == lastIndex ifTrue:[^ nil]. |
|
989 |
^ self at:(idx + 1). |
|
990 |
]. |
|
991 |
^ exceptionBlock value |
|
992 |
||
993 |
" |
|
994 |
#(4 3 2 1) asOrderedCollection after:3. |
|
995 |
#(4 3 2 1) asOrderedCollection after:5 |
|
996 |
#(4 3 2 1) asOrderedCollection after:1 |
|
997 |
" |
|
998 |
! |
|
999 |
||
1000 |
before:anObject |
|
1001 |
"return the element before the argument, anObject. |
|
1002 |
If anObject is not in the receiver, report an error." |
|
1003 |
||
1004 |
^ self before:anObject ifAbsent:[self errorValueNotFound:anObject] |
|
1005 |
||
1006 |
" |
|
1007 |
#(4 3 2 1) asOrderedCollection before:3. |
|
1008 |
#(4 3 2 1) asOrderedCollection before:4 |
|
1009 |
#(4 3 2 1) asOrderedCollection before:0 |
|
1010 |
" |
|
1011 |
! |
|
1012 |
||
1013 |
before:anObject ifAbsent:exceptionBlock |
|
1014 |
"return the element before the argument anObject, nil if there is none. |
|
1015 |
If anObject is not in the receiver, return the result from evaluating exceptionBlock." |
|
1016 |
||
1017 |
|idx| |
|
1018 |
||
1019 |
idx := self indexOf:anObject. |
|
1020 |
idx ~~ 0 ifTrue:[ |
|
1021 |
idx == firstIndex ifTrue:[^ nil]. |
|
1022 |
^ self at:(idx - 1). |
|
1023 |
]. |
|
1024 |
^ exceptionBlock value |
|
1025 |
||
1026 |
" |
|
1027 |
#(4 3 2 1) asOrderedCollection before:3. |
|
1028 |
#(4 3 2 1) asOrderedCollection before:5 |
|
1029 |
#(4 3 2 1) asOrderedCollection before:1 |
|
1030 |
#(4 3 2 1) asOrderedCollection before:4 |
|
1031 |
" |
|
1 | 1032 |
! ! |
1033 |
||
1034 |
!OrderedCollection methodsFor:'testing'! |
|
1035 |
||
1036 |
identityIndexOf:anObject |
|
33 | 1037 |
"return the index of anObject or 0 if not found. Compare using ==" |
1 | 1038 |
|
33 | 1039 |
|index "{ Class:SmallInteger }"| |
1 | 1040 |
|
13 | 1041 |
index := contentsArray identityIndexOf:anObject startingAt:firstIndex. |
33 | 1042 |
((index < firstIndex) or:[index > lastIndex]) ifTrue:[^ 0]. |
1 | 1043 |
^ index - firstIndex + 1 |
1044 |
! |
|
1045 |
||
1046 |
identityIndexOf:anObject startingAt:startIndex |
|
33 | 1047 |
"return the index of anObject, starting search at startIndex. |
1048 |
Compare using ==; return 0 if not found in the collection" |
|
1 | 1049 |
|
33 | 1050 |
|index "{ Class:SmallInteger }"| |
1 | 1051 |
|
1052 |
index := contentsArray identityIndexOf:anObject startingAt:(startIndex + firstIndex - 1). |
|
33 | 1053 |
((index < firstIndex) or:[index > lastIndex]) ifTrue:[^ 0]. |
1 | 1054 |
^ index - firstIndex + 1 |
1055 |
! |
|
1056 |
||
606 | 1057 |
includes:anObject |
1058 |
"return true if anObject is in the collection. Compare using =" |
|
1059 |
||
1060 |
|index "{ Class:SmallInteger }"| |
|
1061 |
||
1062 |
index := contentsArray indexOf:anObject startingAt:firstIndex. |
|
1063 |
((index < firstIndex) or:[index > lastIndex]) ifTrue:[^ false]. |
|
1064 |
^ true |
|
1065 |
! |
|
1066 |
||
1 | 1067 |
indexOf:anObject |
33 | 1068 |
"return the index of anObject or 0 if not found in the collection. |
1069 |
Compare using =" |
|
1 | 1070 |
|
33 | 1071 |
|index "{ Class:SmallInteger }"| |
1 | 1072 |
|
13 | 1073 |
index := contentsArray indexOf:anObject startingAt:firstIndex. |
33 | 1074 |
((index < firstIndex) or:[index > lastIndex]) ifTrue:[^ 0]. |
1 | 1075 |
^ index - firstIndex + 1 |
1076 |
! |
|
1077 |
||
1078 |
indexOf:anObject startingAt:startIndex |
|
33 | 1079 |
"return the index of anObject, starting search at startIndex. |
1080 |
Compare using =; return 0 if not found in the collection" |
|
1 | 1081 |
|
33 | 1082 |
|index "{ Class:SmallInteger }"| |
1 | 1083 |
|
1084 |
index := contentsArray indexOf:anObject startingAt:(startIndex + firstIndex - 1). |
|
33 | 1085 |
((index < firstIndex) or:[index > lastIndex]) ifTrue:[^ 0]. |
1 | 1086 |
^ index - firstIndex + 1 |
1087 |
! ! |
|
1088 |