ArrayedCollection.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 18:00:32 +0100
changeset 628 7aa563e4c64a
parent 602 771ab7a8c4bf
child 916 a050d17c7e1f
permissions -rw-r--r--
version at the end
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
SequenceableCollection subclass:#ArrayedCollection
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
    14
	 instanceVariableNames:''
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
    15
	 classVariableNames:''
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
    16
	 poolDictionaries:''
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
    17
	 category:'Collections-Abstract'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
82
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    20
!ArrayedCollection class methodsFor:'documentation'!
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    21
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    22
copyright
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    23
"
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
    25
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
82
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    27
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    28
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    30
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    31
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    32
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    33
"
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    34
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
82
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    36
documentation
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    37
"
249
claus
parents: 213
diff changeset
    38
    ArrayedCollection is an abstract superclass for all collections where 
claus
parents: 213
diff changeset
    39
    the elements can be accessed via an integer index.
360
claus
parents: 359
diff changeset
    40
    And the collection is a fixed size collection. Those fixed size collections
claus
parents: 359
diff changeset
    41
    cannot easily grow, since they store the elements directly within the
claus
parents: 359
diff changeset
    42
    object and a grow operation can only be done by becoming another object.
claus
parents: 359
diff changeset
    43
    (other collections keep a reference to the physical container, which
claus
parents: 359
diff changeset
    44
     can be easily replaced)
claus
parents: 359
diff changeset
    45
claus
parents: 359
diff changeset
    46
    Notice: currently, ST/X supports growing fix-size collections
claus
parents: 359
diff changeset
    47
	    (such as Arrays, ByteArrays and Strings). However, this
