author | Claus Gittinger <cg@exept.de> |
Thu, 15 Jul 1999 21:45:54 +0200 | |
changeset 4392 | 26fb48f04e1b |
parent 2689 | ada9b102abcf |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
155 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
SequenceableCollection subclass:#ArrayedCollection |
|
1111 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Collections-Abstract' |
|
1 | 18 |
! |
19 |
||
2125 | 20 |
!ArrayedCollection class methodsFor:'documentation'! |
82 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
155 | 25 |
All Rights Reserved |
1 | 26 |
|
82 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
82 | 36 |
documentation |
37 |
" |
|
249 | 38 |
ArrayedCollection is an abstract superclass for all collections where |
1171 | 39 |
the elements can be accessed via an integer index, |
40 |
AND the collection is a fixed size collection. |
|
41 |
Those fixed size collections cannot easily grow, since they store the |
|
42 |
elements directly within the object and a grow operation can only be done |
|
43 |
by #becoming another object. |
|
360 | 44 |
(other collections keep a reference to the physical container, which |
45 |
can be easily replaced) |
|
46 |
||
2146 | 47 |
[Warning:] |
48 |
currently, ST/X supports growing fix-size collections |
|
49 |
(such as Arrays, ByteArrays and Strings). However, this |
|
50 |
is done in a very slow way (using #become). |
|
51 |
Become is a very slow operation in a direct-pointer smalltalk |
|
52 |
system. |
|
53 |
\ |
|
54 |
Therefore, you SHOULD rewrite any application that does this, |
|
55 |
to make use of OrderedCollections or any other collection which |
|
56 |
can grow faster. |
|
57 |
To remind you of that, a warning message is sent to the |
|
58 |
standard error whenever such an operation is performed (see #grow). |
|
59 |
\ |
|
60 |
Also note, that some other smalltalk systems do NOT allow |
|
61 |
fix size collection to change their size, and that future |
|
62 |
ST/X versions may be changed to trigger an error (instead of a |
|
63 |
warning) in those situations. |
|
1283 | 64 |
|
1289 | 65 |
[author:] |
2146 | 66 |
Claus Gittinger |
1289 | 67 |
|
1283 | 68 |
[see also:] |
2146 | 69 |
OrderedCollection Array |
82 | 70 |
" |
92 | 71 |
! ! |
72 |
||
2125 | 73 |
!ArrayedCollection class methodsFor:'instance creation'! |
1 | 74 |
|
75 |
with:element |
|
76 |
"return a new SequenceableCollection with one element:anObject" |
|
77 |
||
78 |
|newCollection| |
|
79 |
||
80 |
newCollection := self new:1. |
|
81 |
newCollection at:1 put:element. |
|
82 |
^newCollection |
|
125 | 83 |
|
84 |
" |
|
85 |
OrderedCollection with:1 |
|
86 |
SortedCollection with:99 |
|
87 |
" |
|
1 | 88 |
! |
89 |
||
90 |
with:first with:second |
|
91 |
"return a new SequenceableCollection with two elements" |
|
92 |
||
93 |
|newCollection| |
|
94 |
||
95 |
newCollection := self new:2. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
96 |
newCollection at:1 put:first; at:2 put:second. |
1 | 97 |
^newCollection |
125 | 98 |
|
99 |
" |
|
100 |
OrderedCollection with:1 with:2 |
|
101 |
SortedCollection with:99 with:3 |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
102 |
Array with:1 with:2 |
125 | 103 |
" |
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
104 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
105 |
"Modified: 22.1.1997 / 19:35:43 / cg" |
1 | 106 |
! |
107 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
108 |
with:a1 with:a2 with:a3 |
1 | 109 |
"return a new SequenceableCollection with three elements" |
110 |
||
111 |
|newCollection| |
|
112 |
||
113 |
newCollection := self new:3. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
114 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
115 |
^ newCollection |
125 | 116 |
|
117 |
" |
|
118 |
OrderedCollection with:1 with:2 with:3 |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
119 |
Array with:1 with:2 with:3 |
125 | 120 |
" |
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
121 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
122 |
"Modified: 22.1.1997 / 19:35:47 / cg" |
1 | 123 |
! |
124 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
125 |
with:a1 with:a2 with:a3 with:a4 |
1 | 126 |
"return a new SequenceableCollection with four elements" |
127 |
||
128 |
|newCollection| |
|
129 |
||
130 |
newCollection := self new:4. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
131 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3; at:4 put:a4. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
132 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
133 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
134 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
135 |
OrderedCollection with:1 with:2 with:3 with:4 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
136 |
Array with:1 with:2 with:3 with:4 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
137 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
138 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
139 |
"Modified: 22.1.1997 / 19:35:52 / cg" |
1 | 140 |
! |
141 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
142 |
with:a1 with:a2 with:a3 with:a4 with:a5 |
1 | 143 |
"return a new SequenceableCollection with five elements" |
144 |
||
145 |
|newCollection| |
|
146 |
||
147 |
newCollection := self new:5. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
148 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3; at:4 put:a4; |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
149 |
at:5 put:a5. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
150 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
151 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
152 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
153 |
OrderedCollection with:1 with:2 with:3 with:4 with:5 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
154 |
Array with:1 with:2 with:3 with:4 with:5 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
155 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
156 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
157 |
"Modified: 22.1.1997 / 19:35:57 / cg" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
158 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
159 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
160 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
161 |
"return a new SequenceableCollection with six elements" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
162 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
163 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
164 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
165 |
newCollection := self new:6. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
166 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3; at:4 put:a4; |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
167 |
at:5 put:a5; at:6 put:a6. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
168 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
169 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
170 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
171 |
OrderedCollection with:1 with:2 with:3 with:4 with:5 with:6 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
172 |
Array with:1 with:2 with:3 with:4 with:5 with:6 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
173 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
174 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
175 |
"Modified: 22.1.1997 / 19:36:03 / cg" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
176 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
177 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
178 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 with:a7 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
179 |
"return a new SequenceableCollection with seven elements" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
180 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
181 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
182 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
183 |
newCollection := self new:7. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
184 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3; at:4 put:a4; |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
185 |
at:5 put:a5; at:6 put:a6; at:7 put:a7. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
186 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
187 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
188 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
189 |
OrderedCollection with:1 with:2 with:3 with:4 with:5 with:6 with:7 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
190 |
Array with:1 with:2 with:3 with:4 with:5 with:6 with:7 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
191 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
192 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
193 |
"Modified: 22.1.1997 / 19:36:20 / cg" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
194 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
195 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
196 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 with:a7 with:a8 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
197 |
"return a new SequenceableCollection with eight elements" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
198 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
199 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
200 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
201 |
newCollection := self new:8. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
202 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3; at:4 put:a4; |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
203 |
at:5 put:a5; at:6 put:a6; at:7 put:a7; at:8 put:a8. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
204 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
205 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
206 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
207 |
OrderedCollection with:1 with:2 with:3 with:4 with:5 with:6 with:7 with:8 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
208 |
Array with:1 with:2 with:3 with:4 with:5 with:6 with:7 with:8 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
209 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
210 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
211 |
"Modified: 22.1.1997 / 19:35:21 / cg" |
1 | 212 |
! |
213 |
||
214 |
withAll:aCollection |
|
215 |
"return a new Collection with all elements taken from the argument, |
|
216 |
aCollection" |
|
217 |
||
218 |
|newCollection newSize |
|
219 |
index "{ Class: SmallInteger }" | |
|
220 |
||
221 |
newSize := aCollection size. |
|
222 |
newCollection := self new:newSize. |
|
359 | 223 |
aCollection isSequenceable ifTrue:[ |
1998 | 224 |
"/ |
225 |
"/ aCollection has indexed elements |
|
226 |
"/ a block-replace may be faster |
|
227 |
"/ |
|
228 |
newCollection replaceFrom:1 to:newSize with:aCollection startingAt:1 |
|
1 | 229 |
] ifFalse:[ |
1998 | 230 |
"/ |
231 |
"/ must enumerate the elements individually |
|
232 |
"/ |
|
233 |
index := 1. |
|
234 |
aCollection do:[:element | |
|
235 |
newCollection at:index put:element. |
|
236 |
index := index + 1 |
|
237 |
] |
|
1 | 238 |
]. |
239 |
^ newCollection |
|
125 | 240 |
|
241 |
" |
|
242 |
OrderedCollection withAll:#(1 2 3 4 5) |
|
243 |
SortedCollection withAll:#(99 17 53 1 101) |
|
244 |
" |
|
1171 | 245 |
|
246 |
"Modified: 13.4.1996 / 12:14:38 / cg" |
|
1 | 247 |
! ! |
248 |
||
2125 | 249 |
!ArrayedCollection class methodsFor:'queries'! |
68 | 250 |
|
602 | 251 |
growIsCheap |
252 |
"return true, if this collection can easily grow |
|
253 |
(i.e. without a need for become:). |
|
254 |
Since this is the superclass of all indexed fix-size collections, |
|
255 |
return false here." |
|
68 | 256 |
|
602 | 257 |
^ false |
2 | 258 |
! ! |
259 |
||
249 | 260 |
!ArrayedCollection methodsFor:'copying'! |
261 |
||
262 |
copyEmptyAndGrow:size |
|
263 |
"return a new instance of the receivers species with size |
|
264 |
nilled elements and any named instance variables copied." |
|
265 |
||
266 |
"special case for Array, which has no named instance vars" |
|
267 |
||
356 | 268 |
|cls| |
269 |
||
270 |
(cls := self class) instSize == 0 ifTrue:[ |
|
271 |
^ cls new:size |
|
249 | 272 |
]. |
273 |
^ super copyEmptyAndGrow:size |
|
274 |
! ! |
|
275 |
||
602 | 276 |
!ArrayedCollection methodsFor:'error handling'! |
277 |
||
278 |
fixedSizeError |
|
1998 | 279 |
"{ Pragma: +optSpace }" |
280 |
||
602 | 281 |
"report an error that size of the collection cannot be changed. |
1171 | 282 |
This is not used right now (instead, a warning is sent to stderr |
1579 | 283 |
in the #grow method); however, future versions of ST/X may no longer |
1171 | 284 |
allow fixed size collection to grow. |
285 |
Read the documentation on why things are that way ..." |
|
602 | 286 |
|
287 |
^ self error:'cannot change size' |
|
1171 | 288 |
|
1579 | 289 |
"Modified: 18.7.1996 / 21:39:09 / cg" |
602 | 290 |
! ! |
291 |
||
292 |
!ArrayedCollection methodsFor:'printing & storing'! |
|
293 |
||
294 |
storeOn:aStream |
|
295 |
"output a printed representation (which can be re-read with readFrom:) |
|
296 |
onto the argument aStream. Redefined to output index access." |
|
297 |
||
298 |
|index "{ Class: SmallInteger }"| |
|
299 |
||
300 |
thisContext isRecursive ifTrue:[ |
|
2290 | 301 |
'ArrayedCollection [error]: storeOn: of self referencing collection.' errorPrintCR. |
302 |
aStream nextPutAll:'#recursive'. |
|
303 |
^ self |
|
602 | 304 |
]. |
305 |
||
306 |
aStream nextPutAll:'(('; nextPutAll:self class name; nextPutAll:' new:'. |
|
307 |
self size printOn:aStream. |
|
308 |
aStream nextPutAll:')'. |
|
309 |
index := 1. |
|
310 |
self do:[:element | |
|
2290 | 311 |
aStream nextPutAll:' at:'. index printOn:aStream. aStream nextPutAll:' put:('. |
312 |
element storeOn:aStream. |
|
313 |
aStream nextPutAll:');'. |
|
314 |
index := index + 1 |
|
602 | 315 |
]. |
316 |
index > 1 ifTrue:[aStream nextPutAll:' yourself']. |
|
317 |
aStream nextPut:$) |
|
318 |
||
319 |
" |
|
320 |
(Array with:(1@2) with:(1->2)) storeString |
|
321 |
" |
|
1414 | 322 |
|
2290 | 323 |
"Modified: 28.1.1997 / 00:39:59 / cg" |
602 | 324 |
! ! |
325 |
||
2 | 326 |
!ArrayedCollection methodsFor:'resizing'! |
1 | 327 |
|
2 | 328 |
grow:newSize |
125 | 329 |
"grow the receiver i.e. cut off everything after newSize. |
330 |
Warning: this may be a slow operation due to the use of become |
|
331 |
- you should write your collection classes to avoid the use of become. |
|
155 | 332 |
You have been warned." |
2 | 333 |
|
599 | 334 |
|newArray oldSize sender| |
1 | 335 |
|
27 | 336 |
oldSize := self size. |
337 |
(newSize ~~ oldSize) ifTrue:[ |
|
2125 | 338 |
InfoPrinting ifTrue:[ |
339 |
"/ |
|
340 |
"/ output a warning - you should rewrite your application |
|
341 |
"/ to use some collection which implements grow: more efficient |
|
342 |
"/ (i.e. use OrderedCollection instead of Array ..) |
|
343 |
"/ |
|
344 |
'ArrayedCollection [info]: slow grow operation (' infoPrint. |
|
345 |
self class name infoPrint. ') via ' infoPrint. |
|
346 |
sender := thisContext sender. |
|
347 |
sender methodPrintString infoPrint. |
|
348 |
' from ' infoPrint. sender sender methodPrintString infoPrintCR. |
|
349 |
]. |
|
360 | 350 |
|
2125 | 351 |
newArray := self species new:newSize. |
352 |
newArray replaceFrom:1 to:(newSize min:oldSize) with:self. |
|
353 |
self become:newArray. |
|
2 | 354 |
] |
125 | 355 |
|
356 |
" |
|
590
3ffb78fb2716
report sender in slow grow warning
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
357 |
#(1 2 3 4 5 6) add:7 |
3ffb78fb2716
report sender in slow grow warning
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
358 |
#(1 2 3 4 5 6) remove:5 |
125 | 359 |
#(1 2 3 4 5 6) copy grow:3 |
155 | 360 |
#(1 2 3 4 5 6) copy grow:10 |
125 | 361 |
'hello world' copy grow:5 |
155 | 362 |
'hello' copy grow:20 |
125 | 363 |
" |
1428 | 364 |
|
2125 | 365 |
"Modified: 10.1.1997 / 15:14:43 / cg" |
360 | 366 |
! |
367 |
||
368 |
removeAll |
|
1998 | 369 |
"{ Pragma: +optSpace }" |
370 |
||
1164 | 371 |
"remove all elements from the receiver. Returns the receiver. |
372 |
||
1111 | 373 |
For ArrayedCollections (which are actually fixed-size collections), |
374 |
this is a slow operation, since a #become: is required to update |
|
375 |
all owners. Better use a collection which is prepared for growing |
|
376 |
(i.e. an OrderedCollection). |
|
377 |
We output a warning message here, to remind you about that." |
|
378 |
||
2125 | 379 |
'ArrayedCollection [info]: slow removeAll operation (' infoPrint. |
1428 | 380 |
self class name infoPrint. ')' infoPrintCR. |
360 | 381 |
|
382 |
self become:(self copyEmpty) |
|
383 |
||
384 |
" |
|
385 |
#(1 2 3 4 5) copy removeAll |
|
386 |
#(1 2 3 4 5) removeAll |
|
387 |
" |
|
1111 | 388 |
|
2125 | 389 |
"Modified: 10.1.1997 / 15:14:55 / cg" |
2 | 390 |
! ! |
1 | 391 |
|
602 | 392 |
!ArrayedCollection methodsFor:'testing'! |
393 |
||
394 |
includesKey:anIndex |
|
395 |
"return true, if anIndex is a valid key. |
|
396 |
NOTICE: in ST-80, this message is only defined for Dictionaries, |
|
397 |
however, having a common protocol with indexed collections |
|
398 |
often simplifies things." |
|
399 |
||
400 |
^ (anIndex >= 1) and:[anIndex <= self size] |
|
1 | 401 |
|
602 | 402 |
" |
403 |
#(1 2 3) includesKey:4 |
|
404 |
#(1 2 3) includesKey:3 |
|
405 |
" |
|
406 |
! |
|
1 | 407 |
|
602 | 408 |
size |
409 |
"redefined to re-enable size->basicSize forwarding |
|
2689 | 410 |
(it is caught in SequencableCollection)" |
602 | 411 |
|
412 |
^ self basicSize |
|
1 | 413 |
! ! |
414 |
||
2125 | 415 |
!ArrayedCollection class methodsFor:'documentation'! |
628 | 416 |
|
417 |
version |
|
2689 | 418 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/ArrColl.st,v 1.44 1997-06-16 18:20:15 cg Exp $' |
628 | 419 |
! ! |