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