smalltalk: Collection class

back  
The following table shows the attributes of each class:

Collection  Ordered  Fixed Size   Duplicates  Keys      Element Class  Laufzeitvorteil
    Bag NoNoYesNoneany 
    IndexedCollection* Yes N.A. N.A. Integer N.A.  
        FixedSizeCollection* Yes YesN.A. Integer N.A.  
            ArrayYesYesYesInteger anyJa
            ByteArrayYesYesYesIntegerSmallInteger 
            IntervalInternalYesNoInteger Number 
            StringYesYesYesInteger Character 
                SymbolYesYesYesInteger Character 
        OrderedCollectionYesNoYesInteger any 
            SortedCollectionInternalNoYesInteger any 
    SetNoNoNoNoneany 
        DictionaryNoNoNoLookupany 
            IdentityDictionaryNoNoNoLookupanyJa

Notes:
* -- abstract classes, there are no instances
Internal -- ordered by the internal contents of the collection
N.A. -- not applicable (determined by subclasses)


Conversions

Because the various collection classes have different attributes, being able to convert from one kind of collection to another is useful. Smalltalk/V provides the following conversion protocol in class Collection.
Methods Comments
asArray Ordering is possibly arbitrary. (arbitrary=willkürlich )
asBag Duplicates are kept.
asSet Duplicates are eliminated.
asOrderedCollection Ordering is possibly arbitrary.
asSortedCollection Each element is <= its successor.
asSortedCollection: sortBlock   Ordering is specified by sortBlock

Thus any collection can be converted into an Array, a Bag, a Set, an OrderedCollection, or a SortedCollection.

Source: Smalltalk/V Tutorial and Programming Handbook, 1991
-- Items added by mr, Jan. 13, 1999