Object » Collection » SequenceableCollection » ArrayedCollection Array » Bitmap ByteArray » String » Symbol » Text »
Class ArrayedCollection is the abstract superclass of various collections that use indices from 1 to an upper limit to access their elements. All subclasses with the exception of DirectoryEntry, RunArray and Text are variable subclasses.
Instances of subclasses are created at a fixed size and cannot grow.
Initial values for the elements of an arrayed collection are:
The notion 'size' has a special interpretation for arrayed collections, which differs from the interpretation of size that is valid for other collections:
sort
Performs an in-place sort of the elements in the collection. The
merge sort algorithm is used to sort the collection elements. When this
method is completed, the collection elements are sorted with respect
to the method <=. The method fails when a collection
element does not understand the message <=.
sort: aBlock
aBlock is required to be a block with two arguments
that answers a boolean value. The method performs an in-place
sort of the elements in the collection. The
merge sort algorithm is used to sort the collection elements. When this
method is completed, the collection elements are sorted with respect
to the ordering that is defined by aBlock.
This example demonstrates the different interpretation of size for an array and an ordered collection:
| array oc | array := Array new: 10. oc := OrderedCollection new: 10. array size = 10 & (oc size = 0)
This example verifies the initialization of the elements of an array.
| array | array := Array new: 10. array collect: [:item | item isNil]
#(true true true true true true true true true true)
The following example demonstrates the use of in-place sorting:
| array | array := Array new: 10. #(54 23 12 58 22 78 91 11 31 41) withIndexDo: [:item :idx | array at: idx put: item]. array sort: [:x :y | x <= y]. array.
#(11 12 22 23 31 41 54 58 78 91)