author | Stefan Vogel <sv@exept.de> |
Thu, 16 Apr 2015 18:28:45 +0200 | |
branch | expecco_2_7_5 |
changeset 18220 | 361e98951d47 |
parent 17212 | 2e02d9d621da |
child 18120 | e3a375d5f6a8 |
child 19100 | c5b67cced033 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
14058
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
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 |
" |
|
5497 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
SequenceableCollection subclass:#ArrayedCollection |
14112 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Abstract' |
|
1 | 19 |
! |
20 |
||
2125 | 21 |
!ArrayedCollection class methodsFor:'documentation'! |
82 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
14058
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
26 |
All Rights Reserved |
1 | 27 |
|
82 | 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 |
! |
|
1 | 36 |
|
82 | 37 |
documentation |
38 |
" |
|
249 | 39 |
ArrayedCollection is an abstract superclass for all collections where |
1171 | 40 |
the elements can be accessed via an integer index, |
17122 | 41 |
AND the collection is a fixed size collection. |
42 |
||
1171 | 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. |
|
17122 | 46 |
(many other collections keep a reference to the physical container, |
47 |
which can be easily replaced) |
|
360 | 48 |
|
2146 | 49 |
[Warning:] |
50 |
currently, ST/X supports growing fix-size collections |
|
17122 | 51 |
(such as Arrays, ByteArrays and Strings). |
52 |
However, this is done in a very slow way (using #become). |
|
53 |
Become is a very slow operation in a direct-pointer Smalltalk system |
|
54 |
(which ST/X and many other 'modern' Smalltalks are). |
|
55 |
||
2146 | 56 |
Therefore, you SHOULD rewrite any application that does this, |
17122 | 57 |
to make use of OrderedCollections or any other collection which can grow fast. |
2146 | 58 |
To remind you of that, a warning message is sent to the |
59 |
standard error whenever such an operation is performed (see #grow). |
|
17122 | 60 |
|
61 |
Also note, that some other Smalltalk systems do NOT allow |
|
2146 | 62 |
fix size collection to change their size, and that future |
63 |
ST/X versions may be changed to trigger an error (instead of a |
|
64 |
warning) in those situations. |
|
1283 | 65 |
|
1289 | 66 |
[author:] |
2146 | 67 |
Claus Gittinger |
1289 | 68 |
|
1283 | 69 |
[see also:] |
2146 | 70 |
OrderedCollection Array |
82 | 71 |
" |
92 | 72 |
! ! |
73 |
||
2125 | 74 |
!ArrayedCollection class methodsFor:'instance creation'! |
1 | 75 |
|
5626 | 76 |
newFrom:aCollection |
77 |
"Return an instance of me containing the same elements as aCollection." |
|
78 |
||
79 |
|newArray idx sz| |
|
80 |
||
81 |
sz := aCollection size. |
|
82 |
newArray := self new:sz. |
|
83 |
aCollection isSequenceable ifTrue:[ |
|
84 |
newArray replaceFrom:1 to:sz with:aCollection startingAt:1 |
|
85 |
] ifFalse:[ |
|
86 |
idx := 1. |
|
87 |
aCollection do:[:element | |
|
88 |
newArray at:idx put:element. |
|
89 |
idx := idx + 1. |
|
90 |
]. |
|
91 |
]. |
|
92 |
^ newArray |
|
93 |
||
94 |
" |
|
95 |
Array newFrom: #[1 2 3] |
|
96 |
#[1 2 3] as: Array |
|
97 |
#[1 2 3] as: ByteArray |
|
98 |
#($c $h $r) as: String |
|
99 |
#($c $h $r) as: Text |
|
100 |
" |
|
101 |
! |
|
102 |
||
16711 | 103 |
newWithSize:size |
104 |
"return a new collection of size. |
|
105 |
For variable size collections, this is different from #new:, |
|
106 |
in that #new: creates an empty collection with preallocated size, |
|
107 |
while #withSize: creates a non empty one." |
|
108 |
||
109 |
^ self new:size. |
|
110 |
||
111 |
" |
|
112 |
(OrderedCollection new:10) |
|
113 |
(OrderedCollection newWithSize:10) |
|
114 |
(Array new:10) |
|
115 |
(Array newWithSize:10) |
|
116 |
" |
|
117 |
! |
|
118 |
||
1 | 119 |
with:element |
120 |
"return a new SequenceableCollection with one element:anObject" |
|
121 |
||
122 |
|newCollection| |
|
123 |
||
124 |
newCollection := self new:1. |
|
125 |
newCollection at:1 put:element. |
|
126 |
^newCollection |
|
125 | 127 |
|
128 |
" |
|
129 |
OrderedCollection with:1 |
|
130 |
SortedCollection with:99 |
|
131 |
" |
|
1 | 132 |
! |
133 |
||
134 |
with:first with:second |
|
135 |
"return a new SequenceableCollection with two elements" |
|
136 |
||
137 |
|newCollection| |
|
138 |
||
139 |
newCollection := self new:2. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
140 |
newCollection at:1 put:first; at:2 put:second. |
1 | 141 |
^newCollection |
125 | 142 |
|
143 |
" |
|
144 |
OrderedCollection with:1 with:2 |
|
145 |
SortedCollection with:99 with:3 |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
146 |
Array with:1 with:2 |
125 | 147 |
" |
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
148 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
149 |
"Modified: 22.1.1997 / 19:35:43 / cg" |
1 | 150 |
! |
151 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
152 |
with:a1 with:a2 with:a3 |
1 | 153 |
"return a new SequenceableCollection with three elements" |
154 |
||
155 |
|newCollection| |
|
156 |
||
157 |
newCollection := self new:3. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
158 |
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
|
159 |
^ newCollection |
125 | 160 |
|
161 |
" |
|
162 |
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
|
163 |
Array with:1 with:2 with:3 |
125 | 164 |
" |
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
165 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
166 |
"Modified: 22.1.1997 / 19:35:47 / cg" |
1 | 167 |
! |
168 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
169 |
with:a1 with:a2 with:a3 with:a4 |
1 | 170 |
"return a new SequenceableCollection with four elements" |
171 |
||
172 |
|newCollection| |
|
173 |
||
174 |
newCollection := self new:4. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
175 |
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
|
176 |
^ newCollection |
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 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
" |
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 |
"Modified: 22.1.1997 / 19:35:52 / cg" |
1 | 184 |
! |
185 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
186 |
with:a1 with:a2 with:a3 with:a4 with:a5 |
1 | 187 |
"return a new SequenceableCollection with five elements" |
188 |
||
189 |
|newCollection| |
|
190 |
||
191 |
newCollection := self new:5. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
192 |
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
|
193 |
at:5 put:a5. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
194 |
^ newCollection |
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 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
197 |
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
|
198 |
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
|
199 |
" |
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 |
"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
|
202 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
203 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
204 |
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
|
205 |
"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
|
206 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
207 |
|newCollection| |
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 |
newCollection := self new:6. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
210 |
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
|
211 |
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
|
212 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
213 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
214 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
218 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
219 |
"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
|
220 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
221 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
222 |
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
|
223 |
"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
|
224 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
225 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
226 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
227 |
newCollection := self new:7. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
228 |
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
|
229 |
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
|
230 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
231 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
232 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
236 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
237 |
"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
|
238 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
239 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
240 |
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
|
241 |
"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
|
242 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
243 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
244 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
245 |
newCollection := self new:8. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
246 |
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
|
247 |
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
|
248 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
249 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
250 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
254 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2146
diff
changeset
|
255 |
"Modified: 22.1.1997 / 19:35:21 / cg" |
1 | 256 |
! |
257 |
||
14013
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
258 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 with:a7 with:a8 with:a9 |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
259 |
"return a new SequenceableCollection with nine elements" |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
260 |
|
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
261 |
|newCollection| |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
262 |
|
14015
579bff670366
changed: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
14013
diff
changeset
|
263 |
newCollection := self new:9. |
14013
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
264 |
newCollection at:1 put:a1; at:2 put:a2; at:3 put:a3; at:4 put:a4; |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
265 |
at:5 put:a5; at:6 put:a6; at:7 put:a7; at:8 put:a8; |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
266 |
at:9 put:a9. |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
267 |
^ newCollection |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
268 |
|
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
269 |
" |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
270 |
OrderedCollection with:1 with:2 with:3 with:4 with:5 with:6 with:7 with:8 with:9 |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
271 |
Array with:1 with:2 with:3 with:4 with:5 with:6 with:7 with:8w ith:9 |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
272 |
" |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
273 |
|
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
274 |
"Created: / 14-02-2012 / 17:43:07 / cg" |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
275 |
! |
412c81f15eb4
added: #with:with:with:with:with:with:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
11471
diff
changeset
|
276 |
|
1 | 277 |
withAll:aCollection |
278 |
"return a new Collection with all elements taken from the argument, |
|
279 |
aCollection" |
|
280 |
||
281 |
|newCollection newSize |
|
282 |
index "{ Class: SmallInteger }" | |
|
283 |
||
284 |
newSize := aCollection size. |
|
285 |
newCollection := self new:newSize. |
|
359 | 286 |
aCollection isSequenceable ifTrue:[ |
14058
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
287 |
"/ |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
288 |
"/ aCollection has indexed elements |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
289 |
"/ a block-replace may be faster |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
290 |
"/ |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
291 |
newCollection replaceFrom:1 to:newSize with:aCollection startingAt:1 |
1 | 292 |
] ifFalse:[ |
14058
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
293 |
"/ |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
294 |
"/ must enumerate the elements individually |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
295 |
"/ |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
296 |
index := 1. |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
297 |
aCollection do:[:element | |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
298 |
newCollection at:index put:element. |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
299 |
index := index + 1 |
670252a21fb9
changed: #inspector2TabForHexDump
Claus Gittinger <cg@exept.de>
parents:
14057
diff
changeset
|
300 |
] |
1 | 301 |
]. |
302 |
^ newCollection |
|
125 | 303 |
|
304 |
" |
|
305 |
OrderedCollection withAll:#(1 2 3 4 5) |
|
306 |
SortedCollection withAll:#(99 17 53 1 101) |
|
307 |
" |
|
1171 | 308 |
|
309 |
"Modified: 13.4.1996 / 12:14:38 / cg" |
|
1 | 310 |
! ! |
311 |
||
2125 | 312 |
!ArrayedCollection class methodsFor:'queries'! |
68 | 313 |
|
602 | 314 |
growIsCheap |
315 |
"return true, if this collection can easily grow |
|
316 |
(i.e. without a need for become:). |
|
317 |
Since this is the superclass of all indexed fix-size collections, |
|
318 |
return false here." |
|
68 | 319 |
|
602 | 320 |
^ false |
8893 | 321 |
! |
322 |
||
323 |
isAbstract |
|
11230 | 324 |
"Return if this class is an abstract class. |
325 |
True is returned for ArrayedCollection here; false for subclasses. |
|
326 |
Abstract subclasses must redefine again." |
|
327 |
||
8893 | 328 |
^ self == ArrayedCollection |
2 | 329 |
! ! |
330 |
||
17211 | 331 |
!ArrayedCollection methodsFor:'adding & removing'! |
10797 | 332 |
|
333 |
addAll:aCollection |
|
334 |
"add all elements of the argument, aCollection to the receiver. |
|
335 |
Returns the argument, aCollection (sigh). |
|
336 |
||
337 |
Redefined here, to perform only a single slow grow operation" |
|
338 |
||
339 |
|mySize| |
|
340 |
||
341 |
mySize := self size. |
|
342 |
self grow:mySize + aCollection size. |
|
343 |
||
344 |
aCollection do:[:element | |
|
345 |
mySize := mySize + 1. |
|
346 |
self at:mySize put:element |
|
347 |
]. |
|
348 |
^ aCollection |
|
349 |
||
350 |
" |
|
351 |
#(1 2 3 4) addAll:#(5 6 7 8); yourself |
|
352 |
" |
|
17212 | 353 |
! |
354 |
||
355 |
removeAll |
|
356 |
"{ Pragma: +optSpace }" |
|
357 |
||
358 |
"remove all elements from the receiver. Returns the receiver. |
|
359 |
||
360 |
For ArrayedCollections (which are actually fixed-size collections), |
|
361 |
this is a slow operation, since a #become: is required to update |
|
362 |
all owners. Better use a collection which is prepared for growing |
|
363 |
(i.e. an OrderedCollection). |
|
364 |
We output a warning message here, to remind you about that." |
|
365 |
||
366 |
'ArrayedCollection [info]: slow removeAll operation (' infoPrint. |
|
367 |
self class name infoPrint. ')' infoPrintCR. |
|
368 |
||
369 |
self become:(self copyEmpty) |
|
370 |
||
371 |
" |
|
372 |
#(1 2 3 4 5) copy removeAll |
|
373 |
#(1 2 3 4 5) removeAll |
|
374 |
" |
|
375 |
||
376 |
"Modified: 10.1.1997 / 15:14:55 / cg" |
|
10797 | 377 |
! ! |
378 |
||
249 | 379 |
!ArrayedCollection methodsFor:'copying'! |
380 |
||
381 |
copyEmptyAndGrow:size |
|
14615 | 382 |
"return a new instance of the receiver's species with size |
249 | 383 |
nilled elements and any named instance variables copied." |
384 |
||
14112 | 385 |
"Performance optimization for classes like Array, String, ..., |
386 |
which have no named instance vars" |
|
249 | 387 |
|
14112 | 388 |
self class instSize == 0 ifTrue:[ |
389 |
^ self species new:size |
|
249 | 390 |
]. |
391 |
^ super copyEmptyAndGrow:size |
|
392 |
! ! |
|
393 |
||
602 | 394 |
!ArrayedCollection methodsFor:'error handling'! |
395 |
||
396 |
fixedSizeError |
|
1998 | 397 |
"{ Pragma: +optSpace }" |
398 |
||
602 | 399 |
"report an error that size of the collection cannot be changed. |
1171 | 400 |
This is not used right now (instead, a warning is sent to stderr |
1579 | 401 |
in the #grow method); however, future versions of ST/X may no longer |
1171 | 402 |
allow fixed size collection to grow. |
403 |
Read the documentation on why things are that way ..." |
|
602 | 404 |
|
405 |
^ self error:'cannot change size' |
|
1171 | 406 |
|
1579 | 407 |
"Modified: 18.7.1996 / 21:39:09 / cg" |
602 | 408 |
! ! |
409 |
||
17212 | 410 |
!ArrayedCollection methodsFor:'growing'! |
411 |
||
412 |
grow:newSize |
|
413 |
"grow the receiver i.e. cut off everything after newSize. |
|
414 |
Warning: this may be a slow operation due to the use of become |
|
415 |
- you should write your collection classes to avoid the use of become. |
|
416 |
You have been warned." |
|
417 |
||
418 |
|newArray oldSize| |
|
419 |
||
420 |
oldSize := self size. |
|
421 |
(newSize ~~ oldSize) ifTrue:[ |
|
422 |
InfoPrinting ifTrue:[ |
|
423 |
"/ |
|
424 |
"/ output a warning - you should rewrite your application |
|
425 |
"/ to use some collection which implements grow: more efficient |
|
426 |
"/ (i.e. use OrderedCollection instead of Array ..) |
|
427 |
"/ |
|
428 |
'ArrayedCollection [warning]: slow grow operation (' errorPrint. |
|
429 |
self class name infoPrint. ') ' errorPrintCR. |
|
430 |
Context showWhereWeCameFrom. |
|
431 |
]. |
|
432 |
||
433 |
newArray := self species new:newSize. |
|
434 |
newArray replaceFrom:1 to:(newSize min:oldSize) with:self. |
|
435 |
self become:newArray. |
|
436 |
] |
|
437 |
||
438 |
" |
|
439 |
#(1 2 3 4 5 6) add:7 |
|
440 |
#(1 2 3 4 5 6) remove:5 |
|
441 |
#(1 2 3 4 5 6) copy grow:3 |
|
442 |
#(1 2 3 4 5 6) copy grow:10 |
|
443 |
'hello world' copy grow:5 |
|
444 |
'hello' copy grow:20 |
|
445 |
" |
|
446 |
||
447 |
"Modified: 10.1.1997 / 15:14:43 / cg" |
|
448 |
! ! |
|
449 |
||
14112 | 450 |
|
602 | 451 |
!ArrayedCollection methodsFor:'printing & storing'! |
452 |
||
453 |
storeOn:aStream |
|
454 |
"output a printed representation (which can be re-read with readFrom:) |
|
455 |
onto the argument aStream. Redefined to output index access." |
|
456 |
||
457 |
|index "{ Class: SmallInteger }"| |
|
458 |
||
459 |
thisContext isRecursive ifTrue:[ |
|
15855 | 460 |
RecursiveStoreError raiseRequestWith:self. |
2290 | 461 |
'ArrayedCollection [error]: storeOn: of self referencing collection.' errorPrintCR. |
462 |
aStream nextPutAll:'#recursive'. |
|
463 |
^ self |
|
602 | 464 |
]. |
465 |
||
466 |
aStream nextPutAll:'(('; nextPutAll:self class name; nextPutAll:' new:'. |
|
467 |
self size printOn:aStream. |
|
468 |
aStream nextPutAll:')'. |
|
469 |
index := 1. |
|
470 |
self do:[:element | |
|
2290 | 471 |
aStream nextPutAll:' at:'. index printOn:aStream. aStream nextPutAll:' put:('. |
472 |
element storeOn:aStream. |
|
473 |
aStream nextPutAll:');'. |
|
474 |
index := index + 1 |
|
602 | 475 |
]. |
476 |
index > 1 ifTrue:[aStream nextPutAll:' yourself']. |
|
477 |
aStream nextPut:$) |
|
478 |
||
479 |
" |
|
480 |
(Array with:(1@2) with:(1->2)) storeString |
|
481 |
" |
|
1414 | 482 |
|
2290 | 483 |
"Modified: 28.1.1997 / 00:39:59 / cg" |
602 | 484 |
! ! |
485 |
||
5557 | 486 |
!ArrayedCollection methodsFor:'queries'! |
487 |
||
488 |
size |
|
489 |
"redefined to re-enable size->basicSize forwarding |
|
490 |
(it is caught in SequencableCollection)" |
|
491 |
||
492 |
^ self basicSize |
|
6548 | 493 |
! |
494 |
||
495 |
speciesForAdding |
|
496 |
"redefined here, since grow is not cheap. |
|
497 |
Used by functions which create a growing collection (see collect:with:, for example)" |
|
498 |
||
499 |
^ OrderedCollection |
|
5557 | 500 |
! ! |
501 |
||
2125 | 502 |
!ArrayedCollection class methodsFor:'documentation'! |
628 | 503 |
|
504 |
version |
|
17212 | 505 |
^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.69 2014-12-11 17:08:43 cg Exp $' |
506 |
! |
|
507 |
||
508 |
version_CVS |
|
509 |
^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.69 2014-12-11 17:08:43 cg Exp $' |
|
628 | 510 |
! ! |
14615 | 511 |