399
claus
parents: 384
diff changeset
    48
	    can only be done in a very slow way (using #become).
360
claus
parents: 359
diff changeset
    49
	    Therefore, you SHOULD rewrite any application that does this
claus
parents: 359
diff changeset
    50
	    to make use of OrderedCollection or any other collection which
claus
parents: 359
diff changeset
    51
	    can grow faster.
claus
parents: 359
diff changeset
    52
	    To remind you of that, a warning message is sent to the
claus
parents: 359
diff changeset
    53
	    standard error whenever such an operation is performed.
claus
parents: 359
diff changeset
    54
claus
parents: 359
diff changeset
    55
	    Also note, that some other smalltalk systems do NOT allow
claus
parents: 359
diff changeset
    56
	    fix size collection to change their size, and that future
claus
parents: 359
diff changeset
    57
	    ST/X versions may be changed to trigger an error (instead of a
claus
parents: 359
diff changeset
    58
	    warning) in those situations.
82
0147b4f725ae *** empty log message ***
claus
parents: 68
diff changeset
    59
"
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
    60
! !
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
    61
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
!ArrayedCollection class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
with:element
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
    "return a new SequenceableCollection with one element:anObject"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
    newCollection := self new:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
    newCollection at:1 put:element.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
    ^newCollection
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    72
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    73
    "
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    74
     OrderedCollection with:1
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    75
     SortedCollection with:99 
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    76
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
with:first with:second
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
    "return a new SequenceableCollection with two elements"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
    newCollection := self new:2.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
    newCollection at:1 put:first.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
    newCollection at:2 put:second.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
    ^newCollection
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    88
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    89
    "
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    90
     OrderedCollection with:1 with:2
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    91
     SortedCollection with:99 with:3
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
    92
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
with:first with:second with:third
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
    "return a new SequenceableCollection with three elements"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
a27a279701f8 Initial revision
claus
parents:
diff changeset
   100
    newCollection := self new:3.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   101
    newCollection at:1 put:first.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   102
    newCollection at:2 put:second.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   103
    newCollection at:3 put:third.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
    ^newCollection
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   105
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   106
    "
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   107
     OrderedCollection with:1 with:2 with:3
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   108
     SortedCollection with:99 with:3 with:301
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   109
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   110
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
a27a279701f8 Initial revision
claus
parents:
diff changeset
   112
with:first with:second with:third with:forth
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
    "return a new SequenceableCollection with four elements"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   114
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
    newCollection := self new:4.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
    newCollection at:1 put:first.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
    newCollection at:2 put:second.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
    newCollection at:3 put:third.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
    newCollection at:4 put:forth.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
    ^newCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
with:one with:two with:three with:four with:five
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
    "return a new SequenceableCollection with five elements"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
    |newCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
a27a279701f8 Initial revision
claus
parents:
diff changeset
   130
    newCollection := self new:5.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
    newCollection at:1 put:one.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
    newCollection at:2 put:two.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
    newCollection at:3 put:three.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
    newCollection at:4 put:four.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
    newCollection at:5 put:five.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
    ^newCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   137
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
withAll:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   140
    "return a new Collection with all elements taken from the argument,
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
     aCollection"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
    |newCollection newSize
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
     index "{ Class: SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
    newSize := aCollection size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   147
    newCollection := self new:newSize.
359
claus
parents: 356
diff changeset
   148
    aCollection isSequenceable ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   149
	"aCollection has indexed elements"
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   150
	newCollection replaceFrom:1 to:newSize with:aCollection startingAt:1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
    ] ifFalse:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   152
	"must enumerate the elements"
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   153
	index := 1.
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   154
	aCollection do:[:element |
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   155
	    newCollection at:index put:element.
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   156
	    index := index + 1
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   157
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
    ^ newCollection
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   160
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   161
    "
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   162
     OrderedCollection withAll:#(1 2 3 4 5)
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   163
     SortedCollection withAll:#(99 17 53 1 101) 
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   164
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   167
!ArrayedCollection class methodsFor:'queries'!
68
59faa75185ba *** empty log message ***
claus
parents: 28
diff changeset
   168
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   169
growIsCheap
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   170
    "return true, if this collection can easily grow
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   171
     (i.e. without a need for become:).
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   172
     Since this is the superclass of all indexed fix-size collections,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   173
     return false here."
68
59faa75185ba *** empty log message ***
claus
parents: 28
diff changeset
   174
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   175
    ^ false
2
claus
parents: 1
diff changeset
   176
! !
claus
parents: 1
diff changeset
   177
249
claus
parents: 213
diff changeset
   178
!ArrayedCollection methodsFor:'copying'!
claus
parents: 213
diff changeset
   179
claus
parents: 213
diff changeset
   180
copyEmptyAndGrow:size
claus
parents: 213
diff changeset
   181
    "return a new instance of the receivers species with size
claus
parents: 213
diff changeset
   182
     nilled elements and any named instance variables copied."
claus
parents: 213
diff changeset
   183
claus
parents: 213
diff changeset
   184
    "special case for Array, which has no named instance vars"
claus
parents: 213
diff changeset
   185
356
claus
parents: 333
diff changeset
   186
    |cls|
claus
parents: 333
diff changeset
   187
claus
parents: 333
diff changeset
   188
    (cls := self class) instSize == 0 ifTrue:[
claus
parents: 333
diff changeset
   189
	^ cls new:size
249
claus
parents: 213
diff changeset
   190
    ].
claus
parents: 213
diff changeset
   191
    ^ super copyEmptyAndGrow:size
claus
parents: 213
diff changeset
   192
! !
claus
parents: 213
diff changeset
   193
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   194
!ArrayedCollection methodsFor:'error handling'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   195
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   196
fixedSizeError
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   197
    "report an error that size of the collection cannot be changed.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   198
     This is obsolete now."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   199
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   200
    ^ self error:'cannot change size'
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   201
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   202
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   203
!ArrayedCollection methodsFor:'printing & storing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   204
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   205
storeOn:aStream
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   206
    "output a printed representation (which can be re-read with readFrom:)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   207
     onto the argument aStream. Redefined to output index access."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   208
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   209
    |index "{ Class: SmallInteger }"|
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   210
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   211
    thisContext isRecursive ifTrue:[
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   212
	Transcript showCr:'Error: storeOn: of self referencing collection.'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   213
	aStream nextPutAll:'#recursive'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   214
	^ self
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   215
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   216
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   217
    aStream nextPutAll:'(('; nextPutAll:self class name; nextPutAll:' new:'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   218
    self size printOn:aStream.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   219
    aStream nextPutAll:')'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   220
    index := 1.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   221
    self do:[:element |
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   222
	aStream nextPutAll:' at:'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   223
	index printOn:aStream.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   224
	aStream nextPutAll:' put:('.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   225
	element storeOn:aStream.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   226
	aStream nextPutAll:');'.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   227
	index := index + 1
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   228
    ].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   229
    index > 1 ifTrue:[aStream nextPutAll:' yourself'].
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   230
    aStream nextPut:$)
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   231
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   232
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   233
     (Array with:(1@2) with:(1->2)) storeString    
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   234
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   235
! !
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   236
2
claus
parents: 1
diff changeset
   237
!ArrayedCollection methodsFor:'resizing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
2
claus
parents: 1
diff changeset
   239
grow:newSize
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   240
    "grow the receiver i.e. cut off everything after newSize.
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   241
     Warning: this may be a slow operation due to the use of become 
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   242
     - you should write your collection classes to avoid the use of become. 
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   243
     You have been warned."
2
claus
parents: 1
diff changeset
   244
599
8a0fefb0a725 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   245
    |newArray oldSize sender|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   246
27
d98f9dd437f7 *** empty log message ***
claus
parents: 5
diff changeset
   247
    oldSize := self size.
d98f9dd437f7 *** empty log message ***
claus
parents: 5
diff changeset
   248
    (newSize ~~ oldSize) ifTrue:[
360
claus
parents: 359
diff changeset
   249
	"/
claus
parents: 359
diff changeset
   250
	"/ output a warning - you should rewrite your application
claus
parents: 359
diff changeset
   251
	"/ to use some collection which implements grow: more efficient
claus
parents: 359
diff changeset
   252
	"/ (i.e. use OrderedCollection instead of Array ..)
claus
parents: 359
diff changeset
   253
	"/
claus
parents: 359
diff changeset
   254
	'ARRCOLL: Warning: slow grow operation (' infoPrint.
590
3ffb78fb2716 report sender in slow grow warning
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   255
	self class name infoPrint. ') via ' infoPrint.
599
8a0fefb0a725 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   256
        sender := thisContext sender.
8a0fefb0a725 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   257
	sender methodPrintString infoPrint. 
8a0fefb0a725 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 590
diff changeset
   258
	' from ' infoPrint. sender sender methodPrintString infoPrintNL.
360
claus
parents: 359
diff changeset
   259
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   260
	newArray := self species new:newSize.
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   261
	newArray replaceFrom:1 to:(newSize min:oldSize) with:self.
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   262
	self become:newArray.
2
claus
parents: 1
diff changeset
   263
    ]
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   264
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   265
    "
590
3ffb78fb2716 report sender in slow grow warning
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   266
     #(1 2 3 4 5 6) add:7
3ffb78fb2716 report sender in slow grow warning
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   267
     #(1 2 3 4 5 6) remove:5 
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   268
     #(1 2 3 4 5 6) copy grow:3  
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   269
     #(1 2 3 4 5 6) copy grow:10  
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   270
     'hello world' copy grow:5   
155
edd7fc34e104 *** empty log message ***
claus
parents: 125
diff changeset
   271
     'hello' copy grow:20   
125
5fdcb4b2567f *** empty log message ***
claus
parents: 92
diff changeset
   272
    "
360
claus
parents: 359
diff changeset
   273
!
claus
parents: 359
diff changeset
   274
claus
parents: 359
diff changeset
   275
removeAll
claus
parents: 359
diff changeset
   276
    'ARRCOLL: Warning: slow remove operation (' infoPrint.
claus
parents: 359
diff changeset
   277
    self class name infoPrint. ')' infoPrintNL.
claus
parents: 359
diff changeset
   278
claus
parents: 359
diff changeset
   279
    self become:(self copyEmpty)
claus
parents: 359
diff changeset
   280
claus
parents: 359
diff changeset
   281
    "
claus
parents: 359
diff changeset
   282
     #(1 2 3 4 5) copy removeAll    
claus
parents: 359
diff changeset
   283
     #(1 2 3 4 5) removeAll    
claus
parents: 359
diff changeset
   284
    "
2
claus
parents: 1
diff changeset
   285
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   286
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   287
!ArrayedCollection methodsFor:'testing'!
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   288
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   289
includesKey:anIndex
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   290
    "return true, if anIndex is a valid key.
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   291
     NOTICE: in ST-80, this message is only defined for Dictionaries,
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   292
	     however, having a common protocol with indexed collections
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   293
	     often simplifies things."
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   294
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   295
    ^ (anIndex >= 1) and:[anIndex <= self size]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   296
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   297
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   298
     #(1 2 3) includesKey:4 
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   299
     #(1 2 3) includesKey:3  
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   300
    "
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   301
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   302
602
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   303
size
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   304
    "redefined to re-enable size->basicSize forwarding
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   305
     (it is cought in SequencableCollection)"
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   306
771ab7a8c4bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 599
diff changeset
   307
    ^ self basicSize
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   308
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   309
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
   310
!ArrayedCollection class methodsFor:'documentation'!
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
   311
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
   312
version
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
   313
    ^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.28 1995-11-23 16:57:30 cg Exp $'
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
   314
! !