author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2013 10:35:54 +0200 | |
changeset 15442 | 5ae3f8265977 |
parent 15401 | 813953f5abf3 |
child 15660 | 3143ca7c443a |
child 18070 | d262e3aecaca |
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 |
" |
|
5401 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
SequenceableCollection subclass:#OrderedCollection |
1071 | 15 |
instanceVariableNames:'contentsArray firstIndex lastIndex' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Sequenceable' |
|
1 | 19 |
! |
20 |
||
33 | 21 |
!OrderedCollection class methodsFor:'documentation'! |
22 |
||
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
33 | 37 |
documentation |
38 |
" |
|
1387 | 39 |
OrderedCollections (OCs) have their elements ordered as they were |
40 |
added. In addition, they provide all indexing access protocol |
|
41 |
and bulk copying (much like Arrays). |
|
42 |
||
1324 | 43 |
Insertion and removal at both ends is possible and reasonably |
44 |
fast - therefore they can be used for queues and stacks. |
|
45 |
||
1387 | 46 |
[Instance variables:] |
47 |
contentsArray <Array> the actual contents |
|
48 |
||
49 |
firstIndex <SmallInteger> index of first valid element |
|
50 |
||
51 |
lastIndex <SmallInteger> index of last valid element |
|
52 |
||
53 |
||
54 |
[performance hint:] |
|
1324 | 55 |
Although insertion and removal of inner elements is possible and supported, |
56 |
it may be slow, because remaining elements have to be copied. |
|
1387 | 57 |
If many elements have to be removed out of the middle of a big OC, |
14919 | 58 |
it is often faster to create a new OC from scratch or to use another collection |
59 |
class (SegmentedOrderedCollection) which is specialized for this kind of usage. |
|
1324 | 60 |
|
1 | 61 |
|
1387 | 62 |
[beginners bug hint:] |
63 |
notice that: |
|
64 |
Array new:n |
|
65 |
is quite different from: |
|
66 |
OrderedCollection new:n |
|
1290 | 67 |
|
1387 | 68 |
The later creates an OC which is prepared to hold <n> elements, |
69 |
but has a logical size of 0 (zero). To get an OC containing <n> nils, |
|
70 |
use: |
|
71 |
(OrderedCollection new) grow:n |
|
72 |
||
1 | 73 |
|
4064 | 74 |
[memory requirements:] |
75 |
OBJ-HEADER + (3 * ptr-size) |
|
76 |
+ (size-roundedUpToNextPowerOf2 * ptr-size) |
|
77 |
||
1290 | 78 |
[see also:] |
79 |
Array |
|
80 |
||
81 |
[author:] |
|
82 |
Claus Gittinger |
|
33 | 83 |
" |
1321 | 84 |
! |
85 |
||
86 |
examples |
|
87 |
" |
|
1387 | 88 |
using OC as a stack: |
1321 | 89 |
[exBegin] |
1387 | 90 |
|stack top| |
1321 | 91 |
|
1387 | 92 |
stack := OrderedCollection new. |
1321 | 93 |
|
1387 | 94 |
1 to:10 do:[:i | |
95 |
stack add:i |
|
96 |
]. |
|
1321 | 97 |
|
1387 | 98 |
10 timesRepeat:[ |
99 |
top := stack removeLast. |
|
1422 | 100 |
Transcript showCR:top |
1387 | 101 |
] |
1321 | 102 |
[exEnd] |
1387 | 103 |
using OC as a queue (you should use Queue right away ..): |
1321 | 104 |
[exBegin] |
1387 | 105 |
|queue dequeued| |
1321 | 106 |
|
1387 | 107 |
queue := OrderedCollection new. |
1321 | 108 |
|
1387 | 109 |
1 to:10 do:[:i | |
110 |
queue addLast:i |
|
111 |
]. |
|
1321 | 112 |
|
1387 | 113 |
10 timesRepeat:[ |
114 |
dequeued := queue removeFirst. |
|
1422 | 115 |
Transcript showCR:dequeued |
1387 | 116 |
] |
1321 | 117 |
[exEnd] |
1324 | 118 |
|
119 |
||
1387 | 120 |
examples to support the performance hint (see documentation) |
1324 | 121 |
|
122 |
timing removal of all odd elements in a collection of 10000: |
|
123 |
(940 ms on P5/133) |
|
124 |
[exBegin] |
|
125 |
|coll time| |
|
126 |
||
127 |
coll := (1 to:10000) asOrderedCollection. |
|
128 |
time := Time millisecondsToRun:[ |
|
129 |
coll removeAllSuchThat:[:el | el even] |
|
130 |
]. |
|
1422 | 131 |
Transcript show:'time is '; show:time; showCR:' ms'. |
1324 | 132 |
[exEnd] |
133 |
||
1387 | 134 |
tuning the removal by doing it reverse |
135 |
(less copying in #removeAtIndex:) speeds it up by a factor of 2: |
|
1324 | 136 |
[exBegin] |
137 |
|coll time| |
|
138 |
||
139 |
coll := (1 to:10000) asOrderedCollection. |
|
140 |
time := Time millisecondsToRun:[ |
|
141 |
coll size to:1 by:-1 do:[:index | |
|
142 |
(coll at:index) even ifTrue:[ |
|
143 |
coll removeAtIndex:index |
|
144 |
] |
|
145 |
] |
|
146 |
]. |
|
1422 | 147 |
Transcript show:'time is '; show:time; showCR:' ms'. |
1324 | 148 |
[exEnd] |
149 |
||
1387 | 150 |
rebuilding a new collection: |
1324 | 151 |
(64 ms on P5/133) |
152 |
[exBegin] |
|
153 |
|coll time| |
|
154 |
||
155 |
coll := (1 to:10000) asOrderedCollection. |
|
156 |
time := Time millisecondsToRun:[ |
|
157 |
coll := coll select:[:el | el odd] |
|
158 |
]. |
|
1422 | 159 |
Transcript show:'time is '; show:time; showCR:' ms'. |
1324 | 160 |
[exEnd] |
11271 | 161 |
|
162 |
adding at the end (fast): |
|
163 |
[exBegin] |
|
164 |
|coll time| |
|
165 |
||
166 |
coll := OrderedCollection new. |
|
167 |
time := TimeDuration toRun:[ |
|
168 |
(1 to:100000) do:[:el | coll add:el]. |
|
169 |
]. |
|
170 |
Transcript show:'time is '; showCR:time. |
|
171 |
self assert:(coll = (1 to:100000)). |
|
172 |
self assert:(coll asBag = (1 to:100000) asBag). |
|
173 |
[exEnd] |
|
174 |
adding at front (fast): |
|
175 |
[exBegin] |
|
176 |
|coll time| |
|
177 |
||
178 |
coll := OrderedCollection new. |
|
179 |
time := TimeDuration toRun:[ |
|
180 |
(1 to:100000) reverseDo:[:el | coll addFirst:el]. |
|
181 |
]. |
|
182 |
Transcript show:'time is '; showCR:time. |
|
183 |
self assert:(coll = (1 to:100000)). |
|
184 |
self assert:(coll asBag = (1 to:100000) asBag). |
|
185 |
[exEnd] |
|
186 |
inserting in the middle (slow): |
|
187 |
[exBegin] |
|
188 |
|coll time| |
|
189 |
||
190 |
coll := OrderedCollection new. |
|
191 |
time := TimeDuration toRun:[ |
|
192 |
(1 to:100000) do:[:el | coll add:el beforeIndex:(coll size // 2)+1 ]. |
|
193 |
]. |
|
194 |
Transcript show:'time is '; showCR:time. |
|
195 |
self assert:(coll asBag = (1 to:100000) asBag). |
|
196 |
[exEnd] |
|
1321 | 197 |
" |
33 | 198 |
! ! |
1 | 199 |
|
200 |
!OrderedCollection class methodsFor:'instance creation'! |
|
201 |
||
202 |
new |
|
1106 | 203 |
"create a new, empty OrderedCollection" |
1 | 204 |
|
205 |
^ (self basicNew) initContents:10 |
|
1106 | 206 |
|
207 |
"Modified: 19.3.1996 / 17:53:12 / cg" |
|
293 | 208 |
! |
209 |
||
606 | 210 |
new:size |
1106 | 211 |
"create a new, empty OrderedCollection with a preallocated physical |
212 |
size. |
|
213 |
NOTICE: |
|
214 |
the logical size of the returned collection is 0 (i.e. it is empty). |
|
215 |
This may be confusing, in that it is different from what Array>>new: |
|
216 |
returns. |
|
217 |
" |
|
606 | 218 |
|
219 |
^ (self basicNew) initContents:(size max:3) |
|
1106 | 220 |
|
221 |
"Modified: 19.3.1996 / 17:53:47 / cg" |
|
4427 | 222 |
! |
223 |
||
6700
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
224 |
new:size withAll:element |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
225 |
"return a new collection of size, where all elements are |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
226 |
initialized to element." |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
227 |
|
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
228 |
|newCollection| |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
229 |
|
9160 | 230 |
newCollection := self withSize:size. |
6700
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
231 |
newCollection atAllPut:element. |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
232 |
^ newCollection |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
233 |
|
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
234 |
" |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
235 |
OrderedCollection new:10 withAll:1234 |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
236 |
" |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
237 |
! |
e4254778c239
new:withAll: redefined to work around the wierd new: behavior.
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
238 |
|
4427 | 239 |
newFrom:aCollection |
240 |
"return a new OrderedCollection filled with all elements from the argument, |
|
241 |
aCollection" |
|
242 |
||
243 |
|newColl| |
|
244 |
||
245 |
newColl := self new:(aCollection size). |
|
246 |
newColl addAll:aCollection. |
|
247 |
^ newColl |
|
248 |
||
249 |
" |
|
250 |
OrderedCollection newFrom:#(1 2 3 4) |
|
251 |
OrderedCollection newFrom:(Set with:1 with:2 with:3) |
|
252 |
" |
|
293 | 253 |
! ! |
254 |
||
606 | 255 |
!OrderedCollection methodsFor:'accessing'! |
1 | 256 |
|
606 | 257 |
at:anInteger |
258 |
"return the element at index, anInteger" |
|
1 | 259 |
|
3107 | 260 |
|idx "{ Class: SmallInteger }"| |
387 | 261 |
|
606 | 262 |
idx := anInteger + firstIndex - 1. |
263 |
((anInteger < 1) or:[idx > lastIndex]) ifTrue:[ |
|
3107 | 264 |
^ self subscriptBoundsError:anInteger |
265 |
]. |
|
266 |
^ contentsArray basicAt:idx |
|
267 |
||
268 |
"Modified: / 12.11.1997 / 17:56:05 / cg" |
|
360 | 269 |
! |
270 |
||
606 | 271 |
at:anInteger put:anObject |
1221 | 272 |
"set the element at index, to be anInteger. |
273 |
Return anObject (sigh)." |
|
1 | 274 |
|
3107 | 275 |
|idx "{ Class: SmallInteger }"| |
1 | 276 |
|
606 | 277 |
idx := anInteger + firstIndex - 1. |
278 |
((anInteger < 1) or:[idx > lastIndex]) ifTrue:[ |
|
1221 | 279 |
^ self subscriptBoundsError:anInteger |
3107 | 280 |
]. |
281 |
^ contentsArray basicAt:idx put:anObject |
|
1221 | 282 |
|
3107 | 283 |
"Modified: / 12.11.1997 / 17:56:32 / cg" |
202 | 284 |
! |
285 |
||
606 | 286 |
first |
287 |
"return the first element" |
|
1 | 288 |
|
606 | 289 |
firstIndex <= lastIndex ifTrue:[ |
290 |
^ contentsArray at:firstIndex |
|
1 | 291 |
]. |
606 | 292 |
"error if collection is empty" |
293 |
^ self emptyCollectionError |
|
2 | 294 |
|
93 | 295 |
" |
606 | 296 |
(OrderedCollection withAll:#(1 2 3 4 5)) first |
297 |
(SortedCollection withAll:#(5 4 3 2 1)) first |
|
93 | 298 |
" |
13 | 299 |
! |
300 |
||
606 | 301 |
last |
302 |
"return the last element" |
|
68 | 303 |
|
606 | 304 |
firstIndex <= lastIndex ifTrue:[ |
305 |
^ contentsArray at:lastIndex |
|
306 |
]. |
|
307 |
"error if collection is empty" |
|
308 |
^ self emptyCollectionError |
|
68 | 309 |
|
93 | 310 |
" |
606 | 311 |
(OrderedCollection withAll:#(1 2 3 4 5)) last |
312 |
(SortedCollection withAll:#(5 4 3 2 1)) last |
|
93 | 313 |
" |
1 | 314 |
! ! |
315 |
||
316 |
!OrderedCollection methodsFor:'adding & removing'! |
|
317 |
||
606 | 318 |
add:anObject |
319 |
"add the argument, anObject to the end of the collection |
|
320 |
Return the argument, anObject." |
|
321 |
||
322 |
|idx "{ Class:SmallInteger }"| |
|
1 | 323 |
|
606 | 324 |
idx := lastIndex. |
1 | 325 |
|
606 | 326 |
(idx == contentsArray size) ifTrue:[ |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
327 |
self makeRoomAtLast. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
328 |
idx := lastIndex. |
42 | 329 |
]. |
3107 | 330 |
lastIndex := idx := idx + 1. |
331 |
contentsArray basicAt:idx put:anObject. |
|
1 | 332 |
^ anObject |
42 | 333 |
|
348 | 334 |
" |
606 | 335 |
|c| |
336 |
c := #(4 3 2 1) asOrderedCollection. |
|
337 |
c add:'here' |
|
348 | 338 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
339 |
|
3107 | 340 |
"Modified: / 12.11.1997 / 17:49:47 / cg" |
1 | 341 |
! |
342 |
||
606 | 343 |
add:newObject after:oldObject |
344 |
"insert the argument, newObject after oldObject. |
|
345 |
If oldObject is not in the receiver, report an error, |
|
346 |
otherwise return the argument, anObject." |
|
1 | 347 |
|
606 | 348 |
|idx| |
1 | 349 |
|
606 | 350 |
idx := self indexOf:oldObject. |
351 |
idx ~~ 0 ifTrue:[ |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
352 |
self add:newObject beforeIndex:(idx + 1). |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
353 |
^ newObject |
42 | 354 |
]. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
355 |
^ self errorValueNotFound:oldObject |
42 | 356 |
|
348 | 357 |
" |
606 | 358 |
|c| |
359 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
360 |
c add:'here' after:3; yourself. |
606 | 361 |
" |
362 |
" |
|
363 |
|c| |
|
364 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
365 |
c add:'here' after:1; yourself. |
606 | 366 |
" |
367 |
" |
|
368 |
|c| |
|
369 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
370 |
c add:'here' after:5; yourself |
606 | 371 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
372 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
373 |
"Modified: 12.4.1996 / 13:51:56 / cg" |
606 | 374 |
! |
375 |
||
376 |
add:anObject afterIndex:index |
|
377 |
"insert the argument, anObject to become located at index. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
378 |
Return the receiver (sigh - ST-80 compatibility)." |
606 | 379 |
|
380 |
^ self add:anObject beforeIndex:(index + 1) |
|
381 |
||
382 |
" |
|
383 |
|c| |
|
384 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
385 |
c add:'here' afterIndex:2 |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
386 |
" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
387 |
" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
388 |
|c| |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
389 |
c := #(4 3 2 1) asOrderedCollection. |
606 | 390 |
c add:'here' afterIndex:4 |
348 | 391 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
392 |
" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
393 |
|c| |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
394 |
c := #(4 3 2 1) asOrderedCollection. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
395 |
c add:'here' afterIndex:0 |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
396 |
" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
397 |
" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
398 |
|c| |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
399 |
c := #(4 3 2 1) asOrderedCollection. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
400 |
c add:'here' afterIndex:5 |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
401 |
" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
402 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
403 |
"Modified: 12.4.1996 / 13:52:41 / cg" |
348 | 404 |
! |
405 |
||
606 | 406 |
add:newObject before:oldObject |
407 |
"insert the argument, newObject before oldObject. |
|
408 |
If oldObject is not in the receiver, report an error, |
|
409 |
otherwise return the argument, anObject." |
|
348 | 410 |
|
606 | 411 |
|idx| |
348 | 412 |
|
606 | 413 |
idx := self indexOf:oldObject. |
414 |
idx ~~ 0 ifTrue:[ |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
415 |
self add:newObject beforeIndex:idx. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
416 |
^ newObject |
348 | 417 |
]. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
418 |
^ self errorValueNotFound:oldObject |
348 | 419 |
|
420 |
" |
|
606 | 421 |
|c| |
422 |
c := #(4 3 2 1) asOrderedCollection. |
|
423 |
c add:'here' before:3. |
|
424 |
c add:'here' before:5 |
|
348 | 425 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
426 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
427 |
"Modified: 12.4.1996 / 13:25:47 / cg" |
348 | 428 |
! |
429 |
||
606 | 430 |
add:anObject beforeIndex:index |
431 |
"insert the argument, anObject to become located at index. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
432 |
Return the receiver (sigh - ST-80 compatibility)." |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
433 |
|
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
434 |
|idx physicalIndex| |
348 | 435 |
|
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
436 |
physicalIndex := index + firstIndex - 1. |
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
437 |
physicalIndex > lastIndex ifTrue:[ |
10839
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
438 |
"can only add to the end of the collection" |
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
439 |
physicalIndex == (lastIndex+1) ifTrue:[ |
10839
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
440 |
idx := lastIndex. |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
441 |
(idx == contentsArray size) ifTrue:[ |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
442 |
self makeRoomAtLast. |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
443 |
idx := lastIndex. |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
444 |
]. |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
445 |
lastIndex := idx := idx + 1. |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
446 |
] ifFalse:[ |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
447 |
^ self subscriptBoundsError:index. |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
448 |
] |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
449 |
] ifFalse:[ |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
450 |
"notice: this may change firstIndex" |
285fa5534f61
#add:beforeIndex: take care for redefinitions of #add: in subclasses sending #add:beforeIndex:
Stefan Vogel <sv@exept.de>
parents:
10799
diff
changeset
|
451 |
idx := self makeRoomAtIndex:physicalIndex. |
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
452 |
]. |
3107 | 453 |
contentsArray basicAt:idx put:anObject. |
348 | 454 |
|
455 |
" |
|
606 | 456 |
|c| |
457 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
458 |
c add:'here' beforeIndex:3 |
606 | 459 |
" |
460 |
" |
|
461 |
|c| |
|
462 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
463 |
c add:'here' beforeIndex:1 |
606 | 464 |
" |
465 |
" |
|
466 |
|c| |
|
467 |
c := #(4 3 2 1) asOrderedCollection. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
468 |
c add:'here' beforeIndex:5 |
348 | 469 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
470 |
|
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
471 |
"Modified: / 28.1.1998 / 17:17:48 / cg" |
1 | 472 |
! |
473 |
||
3109 | 474 |
addAll:aCollection |
7752 | 475 |
"add all elements of the argument, aCollection to the receiver. |
476 |
Returns the argument, aCollection (sigh)." |
|
3109 | 477 |
|
478 |
self addAll:aCollection beforeIndex:(1 + self size). |
|
479 |
^ aCollection |
|
480 |
! |
|
481 |
||
15442 | 482 |
addAll:aCollection afterIndex:index |
483 |
"insert the argument, anObject to become located after index. |
|
484 |
Return the receiver (sigh - ST-80 compatibility)." |
|
485 |
||
486 |
^ self addAll:aCollection beforeIndex:(index + 1) |
|
487 |
||
488 |
" |
|
489 |
|c| |
|
490 |
c := #(4 3 2 1) asOrderedCollection. |
|
491 |
c addAll:#(10 20 30) afterIndex:2 |
|
492 |
" |
|
493 |
" |
|
494 |
|c| |
|
495 |
c := #(4 3 2 1) asOrderedCollection. |
|
496 |
c addAll:#(10 20 30) afterIndex:4 |
|
497 |
" |
|
498 |
" |
|
499 |
|c| |
|
500 |
c := #(4 3 2 1) asOrderedCollection. |
|
501 |
c addAll:#(10 20 30) afterIndex:0 |
|
502 |
" |
|
503 |
||
504 |
"Modified: 12.4.1996 / 13:52:41 / cg" |
|
505 |
! |
|
506 |
||
2222 | 507 |
addAll:aCollection beforeIndex:index |
508 |
"insert all elements of the argument, anObject to become located at index. |
|
509 |
The collection may be unordered, but then order of the sliced-in elements |
|
510 |
is undefined. |
|
511 |
Return the receiver." |
|
512 |
||
513 |
|idx count| |
|
514 |
||
515 |
aCollection isSequenceable ifTrue:[ |
|
516 |
"/ we are lucky - that thing can count & do bulk copies |
|
517 |
||
518 |
count := aCollection size. |
|
2549 | 519 |
idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count. |
2222 | 520 |
"/ notice: the above may change firstIndex |
521 |
contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1. |
|
522 |
^ self |
|
523 |
]. |
|
524 |
||
525 |
idx := index. |
|
526 |
aCollection do:[:element | |
|
527 |
self add:element beforeIndex:idx. |
|
528 |
idx := idx + 1. |
|
529 |
]. |
|
530 |
||
531 |
" |
|
532 |
|c| |
|
533 |
c := #(1 2 3 4) asOrderedCollection. |
|
534 |
c addAll:'here' beforeIndex:3 |
|
535 |
" |
|
536 |
" |
|
537 |
|c| |
|
538 |
c := #(1 2 3 4) asOrderedCollection. |
|
2549 | 539 |
c removeFirst. |
540 |
c addAll:'here' beforeIndex:3 |
|
541 |
" |
|
542 |
" |
|
543 |
|c| |
|
544 |
c := #(1 2 3 4) asOrderedCollection. |
|
2222 | 545 |
c addAll:'here' beforeIndex:1 |
546 |
" |
|
547 |
" |
|
548 |
|c| |
|
549 |
c := #(1 2 3 4) asOrderedCollection. |
|
550 |
c addAll:'here' beforeIndex:5 |
|
551 |
" |
|
552 |
||
553 |
" |
|
554 |
|c| |
|
555 |
c := #(1 2 3 4) asOrderedCollection. |
|
556 |
c addAll:('hello' asSet) beforeIndex:3 |
|
557 |
" |
|
558 |
||
2549 | 559 |
"Modified: 15.4.1997 / 12:43:59 / cg" |
2222 | 560 |
! |
561 |
||
606 | 562 |
addFirst:anObject |
563 |
"add the argument, anObject to the beginning of the collection. |
|
564 |
Return the argument, anObject." |
|
56 | 565 |
|
3107 | 566 |
|idx "{ Class:SmallInteger }"| |
567 |
||
568 |
(idx := firstIndex) == 1 ifTrue:[ |
|
569 |
self makeRoomAtFront. |
|
570 |
idx := firstIndex. |
|
348 | 571 |
]. |
3107 | 572 |
firstIndex := idx := idx - 1. |
573 |
contentsArray basicAt:idx put:anObject. |
|
606 | 574 |
^ anObject |
56 | 575 |
|
576 |
" |
|
606 | 577 |
|c| |
578 |
c := #(1 2 3 4) asOrderedCollection. |
|
579 |
c addFirst:'here'. |
|
580 |
c |
|
581 |
" |
|
582 |
||
583 |
" |
|
584 |
|c| |
|
585 |
c := #() asOrderedCollection. |
|
586 |
c addFirst:'here'. |
|
587 |
c |
|
56 | 588 |
" |
3107 | 589 |
|
590 |
"Modified: / 12.11.1997 / 17:58:05 / cg" |
|
591 |
! |
|
592 |
||
3368 | 593 |
clearContents |
594 |
"remove all elements from the collection but keep the contentsArray. |
|
595 |
Useful for huge lists, if the contents will be rebuild soon (using #add:) |
|
596 |
to a size which is similar to the lists current size. |
|
597 |
Returns the receiver." |
|
598 |
||
599 |
"/ clear those references, to give the garbage collector |
|
600 |
"/ a chance ... |
|
601 |
||
602 |
firstIndex >= lastIndex ifTrue:[ |
|
603 |
contentsArray from:firstIndex to:lastIndex put:nil. |
|
604 |
]. |
|
605 |
firstIndex := 1. |
|
606 |
lastIndex := 0. |
|
607 |
||
608 |
"/ this is the same as: |
|
609 |
"/ self initContents:(self size) |
|
610 |
||
611 |
"Modified: 12.4.1996 / 13:34:19 / cg" |
|
612 |
! |
|
613 |
||
1 | 614 |
remove:anObject ifAbsent:exceptionBlock |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
615 |
"remove the first element which is equal to anObject; |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
616 |
if found, remove and return it; |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
617 |
if not, return the value from evaluating exceptionBlock. |
2362 | 618 |
Uses equality compare (=) to search for the element." |
1 | 619 |
|
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
620 |
|index retVal| |
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
621 |
|
12035 | 622 |
index := self indexOf:anObject. |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
623 |
index ~~ 0 ifTrue:[ |
12035 | 624 |
retVal := contentsArray at:index+firstIndex-1. |
2361
dd95b53674e9
oops - removeIdentical was wrong
Claus Gittinger <cg@exept.de>
parents:
2355
diff
changeset
|
625 |
self removeFromIndex:index toIndex:index. |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
626 |
^ retVal |
1 | 627 |
]. |
628 |
^ exceptionBlock value |
|
348 | 629 |
|
630 |
" |
|
12035 | 631 |
#(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:[self halt]; yourself |
632 |
#(1 2 3 4 5) asOrderedCollection remove:3 ifAbsent:[self halt]; yourself |
|
1496 | 633 |
|
12035 | 634 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection remove:3 ifAbsent:'oops' |
348 | 635 |
#(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:'oops' |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
636 |
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops' |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
637 |
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops' |
348 | 638 |
" |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
639 |
|
2362 | 640 |
"Modified: 8.2.1997 / 19:17:19 / cg" |
1 | 641 |
! |
642 |
||
114 | 643 |
removeAll |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
644 |
"remove all elements from the collection. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
645 |
Returns the receiver." |
114 | 646 |
|
15401 | 647 |
contentsArray size <= 20 ifTrue:[ |
648 |
"/ reuse the contents array |
|
649 |
contentsArray atAllPut:nil. |
|
650 |
firstIndex := 1. |
|
651 |
lastIndex := 0. |
|
652 |
] ifFalse:[ |
|
653 |
self initContents:10 |
|
654 |
]. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
655 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
656 |
"Modified: 12.4.1996 / 13:34:19 / cg" |
114 | 657 |
! |
658 |
||
348 | 659 |
removeAllSuchThat:aBlock |
660 |
"remove all elements that meet a test criteria as specified in aBlock. |
|
661 |
The argument, aBlock is evaluated for successive elements and all those, |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
662 |
for which it returns true, are removed. |
1496 | 663 |
Return a collection containing the removed elements. |
664 |
||
665 |
Performance hint: |
|
2362 | 666 |
if a large number of objects is to be removed this way, |
1496 | 667 |
it may be better to rebuild a new collection via #select:, |
668 |
since removing elements out of the middle is somewhat slow |
|
2362 | 669 |
due to the need to copy over remaining elements within the collection." |
348 | 670 |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
671 |
"/ this is a q&d implementation (possibly slow). |
348 | 672 |
|
2362 | 673 |
|runIndex removed element sz| |
348 | 674 |
|
8779
0f5b343312b4
removeAllSuchThat: returns OrderedCollection not spezies new
penk
parents:
7752
diff
changeset
|
675 |
removed := OrderedCollection new. |
348 | 676 |
|
677 |
runIndex := 1. |
|
2362 | 678 |
sz := self size. |
679 |
[runIndex <= sz] whileTrue:[ |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
680 |
element := self at:runIndex. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
681 |
(aBlock value:element) ifTrue:[ |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
682 |
removed add:element. |
2362 | 683 |
self removeAtIndex:runIndex. |
684 |
sz := sz - 1. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
685 |
] ifFalse:[ |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
686 |
runIndex := runIndex + 1 |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
687 |
] |
348 | 688 |
]. |
689 |
^ removed |
|
690 |
||
691 |
" |
|
692 |
|coll| |
|
693 |
||
694 |
coll := OrderedCollection withAll:(1 to:10). |
|
1422 | 695 |
Transcript showCR:(coll removeAllSuchThat:[:el | el even]). |
696 |
Transcript showCR:coll |
|
348 | 697 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
698 |
|
2362 | 699 |
"Modified: 8.2.1997 / 19:19:00 / cg" |
348 | 700 |
! |
701 |
||
606 | 702 |
removeFirst |
3695 | 703 |
"remove the first element from the collection; return the element. |
704 |
If there is no element in the receiver collection, raise an error." |
|
202 | 705 |
|
3968 | 706 |
|anObject |
707 |
fI "{ Class: SmallInteger }" | |
|
13 | 708 |
|
2362 | 709 |
fI := firstIndex. |
710 |
||
711 |
fI > lastIndex ifTrue:[ |
|
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
712 |
"error if collection is empty" |
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
713 |
^ self emptyCollectionError. |
606 | 714 |
]. |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
715 |
|
3107 | 716 |
anObject := contentsArray basicAt:fI. |
1496 | 717 |
|
718 |
"/ nil it out, to allow GC to reclaim it. |
|
3107 | 719 |
contentsArray basicAt:fI put:nil. |
1496 | 720 |
|
2362 | 721 |
fI := fI + 1. |
1 | 722 |
|
2362 | 723 |
fI > lastIndex ifTrue:[ |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
724 |
"reset to avoid ever growing" |
2362 | 725 |
fI := 1. |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
726 |
lastIndex := 0 |
1 | 727 |
]. |
2362 | 728 |
firstIndex := fI. |
1 | 729 |
^ anObject |
13 | 730 |
|
731 |
" |
|
606 | 732 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself |
733 |
OrderedCollection new removeFirst |
|
734 |
(SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself |
|
93 | 735 |
" |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
736 |
|
3968 | 737 |
"Modified: / 5.2.1999 / 23:22:58 / cg" |
606 | 738 |
! |
739 |
||
740 |
removeFirst:n |
|
741 |
"remove the first n elements from the collection; |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
742 |
Return a collection containing the removed elements." |
606 | 743 |
|
2362 | 744 |
|mySize ret newFirstIndex| |
606 | 745 |
|
746 |
mySize := self size. |
|
747 |
mySize < n ifTrue:[ |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
748 |
"error if collection has not enough elements" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
749 |
^ self notEnoughElementsError. |
606 | 750 |
]. |
751 |
||
752 |
ret := Array new:n. |
|
753 |
ret replaceFrom:1 to:n with:contentsArray startingAt:firstIndex. |
|
1496 | 754 |
|
606 | 755 |
"/ |
756 |
"/ nil-out contents array, to not keep elements from being GC'd |
|
757 |
"/ |
|
2362 | 758 |
newFirstIndex := firstIndex + n. |
759 |
contentsArray from:firstIndex to:newFirstIndex - 1 put:nil. |
|
606 | 760 |
|
2362 | 761 |
newFirstIndex > lastIndex ifTrue:[ |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
762 |
"reset to avoid ever growing" |
2362 | 763 |
newFirstIndex := 1. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
764 |
lastIndex := 0 |
606 | 765 |
]. |
2362 | 766 |
firstIndex := newFirstIndex. |
606 | 767 |
^ ret |
93 | 768 |
|
769 |
" |
|
606 | 770 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:2; yourself |
771 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:0; yourself |
|
772 |
OrderedCollection new removeFirst:2 |
|
773 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:6 |
|
774 |
(SortedCollection withAll:#(5 4 3 2 1)) removeFirst:2; yourself |
|
13 | 775 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
776 |
|
2362 | 777 |
"Modified: 8.2.1997 / 19:20:18 / cg" |
1 | 778 |
! |
779 |
||
3695 | 780 |
removeFirstIfAbsent:exceptionBlock |
781 |
"remove the first element from the collection; return the element. |
|
782 |
If there is no element in the receiver collection, return the value from |
|
783 |
exceptionBlock." |
|
784 |
||
785 |
|anObject fI "{ Class: SmallInteger }" | |
|
786 |
||
787 |
fI := firstIndex. |
|
788 |
||
789 |
fI > lastIndex ifTrue:[ |
|
790 |
"error if collection is empty" |
|
791 |
^ exceptionBlock value. |
|
792 |
]. |
|
793 |
||
794 |
anObject := contentsArray basicAt:fI. |
|
795 |
||
796 |
"/ nil it out, to allow GC to reclaim it. |
|
797 |
contentsArray basicAt:fI put:nil. |
|
798 |
||
799 |
fI := fI + 1. |
|
800 |
||
801 |
fI > lastIndex ifTrue:[ |
|
802 |
"reset to avoid ever growing" |
|
803 |
fI := 1. |
|
804 |
lastIndex := 0 |
|
805 |
]. |
|
806 |
firstIndex := fI. |
|
807 |
^ anObject |
|
808 |
||
809 |
" |
|
810 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself |
|
811 |
OrderedCollection new removeFirst |
|
812 |
(SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself |
|
813 |
" |
|
814 |
||
815 |
"Modified: / 12.11.1997 / 17:58:43 / cg" |
|
816 |
"Created: / 30.7.1998 / 13:19:42 / cg" |
|
817 |
! |
|
818 |
||
2549 | 819 |
removeFrom:startIndex to:stopIndex |
820 |
"added for ST-80 compatibility. |
|
821 |
Same as removeFromIndex:toIndex:." |
|
822 |
||
823 |
^ self removeFromIndex:startIndex toIndex:stopIndex |
|
824 |
||
825 |
"Created: 15.4.1997 / 12:39:00 / cg" |
|
826 |
! |
|
827 |
||
606 | 828 |
removeFromIndex:startIndex toIndex:stopIndex |
829 |
"remove the elements stored under startIndex up to and including |
|
830 |
the elements under stopIndex. |
|
831 |
Return the receiver. |
|
832 |
Returning the receiver here is a historic leftover - it may change. |
|
14917 | 833 |
Please use yourself in a cascade, if you need the receiver's value |
606 | 834 |
when using this method." |
835 |
||
3968 | 836 |
|nDeleted "{ Class: SmallInteger }" |
837 |
fI "{ Class: SmallInteger }" |
|
838 |
lI "{ Class: SmallInteger }" |
|
2364 | 839 |
newLastIndex sz| |
1 | 840 |
|
2364 | 841 |
sz := self size. |
842 |
||
843 |
(startIndex < 1 or:[stopIndex > sz]) ifTrue:[ |
|
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
844 |
^ self notEnoughElementsError |
606 | 845 |
]. |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
846 |
|
2362 | 847 |
nDeleted := stopIndex - startIndex + 1. |
848 |
nDeleted < 0 ifTrue:[ |
|
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
849 |
"/ mhmh - what should be done here ? |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
850 |
^ self error:'bad index range' |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
851 |
]. |
2362 | 852 |
nDeleted == 0 ifTrue:[^ self]. |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
853 |
|
3968 | 854 |
fI := firstIndex. |
855 |
lI := lastIndex. |
|
856 |
||
2362 | 857 |
"/ |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
858 |
"/ can be done faster, when removing the first elements |
2362 | 859 |
"/ |
2364 | 860 |
startIndex == 1 ifTrue:[ |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
861 |
"/ nil out (helps GC) |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
862 |
contentsArray |
3968 | 863 |
from:fI |
864 |
to:fI + nDeleted - 1 |
|
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
865 |
put:nil. |
3968 | 866 |
firstIndex := fI := fI + nDeleted |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
867 |
] ifFalse:[ |
2362 | 868 |
"/ |
869 |
"/ can be done faster, when removing the last elements |
|
870 |
"/ |
|
2364 | 871 |
stopIndex == sz ifTrue:[ |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
872 |
"/ nil out (helps GC) |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
873 |
contentsArray |
3968 | 874 |
from:lI - nDeleted + 1 |
875 |
to:lI |
|
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
876 |
put:nil. |
3968 | 877 |
lastIndex := lI := lI - nDeleted |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
878 |
] ifFalse:[ |
2362 | 879 |
"/ |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
880 |
"/ must shuffle |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
881 |
"/ TODO: |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
882 |
"/ for big collections, try to copy the smallest |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
883 |
"/ possible number of elements |
606 | 884 |
|
3968 | 885 |
newLastIndex := lI - nDeleted. |
2362 | 886 |
|
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
887 |
contentsArray |
3968 | 888 |
replaceFrom:(fI + startIndex - 1) |
2362 | 889 |
to:newLastIndex |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
890 |
with:contentsArray |
3968 | 891 |
startingAt:(fI + stopIndex). |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
892 |
|
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
893 |
"/ nil out rest (helps GC) |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
894 |
contentsArray |
2362 | 895 |
from:(newLastIndex + 1) |
3968 | 896 |
to:lI |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
897 |
put:nil. |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
898 |
|
3968 | 899 |
lastIndex := lI := newLastIndex. |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
900 |
] |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
901 |
]. |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
902 |
|
3968 | 903 |
fI > lI ifTrue:[ |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
904 |
"reset to avoid ever growing" |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
905 |
firstIndex := 1. |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
906 |
lastIndex := 0 |
606 | 907 |
] |
13 | 908 |
|
909 |
" |
|
606 | 910 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:3 toIndex:6 |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
911 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:8 |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
912 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:1 toIndex:3 |
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
913 |
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:9 |
606 | 914 |
#(1 2 3 4 5) asOrderedCollection removeFromIndex:3 toIndex:6 |
217 | 915 |
" |
2355
9476ba4d810d
faster #removeFromIndex:toIndex.
Claus Gittinger <cg@exept.de>
parents:
2354
diff
changeset
|
916 |
|
3968 | 917 |
"Modified: / 5.2.1999 / 23:22:07 / cg" |
217 | 918 |
! |
919 |
||
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
920 |
removeIdentical:anObject ifAbsent:exceptionBlock |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
921 |
"remove the first element which is identical to anObject; |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
922 |
if found, remove and return it; |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
923 |
if not, return the value from evaluating exceptionBlock. |
2361
dd95b53674e9
oops - removeIdentical was wrong
Claus Gittinger <cg@exept.de>
parents:
2355
diff
changeset
|
924 |
Uses identity compare (==) to search for the element." |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
925 |
|
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
926 |
|index| |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
927 |
|
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
928 |
index := contentsArray identityIndexOf:anObject startingAt:firstIndex endingAt:lastIndex. |
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
929 |
index ~~ 0 ifTrue:[ |
6755
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
930 |
index == firstIndex ifTrue:[ |
6756 | 931 |
contentsArray basicAt:firstIndex put:nil. |
6755
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
932 |
firstIndex := firstIndex + 1. |
6756 | 933 |
firstIndex > lastIndex ifTrue:[ |
934 |
"reset to avoid ever growing" |
|
935 |
firstIndex := 1. |
|
936 |
lastIndex := 0 |
|
937 |
]. |
|
6755
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
938 |
] ifFalse:[ |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
939 |
index == lastIndex ifTrue:[ |
6756 | 940 |
contentsArray basicAt:lastIndex put:nil. |
6755
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
941 |
lastIndex := lastIndex - 1. |
6756 | 942 |
firstIndex > lastIndex ifTrue:[ |
943 |
"reset to avoid ever growing" |
|
944 |
firstIndex := 1. |
|
945 |
lastIndex := 0 |
|
946 |
]. |
|
6755
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
947 |
] ifFalse:[ |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
948 |
index := index - firstIndex + 1. |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
949 |
self removeFromIndex:index toIndex:index. |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
950 |
] |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
951 |
]. |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
952 |
^ anObject |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
953 |
]. |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
954 |
^ exceptionBlock value |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
955 |
|
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
956 |
" |
2354
652d17daeeb5
faster remove: if its the first or last element
Claus Gittinger <cg@exept.de>
parents:
2348
diff
changeset
|
957 |
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops' |
2361
dd95b53674e9
oops - removeIdentical was wrong
Claus Gittinger <cg@exept.de>
parents:
2355
diff
changeset
|
958 |
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops'; yourself |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
959 |
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops' |
6755
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
960 |
#(fee foo bar baz) asOrderedCollection removeIdentical:#fee; yourself |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
961 |
#(fee foo bar baz) asOrderedCollection removeIdentical:#foo; yourself |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
962 |
#(fee foo bar baz) asOrderedCollection removeIdentical:#baz; yourself |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
963 |
#(fee) asOrderedCollection removeIdentical:#fee; yourself |
a5704d23e08f
slightly faster removeIdentical
Claus Gittinger <cg@exept.de>
parents:
6700
diff
changeset
|
964 |
#(fee) asOrderedCollection removeIdentical:#foo; yourself |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
965 |
" |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
966 |
|
2361
dd95b53674e9
oops - removeIdentical was wrong
Claus Gittinger <cg@exept.de>
parents:
2355
diff
changeset
|
967 |
"Modified: 8.2.1997 / 18:57:43 / cg" |
2348
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
968 |
! |
523e9d6e0049
added #removeIdentical:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
2222
diff
changeset
|
969 |
|
606 | 970 |
removeLast |
971 |
"remove the last element from the collection; return the element" |
|
972 |
||
3107 | 973 |
|anObject |
974 |
idx "{ Class: SmallInteger }" | |
|
217 | 975 |
|
3107 | 976 |
idx := lastIndex. |
977 |
firstIndex > idx ifTrue:[ |
|
978 |
"error if collection is empty" |
|
979 |
^ self emptyCollectionError. |
|
606 | 980 |
]. |
3107 | 981 |
anObject := contentsArray basicAt:idx. |
1496 | 982 |
|
983 |
"/ nil it (helps GC) |
|
3107 | 984 |
contentsArray basicAt:idx put:nil. |
985 |
lastIndex := idx := idx - 1. |
|
606 | 986 |
|
3107 | 987 |
firstIndex > idx ifTrue:[ |
988 |
"reset to avoid ever growing" |
|
989 |
firstIndex := 1. |
|
990 |
lastIndex := 0 |
|
606 | 991 |
]. |
992 |
^ anObject |
|
217 | 993 |
|
994 |
" |
|
606 | 995 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast; yourself |
996 |
OrderedCollection new removeLast |
|
997 |
(SortedCollection withAll:#(5 4 3 2 1)) removeLast; yourself |
|
217 | 998 |
" |
3107 | 999 |
|
1000 |
"Modified: / 12.11.1997 / 17:58:57 / cg" |
|
13 | 1001 |
! |
1002 |
||
606 | 1003 |
removeLast:n |
11330 | 1004 |
"remove the last n elements from the receiver collection. |
1005 |
Return a collection of removed elements." |
|
606 | 1006 |
|
1007 |
|mySize ret| |
|
1008 |
||
1009 |
mySize := self size. |
|
1010 |
mySize < n ifTrue:[ |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1011 |
"error if collection has not enough elements" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1012 |
^ self notEnoughElementsError. |
606 | 1013 |
]. |
13 | 1014 |
|
606 | 1015 |
ret := Array new:n. |
1016 |
ret replaceFrom:1 to:n with:contentsArray startingAt:lastIndex - n + 1. |
|
1496 | 1017 |
|
606 | 1018 |
"/ |
1019 |
"/ nil-out contents array, to not keep elements from being GC'd |
|
1020 |
"/ |
|
1021 |
contentsArray from:lastIndex - n + 1 to:lastIndex put:nil. |
|
1022 |
lastIndex := lastIndex - n. |
|
13 | 1023 |
|
606 | 1024 |
firstIndex > lastIndex ifTrue:[ |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1025 |
"reset to avoid ever growing" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1026 |
firstIndex := 1. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1027 |
lastIndex := 0 |
13 | 1028 |
]. |
606 | 1029 |
^ ret |
13 | 1030 |
|
1031 |
" |
|
606 | 1032 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast:2; yourself |
1033 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast:0; yourself |
|
1034 |
(OrderedCollection withAll:#(1 2 3 4 5)) removeLast:6; yourself |
|
1035 |
(SortedCollection withAll:#(5 4 3 2 1)) removeLast:2; yourself |
|
11330 | 1036 |
(SortedCollection withAll:#(5 4 3 2 1)) removeLast:0; yourself |
1037 |
(SortedCollection withAll:#(5 4 3 2 1)) removeLast:0 |
|
13 | 1038 |
" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1039 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1040 |
"Modified: 12.4.1996 / 13:39:12 / cg" |
4862 | 1041 |
! |
1042 |
||
1043 |
reset |
|
1044 |
"logically remove all elements from the collection. |
|
1045 |
Thats almost the same as #removeAll, but keeps the contentsArray. |
|
1046 |
Returns the receiver." |
|
1047 |
||
1048 |
firstIndex := contentsArray size // 3 max: 1. |
|
1049 |
lastIndex := firstIndex - 1 |
|
1 | 1050 |
! ! |
1051 |
||
606 | 1052 |
!OrderedCollection methodsFor:'converting'! |
1 | 1053 |
|
1170 | 1054 |
asArray |
1055 |
"return the receiver as an array." |
|
1056 |
||
4153 | 1057 |
^ contentsArray copyFrom:firstIndex to:lastIndex |
1170 | 1058 |
|
4153 | 1059 |
"/ |newArray sz| |
1060 |
"/ |
|
1061 |
"/ sz := self size. |
|
1062 |
"/ newArray := Array new:sz. |
|
1063 |
"/ newArray replaceFrom:1 to:sz with:contentsArray startingAt:firstIndex. |
|
1064 |
"/ ^ newArray |
|
1065 |
||
1066 |
" |
|
1067 |
OrderedCollection new asArray |
|
1068 |
OrderedCollection new add:1;add:2;asArray |
|
1069 |
OrderedCollection new add:1;removeFirst;asArray |
|
1070 |
" |
|
1170 | 1071 |
|
1072 |
" |
|
1073 |
|o rnd| |
|
1074 |
||
1075 |
o := OrderedCollection new. |
|
1076 |
rnd := Random new. |
|
1077 |
10000 timesRepeat:[ |
|
1078 |
o add:rnd next. |
|
1079 |
]. |
|
1080 |
Time millisecondsToRun:[o asArray] |
|
1081 |
" |
|
1082 |
||
1083 |
"Modified: 13.4.1996 / 12:10:56 / cg" |
|
1084 |
! |
|
1085 |
||
14999 | 1086 |
asNewOrderedCollection |
1087 |
"return the receiver as an ordered collection. |
|
1088 |
Make sure to return a unique new OrderedCollection" |
|
1089 |
||
1090 |
"could be an instance of a subclass..." |
|
1091 |
self class == OrderedCollection ifTrue:[ |
|
1092 |
^ self copy |
|
1093 |
]. |
|
1094 |
^ super asOrderedCollection |
|
1095 |
||
1096 |
" |
|
1097 |
|s| |
|
1098 |
s := #(1 2 3 4) asOrderedCollection. |
|
1099 |
self assert:(s ~~ s asNewOrderedCollection). |
|
1100 |
self assert:(s = s asNewOrderedCollection). |
|
1101 |
" |
|
1102 |
! |
|
1103 |
||
606 | 1104 |
asOrderedCollection |
15062 | 1105 |
"return the receiver as an ordered collection. |
1106 |
Notice: this returns the receiver. Use asNewOrderedCollection, if you intent to |
|
1107 |
modify the returned collection." |
|
1 | 1108 |
|
606 | 1109 |
"could be an instance of a subclass..." |
1110 |
self class == OrderedCollection ifTrue:[ |
|
15062 | 1111 |
^ self |
606 | 1112 |
]. |
1113 |
^ super asOrderedCollection |
|
1 | 1114 |
! ! |
1115 |
||
606 | 1116 |
!OrderedCollection methodsFor:'copying'! |
13 | 1117 |
|
606 | 1118 |
, aCollection |
14071 | 1119 |
"return a new collection formed from concatenating the receiver with the argument" |
1 | 1120 |
|
606 | 1121 |
|newCollection| |
1 | 1122 |
|
606 | 1123 |
newCollection := self copyEmpty:(self size + aCollection size). |
1124 |
self do:[:element | |
|
14071 | 1125 |
newCollection add:element |
42 | 1126 |
]. |
606 | 1127 |
aCollection do:[:element | |
14071 | 1128 |
newCollection add:element |
606 | 1129 |
]. |
1130 |
^ newCollection |
|
42 | 1131 |
|
253 | 1132 |
" |
606 | 1133 |
#(1 2 3) asOrderedCollection , #(4 5 6) asOrderedCollection |
1134 |
#(1 2 3) asSortedCollection , #(99 101 100) asSortedCollection |
|
253 | 1135 |
" |
14071 | 1136 |
|
1137 |
"Modified (comment): / 01-04-2012 / 13:17:30 / cg" |
|
42 | 1138 |
! |
1139 |
||
606 | 1140 |
copy |
1141 |
"return a new OrderedCollection containing the elements of the receiver." |
|
1142 |
||
1143 |
"redefinition is a consequence of the implementation with a |
|
1144 |
separate array - otherwise we get a shallow copy of the |
|
1145 |
contents array, which is not what we want here" |
|
1146 |
||
1147 |
^ self copyFrom:1 to:self size |
|
1148 |
! |
|
1149 |
||
1150 |
copyEmpty |
|
1151 |
"return a copy of the receiver without any elements." |
|
1152 |
||
1153 |
^ self copyEmpty:10 |
|
1154 |
! |
|
1155 |
||
1156 |
copyFrom:start to:stop |
|
1157 |
"return a new OrderedCollection containing the elements |
|
1158 |
from start to stop." |
|
42 | 1159 |
|
606 | 1160 |
|newCollection sz| |
1161 |
||
1162 |
sz := stop - start + 1. |
|
1163 |
newCollection := self copyEmptyAndGrow:sz. "must grow, otherwise replace fails" |
|
1164 |
newCollection replaceFrom:1 to:sz with:self startingAt:start. |
|
1165 |
^ newCollection |
|
1166 |
! |
|
1167 |
||
1168 |
postCopy |
|
1169 |
"have to copy the contentsArray too" |
|
1170 |
||
1171 |
contentsArray := contentsArray shallowCopy |
|
1172 |
! ! |
|
1173 |
||
1174 |
!OrderedCollection methodsFor:'enumerating'! |
|
1175 |
||
1176 |
collect:aBlock |
|
1177 |
"evaluate the argument, aBlock for every element in the collection |
|
1178 |
and return a collection of the results" |
|
1179 |
||
1180 |
|newCollection |
|
1181 |
start "{ Class:SmallInteger }" |
|
1182 |
stop "{ Class:SmallInteger }" | |
|
1183 |
||
1184 |
newCollection := self copyEmpty:(self size). |
|
1185 |
stop := lastIndex. |
|
1186 |
start := firstIndex. |
|
1187 |
start to:stop do:[:index | |
|
1188 |
newCollection add:(aBlock value:(contentsArray at:index)). |
|
1189 |
]. |
|
1190 |
^ newCollection |
|
1191 |
||
253 | 1192 |
" |
606 | 1193 |
#(1 2 3 4) asOrderedCollection collect:[:i | i * i] |
1194 |
#(1 2 3 4) asOrderedCollection collect:[:i | i even] |
|
1195 |
" |
|
1196 |
! |
|
1197 |
||
5508 | 1198 |
collect:collectBlock thenSelect:selectBlock |
5874 | 1199 |
"combination of collect followed by select; |
7164 | 1200 |
redefined to avoid the creation of an intermediate (garbage) collection." |
5508 | 1201 |
|
1202 |
|newCollection newElement |
|
1203 |
start "{ Class:SmallInteger }" |
|
1204 |
stop "{ Class:SmallInteger }" | |
|
1205 |
||
7166 | 1206 |
newCollection := self copyEmpty. |
5508 | 1207 |
stop := lastIndex. |
1208 |
start := firstIndex. |
|
1209 |
start to:stop do:[:index | |
|
1210 |
newElement := collectBlock value:(contentsArray at:index). |
|
1211 |
(selectBlock value:newElement) ifTrue:[ |
|
1212 |
newCollection add:newElement. |
|
1213 |
] |
|
1214 |
]. |
|
1215 |
^ newCollection |
|
1216 |
||
1217 |
" |
|
1218 |
#(1 2 3 4) asOrderedCollection collect:[:i | i * i] thenSelect:[:each | each > 5] |
|
1219 |
( #(1 2 3 4) asOrderedCollection collect:[:i | i * i]) select:[:each | each > 5] |
|
1220 |
||
7165 | 1221 |
|coll| |
1222 |
coll := #(1 2 3 4) asOrderedCollection. |
|
5508 | 1223 |
Time millisecondsToRun:[ |
1224 |
100000 timesRepeat:[ |
|
7165 | 1225 |
coll collect:[:i | i * i] thenSelect:[:each | each > 5] |
5508 | 1226 |
] |
7165 | 1227 |
] |
5508 | 1228 |
|
7165 | 1229 |
|coll| |
1230 |
coll := #(1 2 3 4) asOrderedCollection. |
|
5508 | 1231 |
Time millisecondsToRun:[ |
1232 |
100000 timesRepeat:[ |
|
7165 | 1233 |
( coll collect:[:i | i * i]) select:[:each | each > 5] |
5508 | 1234 |
] |
7165 | 1235 |
] |
5508 | 1236 |
" |
1237 |
! |
|
1238 |
||
606 | 1239 |
do:aBlock |
1240 |
"evaluate the argument, aBlock for every element in the collection." |
|
1241 |
||
1242 |
contentsArray from:firstIndex to:lastIndex do:aBlock |
|
1243 |
! |
|
1244 |
||
1245 |
keysAndValuesDo:aTwoArgBlock |
|
1246 |
"evaluate the argument, aBlock for every element in the collection, |
|
1247 |
passing both index and element as arguments." |
|
1248 |
||
1249 |
|start "{ Class:SmallInteger }" |
|
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1250 |
stop "{ Class:SmallInteger }" |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1251 |
idx "{ Class:SmallInteger }" | |
606 | 1252 |
|
1253 |
stop := lastIndex. |
|
1254 |
start := firstIndex. |
|
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1255 |
idx := 1. |
606 | 1256 |
start to:stop do:[:index | |
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1257 |
aTwoArgBlock value:idx value:(contentsArray at:index). |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1258 |
idx := idx + 1. |
606 | 1259 |
] |
1260 |
||
1261 |
" |
|
1262 |
#(10 20 30 40) asOrderedCollection keysAndValuesDo:[:index :value | |
|
1422 | 1263 |
Transcript show:index; show:' '; showCR:value |
606 | 1264 |
] |
1265 |
" |
|
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1266 |
" |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1267 |
|oc| |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1268 |
|
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1269 |
oc := #(10 20 30 40 50 60 70 80) asOrderedCollection. |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1270 |
oc removeFirst; removeFirst. |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1271 |
oc keysAndValuesDo:[:index :value | |
1422 | 1272 |
Transcript show:index; show:' '; showCR:value |
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1273 |
] |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1274 |
" |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1275 |
|
606 | 1276 |
! |
1277 |
||
679 | 1278 |
keysAndValuesReverseDo:aTwoArgBlock |
1279 |
"evaluate the argument, aBlock for every element in the collection, |
|
1280 |
passing both index and element as arguments." |
|
1281 |
||
1282 |
|start "{ Class:SmallInteger }" |
|
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1283 |
stop "{ Class:SmallInteger }" |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1284 |
idx "{ Class:SmallInteger }"| |
679 | 1285 |
|
1286 |
stop := lastIndex. |
|
1287 |
start := firstIndex. |
|
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1288 |
idx := (stop - start + 1). |
679 | 1289 |
stop to:start by: -1 do:[:index | |
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1290 |
aTwoArgBlock value:idx value:(contentsArray at:index). |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1291 |
idx := idx - 1. |
679 | 1292 |
] |
1293 |
||
1294 |
" |
|
1295 |
#(10 20 30 40) asOrderedCollection keysAndValuesReverseDo:[:index :value | |
|
1422 | 1296 |
Transcript show:index; show:' '; showCR:value |
1090
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1297 |
] |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1298 |
" |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1299 |
|
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1300 |
" |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1301 |
|oc| |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1302 |
|
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1303 |
oc := #(10 20 30 40 50 60 70 80) asOrderedCollection. |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1304 |
oc removeFirst; removeFirst. |
def6e50a2d13
oops - keysAndValuesDo was wrong, iff elements have been removed upFront recently
ca
parents:
1071
diff
changeset
|
1305 |
oc keysAndValuesReverseDo:[:index :value | |
1422 | 1306 |
Transcript show:index; show:' '; showCR:value |
679 | 1307 |
] |
1308 |
" |
|
1071 | 1309 |
! |
1310 |
||
1311 |
reverseDo:aBlock |
|
1312 |
"evaluate the argument, aBlock for every element in the collection |
|
1313 |
procesing elements in reverse direction (i.e. starting with the last)" |
|
1314 |
||
1315 |
contentsArray from:firstIndex to:lastIndex reverseDo:aBlock |
|
7165 | 1316 |
! |
1317 |
||
1318 |
select:selectBlock thenCollect:collectBlock |
|
1319 |
"combination of select followed by collect; |
|
1320 |
redefined to avoid the creation of an intermediate (garbage) collection." |
|
1321 |
||
1322 |
|newCollection element |
|
1323 |
start "{ Class:SmallInteger }" |
|
1324 |
stop "{ Class:SmallInteger }" | |
|
1325 |
||
7166 | 1326 |
newCollection := self copyEmpty. |
7165 | 1327 |
stop := lastIndex. |
1328 |
start := firstIndex. |
|
1329 |
start to:stop do:[:index | |
|
1330 |
element := contentsArray at:index. |
|
1331 |
(selectBlock value:element) ifTrue:[ |
|
1332 |
newCollection add:(collectBlock value:element). |
|
1333 |
] |
|
1334 |
]. |
|
1335 |
^ newCollection |
|
1336 |
||
1337 |
" |
|
1338 |
#(1 2 3 4 5 6 7 8) asOrderedCollection |
|
1339 |
select:[:each | each > 5] thenCollect:[:i | i * i] |
|
1340 |
( #(1 2 3 4 5 6 7 8) asOrderedCollection |
|
1341 |
select:[:each | each > 5]) collect:[:i | i * i] |
|
1342 |
||
1343 |
|coll| |
|
1344 |
coll := #(1 2 3 4 5 6 7 8) asOrderedCollection. |
|
1345 |
Time millisecondsToRun:[ |
|
1346 |
100000 timesRepeat:[ |
|
1347 |
coll select:[:each | each > 5] thenCollect:[:i | i * i] |
|
1348 |
] |
|
7166 | 1349 |
] |
7165 | 1350 |
|
1351 |
|coll| |
|
1352 |
coll := #(1 2 3 4 5 6 7 8) asOrderedCollection. |
|
1353 |
Time millisecondsToRun:[ |
|
1354 |
100000 timesRepeat:[ |
|
1355 |
( coll select:[:each | each > 5]) collect:[:i | i * i] |
|
1356 |
] |
|
7166 | 1357 |
] |
7165 | 1358 |
" |
1 | 1359 |
! ! |
1360 |
||
56 | 1361 |
!OrderedCollection methodsFor:'filling & replacing'! |
13 | 1362 |
|
1363 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
1170 | 1364 |
"replace elements in the receiver between index start and stop, |
1365 |
with elements taken from replacementCollection starting at repStart. |
|
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
1366 |
Return the receiver. |
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
1367 |
Redefined here; can be done faster as the inherited operation." |
13 | 1368 |
|
1369 |
|end| |
|
1370 |
||
1371 |
end := stop + firstIndex - 1. |
|
1372 |
((start >= 1) and:[end <= lastIndex]) ifTrue:[ |
|
1170 | 1373 |
aCollection class == self class ifTrue:[ |
1374 |
contentsArray |
|
1375 |
replaceFrom:(start + firstIndex - 1) |
|
1376 |
to:end |
|
1377 |
with:aCollection contentsArray |
|
1378 |
startingAt:(repStart + aCollection firstIndex - 1). |
|
1379 |
] ifFalse:[ |
|
1380 |
contentsArray |
|
1381 |
replaceFrom:(start + firstIndex - 1) |
|
1382 |
to:end |
|
1383 |
with:aCollection |
|
1384 |
startingAt:repStart. |
|
1385 |
]. |
|
1386 |
^ self |
|
13 | 1387 |
]. |
1388 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
293 | 1389 |
|
1390 |
" |
|
1391 |
|c| |
|
1392 |
||
1393 |
c := #(1 2 3 4 5 6) asOrderedCollection. |
|
1394 |
c replaceFrom:3 to:6 with:c startingAt:2. |
|
1395 |
c |
|
1396 |
" |
|
1397 |
" |
|
1398 |
|c| |
|
1399 |
||
1400 |
c := #(1 2 3 4 5 6) asOrderedCollection. |
|
1401 |
c replaceFrom:3 to:5 with:c startingAt:4. |
|
1402 |
c |
|
1403 |
" |
|
1170 | 1404 |
|
3236
b5f80b416cff
check for valid subscript in #add:beforeIndex:
Claus Gittinger <cg@exept.de>
parents:
3109
diff
changeset
|
1405 |
"Modified: / 28.1.1998 / 16:49:31 / cg" |
13 | 1406 |
! ! |
1407 |
||
606 | 1408 |
!OrderedCollection methodsFor:'grow & shrink'! |
77 | 1409 |
|
606 | 1410 |
grow:newSize |
14917 | 1411 |
"grow the receiver to newSize. |
1412 |
This only logically changes the receiver's size; |
|
1413 |
the underlying contentsArray is kept (except if growing to 0 size)" |
|
77 | 1414 |
|
606 | 1415 |
|oldSize newContents oldLast newLast| |
77 | 1416 |
|
606 | 1417 |
oldSize := lastIndex - firstIndex + 1. |
1418 |
newSize ~~ oldSize ifTrue:[ |
|
14917 | 1419 |
newLast := firstIndex + newSize - 1. |
1420 |
newSize < oldSize ifTrue:[ |
|
1421 |
newSize == 0 ifTrue:[ |
|
1422 |
self initContents:10. |
|
1423 |
^ self. |
|
1424 |
]. |
|
1425 |
oldLast := lastIndex. |
|
1426 |
lastIndex := newLast. |
|
1427 |
" |
|
1428 |
nil out rest, to give GC a chance to reclaim things |
|
1429 |
" |
|
1430 |
contentsArray from:lastIndex + 1 to:oldLast put:nil. |
|
1431 |
] ifFalse:[ |
|
1432 |
newLast <= contentsArray size ifTrue:[ |
|
1433 |
lastIndex := newLast. |
|
1434 |
^ self |
|
1435 |
]. |
|
77 | 1436 |
|
14917 | 1437 |
newContents := Array basicNew:newSize. |
1438 |
newContents replaceFrom:1 to:oldSize with:contentsArray startingAt:firstIndex. |
|
1439 |
contentsArray := newContents. |
|
1440 |
firstIndex := 1. |
|
1441 |
lastIndex := newSize |
|
1442 |
] |
|
606 | 1443 |
] |
1444 |
! ! |
|
77 | 1445 |
|
1446 |
||
15442 | 1447 |
|
1 | 1448 |
!OrderedCollection methodsFor:'private'! |
1449 |
||
606 | 1450 |
initContents:size |
1451 |
"setup the receiver-collection to hold size entries" |
|
33 | 1452 |
|
606 | 1453 |
contentsArray := Array basicNew:size. |
1454 |
firstIndex := 1. |
|
1455 |
lastIndex := 0 |
|
1 | 1456 |
! |
1457 |
||
1458 |
makeRoomAtFront |
|
282 | 1459 |
"grow/shift the contents for more room at the beginning. |
1460 |
Does not change the logical size. |
|
1461 |
i.e. |
|
1462 |
#(1 2 3 4 5 6) -> #(nil 1 2 3 4 5 6)" |
|
1 | 1463 |
|
1464 |
|newContents |
|
33 | 1465 |
oldSize "{ Class:SmallInteger }" |
1466 |
newSize "{ Class:SmallInteger }" |
|
1467 |
startIndex "{ Class:SmallInteger }" |
|
1468 |
sz "{ Class:SmallInteger }"| |
|
1 | 1469 |
|
1470 |
oldSize := contentsArray size. |
|
506
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
1471 |
sz := lastIndex - firstIndex + 1. |
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
1472 |
|
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
1473 |
((oldSize == 0) or:[sz == 0]) ifTrue:[ |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1474 |
contentsArray := Array basicNew:3. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1475 |
firstIndex := 2. lastIndex := 1. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1476 |
^ self |
93 | 1477 |
]. |
1478 |
||
329 | 1479 |
" |
1480 |
if there is lots of room at the end (> 50%), |
|
1481 |
shift instead of growing. This helps collections |
|
1482 |
which get elements removed at the end and added at front. |
|
1483 |
" |
|
33 | 1484 |
oldSize > (sz * 2) ifTrue:[ |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1485 |
startIndex := oldSize // 4. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1486 |
startIndex > 1 ifTrue:[ |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1487 |
contentsArray |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1488 |
replaceFrom:startIndex to:(startIndex + sz - 1) |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1489 |
with:contentsArray startingAt:1. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1490 |
contentsArray from:1 to:(startIndex - 1) put:nil. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1491 |
firstIndex := startIndex. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1492 |
lastIndex := startIndex + sz - 1. |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1493 |
^ self |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1494 |
] |
33 | 1495 |
]. |
2 | 1496 |
newSize := oldSize * 2. |
329 | 1497 |
newSize == 0 ifTrue:[ newSize := 3]. |
253 | 1498 |
newContents := Array basicNew:newSize. |
77 | 1499 |
newContents |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1500 |
replaceFrom:(oldSize + 1) to:newSize |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1501 |
with:contentsArray startingAt:1. |
1 | 1502 |
contentsArray := newContents. |
1503 |
firstIndex := firstIndex + oldSize. |
|
1504 |
lastIndex := lastIndex + oldSize |
|
506
984b32fe635a
fixed makeRoomAtFront if underlying arrays size is <= 3
Claus Gittinger <cg@exept.de>
parents:
407
diff
changeset
|
1505 |
|
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1506 |
"Created: / 08-11-1995 / 12:47:49 / cg" |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1507 |
"Modified: / 22-10-2008 / 17:10:13 / cg" |
1 | 1508 |
! |
1509 |
||
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1510 |
makeRoomAtIndex:whereToMakeEmptySlot |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1511 |
"grow the contents for inserting at whereToMakeEmptySlot. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1512 |
The whereToMakeEmptySlot argument must be a physical index within the contentsArray. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1513 |
If there is (plenty of) room at either end, elements are shifted inplace to create |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1514 |
an empty slot; otherwise, a new contentsArray is allocated. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1515 |
Since this changes the logical size, the modified index is returned. |
1 | 1516 |
i.e. |
1517 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:3 -> #(1 2 nil 3 4 5 6) |
|
1518 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:1 -> #(nil 1 2 3 4 5 6) |
|
1519 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:7 -> #(1 2 3 4 5 6 nil)" |
|
1520 |
||
1521 |
|newContents |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1522 |
newSize "{ Class:SmallInteger }" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1523 |
oldSize "{ Class:SmallInteger }" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1524 |
oneFourthOfSize "{ Class:SmallInteger }" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1525 |
first "{ Class:SmallInteger }" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1526 |
last "{ Class:SmallInteger }" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1527 |
index "{ Class:SmallInteger }" |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1528 |
shiftLeft shiftRight| |
1 | 1529 |
|
1530 |
oldSize := contentsArray size. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1531 |
oneFourthOfSize := oldSize // 4. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1532 |
index := whereToMakeEmptySlot. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1533 |
first := firstIndex. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1534 |
last := lastIndex. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1535 |
|
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1536 |
((first > 1) "and:[first > oneFourthOfSize]") ifTrue:[ |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1537 |
"there is room at the beginning" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1538 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1539 |
shiftLeft := true. |
33 | 1540 |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1541 |
index == first ifFalse:[ |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1542 |
"/ so, we'd have to copy all elements before that index |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1543 |
"/ one slot towards the containers beginning ... |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1544 |
"/ if there is also space at the end, AND the number of |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1545 |
"/ elements after the index is smaller than the number before, |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1546 |
"/ copy the remaining elements. To copy the least possible number. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1547 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1548 |
(last - index) < (index - first) ifTrue:[ |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1549 |
last < oldSize "(oneFourthOfSize * 3)" ifTrue:[ |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1550 |
shiftLeft := false. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1551 |
shiftRight := true. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1552 |
] |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1553 |
] |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1554 |
] |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1555 |
] ifFalse:[ |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1556 |
last < oldSize "(oneFourthOfSize * 3)" ifTrue:[ |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1557 |
shiftRight := true |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1558 |
] |
33 | 1559 |
]. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1560 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1561 |
shiftLeft == true ifTrue:[ |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1562 |
"there is room at the beginning" |
33 | 1563 |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1564 |
index == first ifFalse:[ |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1565 |
contentsArray |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1566 |
replaceFrom:(first - 1) to:(index - 2) |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1567 |
with:contentsArray startingAt:first. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1568 |
contentsArray at:index-1 put:nil. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1569 |
]. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1570 |
firstIndex := first - 1. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1571 |
^ index - 1 |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1572 |
]. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1573 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1574 |
shiftRight == true ifTrue:[ |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1575 |
"there is room at the end" |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1576 |
|
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1577 |
last := last + 1. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1578 |
index == last ifFalse:[ |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1579 |
contentsArray |
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1580 |
replaceFrom:(index + 1) to:last |
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1581 |
with:contentsArray startingAt:index. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1582 |
contentsArray at:index put:nil |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1583 |
]. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1584 |
lastIndex := last. |
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1585 |
^ index |
33 | 1586 |
]. |
1587 |
||
1588 |
newSize := oldSize * 2. |
|
253 | 1589 |
newContents := Array basicNew:newSize. |
11271 | 1590 |
index == first ifTrue:[ |
1591 |
"/ if there is a lot at the end (> 50), make all new space at the beginning. |
|
1592 |
"/ otherwise make 3/4 of the new space to the beginning, 1/4 to the end |
|
1593 |
(last < (oldSize - 50)) ifTrue:[ |
|
1594 |
lastIndex := newSize - (oldSize-last). |
|
1595 |
firstIndex := lastIndex - (last - first). |
|
1596 |
] ifFalse:[ |
|
1597 |
firstIndex := oldSize * 3 // 4. |
|
1598 |
lastIndex := firstIndex + (last - first). |
|
1599 |
]. |
|
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1600 |
newContents |
11271 | 1601 |
replaceFrom:firstIndex to:lastIndex |
1602 |
with:contentsArray startingAt:first. |
|
1603 |
||
1604 |
contentsArray := newContents. |
|
1605 |
firstIndex := firstIndex - 1. |
|
1606 |
||
1607 |
^ firstIndex. |
|
1608 |
] ifFalse:[ |
|
1609 |
newContents |
|
1610 |
replaceFrom:1 to:(index - first) |
|
1611 |
with:contentsArray startingAt:first. |
|
1612 |
||
1613 |
index <= last ifTrue:[ |
|
1614 |
newContents |
|
1615 |
replaceFrom:(index - first + 2) to:(last - first + 2) |
|
1616 |
with:contentsArray startingAt:index. |
|
1617 |
]. |
|
1618 |
contentsArray := newContents. |
|
1619 |
firstIndex := 1. |
|
1620 |
lastIndex := last - first + 2. |
|
1621 |
||
1622 |
"/ return the modified index |
|
1623 |
^ index - (first - firstIndex). |
|
1 | 1624 |
]. |
1161
aad722dea51a
return values compatible to ST-80; added comments; fixed & tuned #makeRoomAtIndex:
Claus Gittinger <cg@exept.de>
parents:
1157
diff
changeset
|
1625 |
|
11275
2883195d540e
makeRoomAtIndex: there is no need to do an early reallocation
Claus Gittinger <cg@exept.de>
parents:
11271
diff
changeset
|
1626 |
"Modified: / 22-10-2008 / 17:11:06 / cg" |
1 | 1627 |
! |
1628 |
||
2222 | 1629 |
makeRoomAtIndex:whereToMakeEmptySlots for:howMany |
1630 |
"grow the contents for inserting at whereToMakeEmptySlot. |
|
1631 |
The whereToMakeEmptySlot argument must be a physical index within the contentsArray. |
|
1632 |
If there is (plenty of) room at either end, elements are shifted inplace to create |
|
1633 |
an empty slot; otherwise, a new contentsArray is allocated. |
|
1634 |
Since this changes the logical size, the modified index is returned. |
|
1635 |
i.e. |
|
1636 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:3 for:2 -> #(1 2 nil nil 3 4 5 6) |
|
1637 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:1 for:2 -> #(nil nil 1 2 3 4 5 6) |
|
1638 |
#(1 2 3 4 5 6) asOrderedCollection makeRoomAtIndex:7 for:2 -> #(1 2 3 4 5 6 nil nil)" |
|
1639 |
||
1640 |
|newContents |
|
1641 |
newSize "{ Class:SmallInteger }" |
|
1642 |
oldSize "{ Class:SmallInteger }" |
|
1643 |
oneFourthOfSize "{ Class:SmallInteger }" |
|
1644 |
first "{ Class:SmallInteger }" |
|
1645 |
last "{ Class:SmallInteger }" |
|
1646 |
index "{ Class:SmallInteger }" |
|
1647 |
shiftLeft shiftRight| |
|
1648 |
||
1649 |
oldSize := contentsArray size. |
|
1650 |
oneFourthOfSize := oldSize // 4. |
|
1651 |
index := whereToMakeEmptySlots. |
|
1652 |
first := firstIndex. |
|
1653 |
last := lastIndex. |
|
1654 |
||
2549 | 1655 |
shiftLeft := shiftRight := false. |
2222 | 1656 |
((first > howMany) and:[first > oneFourthOfSize]) ifTrue:[ |
1657 |
"there is room (>25%) at the beginning" |
|
1658 |
||
1659 |
shiftLeft := true. |
|
1660 |
] ifFalse:[ |
|
2549 | 1661 |
((last + howMany) <= oldSize |
1662 |
and:[last < (oneFourthOfSize * 3)]) ifTrue:[ |
|
2222 | 1663 |
shiftRight := true |
1664 |
] |
|
1665 |
]. |
|
1666 |
||
1667 |
shiftLeft == true ifTrue:[ |
|
2549 | 1668 |
"there is room at the beginning" |
2222 | 1669 |
|
1670 |
index == first ifFalse:[ |
|
1671 |
contentsArray |
|
1672 |
replaceFrom:(first - howMany) |
|
1673 |
to:(index - howMany - 1) |
|
1674 |
with:contentsArray |
|
1675 |
startingAt:first. |
|
1676 |
contentsArray from:index-howMany to:index-1 put:nil. |
|
1677 |
]. |
|
1678 |
firstIndex := first - howMany. |
|
1679 |
^ index - howMany |
|
1680 |
]. |
|
1681 |
||
1682 |
shiftRight == true ifTrue:[ |
|
2549 | 1683 |
"there is room at the end" |
2222 | 1684 |
|
1685 |
last := last + howMany. |
|
1686 |
index == last ifFalse:[ |
|
1687 |
contentsArray |
|
1688 |
replaceFrom:(index + howMany) |
|
1689 |
to:last |
|
1690 |
with:contentsArray |
|
1691 |
startingAt:index. |
|
1692 |
contentsArray from:index to:index+howMany-1 put:nil |
|
1693 |
]. |
|
1694 |
lastIndex := last. |
|
1695 |
^ index |
|
1696 |
]. |
|
1697 |
||
1698 |
newSize := oldSize * 2. |
|
1699 |
[newSize < (oldSize+howMany)] whileTrue:[ |
|
1700 |
newSize := newSize * 2 |
|
1701 |
]. |
|
1702 |
||
1703 |
newContents := Array basicNew:newSize. |
|
1704 |
index > first ifTrue:[ |
|
1705 |
newContents |
|
1706 |
replaceFrom:1 |
|
1707 |
to:index - first |
|
1708 |
with:contentsArray |
|
1709 |
startingAt:first. |
|
1710 |
]. |
|
1711 |
index <= last ifTrue:[ |
|
1712 |
newContents |
|
1713 |
replaceFrom:index - first + howMany + 1 |
|
1714 |
to:(last - first + howMany + 1) |
|
1715 |
with:contentsArray |
|
1716 |
startingAt:(index). |
|
1717 |
]. |
|
1718 |
contentsArray := newContents. |
|
1719 |
firstIndex := 1. |
|
1720 |
lastIndex := last - first + howMany + 1. |
|
1721 |
||
1722 |
"/ return the modified index |
|
1723 |
^ index - (first - firstIndex). |
|
1724 |
||
2549 | 1725 |
"Modified: 15.4.1997 / 12:34:16 / cg" |
2222 | 1726 |
! |
1727 |
||
606 | 1728 |
makeRoomAtLast |
1729 |
"grow/shift the contents for more room at the end. |
|
1730 |
Does not change the logical size. |
|
1731 |
i.e. |
|
1732 |
#(1 2 3 4 5 6) -> #(1 2 3 4 5 6 nil)" |
|
1733 |
||
1734 |
|newContents |
|
1735 |
oldSize "{ Class:SmallInteger }" |
|
1736 |
newSize "{ Class:SmallInteger }" |
|
1737 |
startIndex "{ Class:SmallInteger }" |
|
1738 |
sz "{ Class:SmallInteger }"| |
|
1739 |
||
1740 |
oldSize := contentsArray size. |
|
1741 |
sz := lastIndex - firstIndex + 1. |
|
1742 |
||
1743 |
" |
|
1744 |
if there is lots of room at the beginning (> 50%), |
|
1745 |
shift instead of growing. This helps collections which get |
|
1746 |
elements removed at front and added at the end. |
|
1747 |
" |
|
1748 |
oldSize > (sz * 2) ifTrue:[ |
|
11269 | 1749 |
startIndex := firstIndex // 4. |
1750 |
startIndex == 0 ifTrue:[ |
|
1751 |
startIndex := 1 |
|
1752 |
]. |
|
1753 |
contentsArray |
|
1754 |
replaceFrom:startIndex to:startIndex + sz - 1 |
|
1755 |
with:contentsArray startingAt:firstIndex. |
|
1756 |
contentsArray from:startIndex + sz to:lastIndex put:nil. |
|
1757 |
firstIndex := startIndex. |
|
1758 |
lastIndex := startIndex + sz - 1. |
|
1759 |
^ self |
|
606 | 1760 |
]. |
1761 |
newSize := oldSize * 2. |
|
1762 |
newSize == 0 ifTrue:[newSize := 3]. |
|
1763 |
newContents := Array basicNew:newSize. |
|
1764 |
newContents |
|
11269 | 1765 |
replaceFrom:1 to:oldSize |
1766 |
with:contentsArray startingAt:1. |
|
606 | 1767 |
contentsArray := newContents |
11269 | 1768 |
|
1769 |
"Modified: / 22-10-2008 / 11:50:28 / cg" |
|
606 | 1770 |
! |
1771 |
||
1772 |
setFirstIndex:newFirstIndex lastIndex:newLastIndex |
|
1773 |
"set first and last index" |
|
1774 |
||
1775 |
firstIndex := newFirstIndex. |
|
1776 |
lastIndex := newLastIndex. |
|
6088
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1777 |
! |
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1778 |
|
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1779 |
setIndices |
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1780 |
"added for VW compatibility: set the indices for an empty collection" |
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1781 |
|
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1782 |
firstIndex := 1. |
db3fc1ec9c1a
added #setIndices for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
5874
diff
changeset
|
1783 |
lastIndex := 0. |
606 | 1784 |
! ! |
1785 |
||
7260 | 1786 |
!OrderedCollection methodsFor:'private-accessing'! |
606 | 1787 |
|
1788 |
contentsArray |
|
4153 | 1789 |
"return the orderedCollections underlying contentsArray. |
1790 |
The actual elements are found here starting at firstIndex, |
|
1791 |
and ending at lastIndex." |
|
1792 |
||
606 | 1793 |
^ contentsArray |
1794 |
! |
|
1795 |
||
1796 |
firstIndex |
|
4153 | 1797 |
"return the index of my first element in my underlying contentsArray. |
1798 |
The actual elements are found starting this index, |
|
1799 |
and ending at lastIndex." |
|
1800 |
||
606 | 1801 |
^ firstIndex |
1802 |
! ! |
|
1803 |
||
1804 |
!OrderedCollection methodsFor:'queries'! |
|
1805 |
||
1806 |
capacity |
|
1807 |
"return the number of elements, that the receiver is |
|
1808 |
prepared to take. |
|
1809 |
Not used by the system; added for ST-80 compatibility." |
|
1810 |
||
1811 |
^ contentsArray size |
|
1812 |
! |
|
1813 |
||
1814 |
size |
|
1815 |
"return the number of elements in the collection" |
|
1816 |
||
1817 |
^ lastIndex - firstIndex + 1 |
|
1818 |
! ! |
|
1819 |
||
3095 | 1820 |
!OrderedCollection methodsFor:'searching'! |
1 | 1821 |
|
1822 |
identityIndexOf:anObject |
|
33 | 1823 |
"return the index of anObject or 0 if not found. Compare using ==" |
1 | 1824 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1825 |
|index| |
1 | 1826 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1827 |
index := contentsArray |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1828 |
identityIndexOf:anObject |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1829 |
startingAt:firstIndex |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1830 |
endingAt:lastIndex. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1831 |
index == 0 ifTrue:[^ 0]. |
1 | 1832 |
^ index - firstIndex + 1 |
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1833 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1834 |
"Modified: 12.4.1996 / 17:58:25 / cg" |
1 | 1835 |
! |
1836 |
||
1837 |
identityIndexOf:anObject startingAt:startIndex |
|
33 | 1838 |
"return the index of anObject, starting search at startIndex. |
1839 |
Compare using ==; return 0 if not found in the collection" |
|
1 | 1840 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1841 |
|index| |
1 | 1842 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1843 |
index := contentsArray |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1844 |
identityIndexOf:anObject |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1845 |
startingAt:(startIndex + firstIndex - 1) |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1846 |
endingAt:lastIndex. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1847 |
index == 0 ifTrue:[^ 0]. |
1 | 1848 |
^ index - firstIndex + 1 |
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1849 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1850 |
"Modified: 12.4.1996 / 17:58:19 / cg" |
1 | 1851 |
! |
1852 |
||
1853 |
indexOf:anObject |
|
33 | 1854 |
"return the index of anObject or 0 if not found in the collection. |
1855 |
Compare using =" |
|
1 | 1856 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1857 |
|index| |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1858 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1859 |
index := contentsArray |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1860 |
indexOf:anObject |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1861 |
startingAt:firstIndex |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1862 |
endingAt:lastIndex. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1863 |
index == 0 ifTrue:[^ 0]. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1864 |
^ index - firstIndex + 1 |
1 | 1865 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1866 |
" |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1867 |
|c| |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1868 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1869 |
c := OrderedCollection new:10000. |
12035 | 1870 |
c add:10; add:20; add:30. |
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1871 |
c indexOf:99 |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1872 |
" |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1873 |
|
12035 | 1874 |
" |
1875 |
|c| |
|
1876 |
||
1877 |
c := OrderedCollection new:10000. |
|
1878 |
c add:10; add:20; add:30. |
|
1879 |
c indexOf:30 |
|
1880 |
" |
|
1881 |
||
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1882 |
"Modified: 12.4.1996 / 17:57:54 / cg" |
1 | 1883 |
! |
1884 |
||
12036 | 1885 |
indexOf:anObject ifAbsent:exceptionValue |
1886 |
"return the index of anObject or 0 if not found in the collection. |
|
1887 |
Compare using = |
|
1888 |
If the receiver does not contain anElement, |
|
1889 |
return the result of evaluating the argument, exceptionBlock." |
|
1890 |
||
1891 |
|index| |
|
1892 |
||
1893 |
index := contentsArray |
|
1894 |
indexOf:anObject |
|
1895 |
startingAt:firstIndex |
|
1896 |
endingAt:lastIndex. |
|
1897 |
index == 0 ifTrue:[^ exceptionValue value]. |
|
1898 |
^ index - firstIndex + 1 |
|
1899 |
||
1900 |
" |
|
1901 |
|c| |
|
1902 |
||
1903 |
c := OrderedCollection new:10000. |
|
1904 |
c add:10; add:20; add:30. |
|
1905 |
c indexOf:99 ifAbsent:'nope' |
|
1906 |
" |
|
1907 |
||
1908 |
" |
|
1909 |
|c| |
|
1910 |
||
1911 |
c := OrderedCollection new:10000. |
|
1912 |
c add:10; add:20; add:30. |
|
1913 |
c indexOf:30 ifAbsent:'nope' |
|
1914 |
" |
|
1915 |
! |
|
1916 |
||
1 | 1917 |
indexOf:anObject startingAt:startIndex |
33 | 1918 |
"return the index of anObject, starting search at startIndex. |
1919 |
Compare using =; return 0 if not found in the collection" |
|
1 | 1920 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1921 |
|index| |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1922 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1923 |
index := contentsArray |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1924 |
indexOf:anObject |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1925 |
startingAt:(startIndex + firstIndex - 1) |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1926 |
endingAt:lastIndex. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1927 |
index == 0 ifTrue:[^ 0]. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1928 |
^ index - firstIndex + 1 |
1 | 1929 |
|
1157
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1930 |
" |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1931 |
|c| |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1932 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1933 |
c := OrderedCollection new:10000. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1934 |
c add:1; add:2; add:3. |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1935 |
c indexOf:4 startingAt:5 |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1936 |
" |
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1937 |
|
c52d548036e2
faster search (limit to active range)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
1938 |
"Modified: 12.4.1996 / 17:58:53 / cg" |
1 | 1939 |
! ! |
1940 |
||
3095 | 1941 |
!OrderedCollection methodsFor:'testing'! |
1942 |
||
1943 |
includes:anObject |
|
1944 |
"return true if anObject is in the collection. Compare using =" |
|
1945 |
||
1946 |
^ (contentsArray |
|
1947 |
indexOf:anObject |
|
1948 |
startingAt:firstIndex |
|
1949 |
endingAt:lastIndex) ~~ 0 |
|
1950 |
||
1951 |
"Modified: 12.4.1996 / 17:57:27 / cg" |
|
1952 |
! |
|
1953 |
||
1954 |
includesIdentical:anObject |
|
1955 |
"return true if anObject is in the collection. Compare using ==" |
|
1956 |
||
1957 |
^ (contentsArray |
|
1958 |
identityIndexOf:anObject |
|
1959 |
startingAt:firstIndex |
|
1960 |
endingAt:lastIndex) ~~ 0 |
|
1961 |
||
1962 |
"Modified: 12.4.1996 / 17:57:09 / cg" |
|
5401 | 1963 |
! |
1964 |
||
5556 | 1965 |
isEmpty |
1966 |
"return true, if the receiver has no elements" |
|
1967 |
||
1968 |
^ lastIndex < firstIndex |
|
1969 |
! |
|
1970 |
||
1971 |
isFixedSize |
|
1972 |
"return true if the receiver cannot grow - this will vanish once |
|
1973 |
Arrays and Strings learn how to grow ..." |
|
1974 |
||
1975 |
^ false |
|
1976 |
! |
|
1977 |
||
5401 | 1978 |
isOrderedCollection |
1979 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
1980 |
true is returned here - the method is only redefined in Object." |
|
1981 |
||
1982 |
^ true |
|
1983 |
||
1984 |
||
5556 | 1985 |
! |
1986 |
||
1987 |
notEmpty |
|
1988 |
"return true, if the receiver has any elements" |
|
1989 |
||
1990 |
^ lastIndex >= firstIndex |
|
3095 | 1991 |
! ! |
1992 |
||
629 | 1993 |
!OrderedCollection class methodsFor:'documentation'! |
1994 |
||
1995 |
version |
|
15442 | 1996 |
^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.107 2013-06-28 08:35:54 cg Exp $' |
629 | 1997 |
! ! |
14616 | 1998 |